Question
Describe the output of the following program. What C++ object oriented features does this program use? What is the output of the program? You may
Describe the output of the following program. What C++ object oriented features does this program use? What is the output of the program? You may write on the back of this page if necessary.
#include
class example
{
public:
int a;
int b;
example operator+(const example& obj);
void operator=(const example& obj);
};
void example::operator=(const example& obj)
{
(*this).a = obj.a;
(*this).b = obj.b;
return;
}
example example::operator+(const example& obj2)
{
example tmp_obj = *this;
tmp_obj.a = tmp_obj.a + obj2.a;
tmp_obj.b = tmp_obj.b + obj2.b;
return tmp_obj;
}
int main(void)
{
example obj1, obj2, obj3;
obj1.a = 1;
obj1.b = 1;
obj2.a = 2;
obj2.b = 2;
obj3.a = 0;
obj3.b = 0;
obj3 = obj1 + obj2;
std::cout< return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started