2. What will be the output of each of the following program when it is executed? (a)
#include using namespace std; class abc {
private :
int x; public :
abc(int);
void display();
};
abc :: abc (int value)
{
x = value;
}
void abc :: display()
{
cout <><>
}
int main()
{
abc obj1(10); abc obj2(20); obj2 = obj1;
cout <>
}
(b)
obj1.display();
cout <>\n”; obj2.display();
return 0;
#include using namespace std; class abc {
private :
int x; public :
abc(int);
void operator= (abc operabc); void display();
};
abc :: abc(int value)
{
x = value;
}
void abc :: operator= (abc operabc)
{
x = ++(operabc.x);
}
void abc :: display()
{
cout <><>
}
int main()
{
}
(c)
abc obj1(100); abc obj2(20);
obj1.operator= (obj2);
cout <> of the rst object \n”; obj1.display();
cout <>\n”; obj2.display();
return 0;
#include using namespace std; class abc {
private :
int x; public :
abc(int);
void operator= (abc operabc); void display();
};
abc :: abc( int value)
{
x = value;
}
void abc :: operator= (abc operabc)
{
x = ++(operabc.x);
}
void abc :: display()
{
cout <><>
}
int main()
{
}
(d)
abc obj1(100); abc obj2(20);
obj1.operator= (obj2);
cout <> of the rst object \n”; obj1.display();
obj2.operator= (obj2);
cout <>
return 0;
#include using namespace std; class abc{
private:
int x; public:
abc();
void operator++ (int); void display();
};
abc :: abc()
{
x = 0;
}
void abc ::operator ++(int x)
{
x++;
}
void abc ::display()
{
cout <><>
}
int main()
{
abc obj; obj.display(); obj.operator ++(10);
}
(e)
obj.display(); return 0;
#include using namespace std; class abc{
private:
int x; public:
abc();
abc operator++(); void display();
};
abc :: abc()
{
x = 0;
}
abc abc ::operator ++()
{
++x;
return *this;
}
void abc ::display()
{
cout <><>
}
int main()
{
}
(f)
abc obj; obj.display(); obj++; obj.display(); return 0;
#include using namespace std; class abc{
private:
int x; public:
abc();
abc operator++(); void display();
};
abc :: abc()
{
x = 0;
}
abc abc ::operator ++()
{
x++;
return *this;
}
void abc ::display()
{
cout <><>
}
int main()
{
}
(g)
abc obj; obj.display(); obj++; obj.display(); return 0;
#include using namespace std; class abc {
private:
int value; public :
abc();
abc(int );
int operator >= (abc obj);
};
abc :: abc()
{
value = 0;
}
abc :: abc( int one)
{
value = one;
}
int abc :: operator >= ( abc obja)
{
return ( value >= obja.value);
}
int main()
{
abc obja(20); abc objb(100);
cout <>= objb) <><>= obja) <>
}