Professional Documents
Culture Documents
Trace The Following Program To Find Out Its Output
Trace The Following Program To Find Out Its Output
Trace The Following Program To Find Out Its Output
#include <iostream>
using namespace std;
class C1 {
public:
int x, y, z;
C1() { x = 10; y = 20; z = 30; }
C1(int a,int b,int c):x(a),y(b), z(c) { }
C1(const C1& ob) {
x = ob.x;
y = ob.y;
z = ob.z;
cout << "COPY: " << x + this->y + z << endl; }
friend ostream& operator<<(ostream& OUT, const C1& OB);
};
class C2
{
bool A;
char B;
public:
C2(bool a = true, char b = 'a') :A(a),B(b) {}
C2(const C2& ob) {
A = ob.A;
B = ob.B;
cout << "hi : " << A << '\t' << ob.B << endl; }
bool get_A() { return A; }
char get_B() { return B; }
friend ostream& operator<<(ostream& OUT, const C2& OB);
};
C1 fun(C1& ob1, C2 ob2, C1& ob3)
{
if (ob1.x > ob3.x && ob2.get_A() > ob3.z)
return ob1;
else
return ob3;
}
ostream& operator<<(ostream& OUT, const C2& OB)
{
OUT << "Printing C2 info: " << OB.A << OB.B + OB.A + OB.B;
return OUT;
}
ostream& operator<<(ostream& OUT, const C1& OB)
{
OUT << '*' << OB.x + OB.y << "**"<< OB.z << "***"<<OB.y+ var + OB.z;
return OUT;
}
C1& operator+=( C1& L, const C1& R)
{
L.x = R.y + 2;
L.y = R.z;
L.z = R.x + R.y - R.z;
return L;
}
one += four;
two += three;
return 0;
}
Page 2 of 2