Question: 3 . ( 1 0 pts ) Give the output for the following C + + code. #include using namespace std; class Midterm { private:

3.(10 pts) Give the output for the following C++ code.
#include
using namespace std;
class Midterm
{
private:
int num;
public:
Midterm();
Midterm(int num);
~Midterm();
int get();
void increment();
};
Midterm::Midterm() : num(0)
{
cout << "Test object constructed" << endl;
}
Midterm::Midterm(int num) : num(num)
{
cout << "Test object created with num ="<< num << endl;
}
Midterm::~Midterm()
{
cout << "Test object destroyed" << endl;
}
int Midterm::get()
{
return num;
}
void Midterm::increment()
{
num++;
}
void foo(Midterm& m)
{
Midterm temp(0);
m = temp;
m.increment();
cout << "Foo: "<< m.get()<< endl;
}
int main()
{
Midterm b(10);
b.increment();
{
Midterm a;
cout << "Main 1: "<< a.get()<< endl;
foo(a);
}
foo(b);
cout << "Main 2: "<< b.get()<< endl;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!