(5) Please Can some one help me. I need good explanation of each line, what it d
ID: 641858 • Letter: #
Question
(5) Please Can some one help me. I need good explanation of each line, what it does. i am really lost. please help.
read the fallowing program carefully.
#include <iostream>
using namespace std;
class Dumb
{
private:
int a;
public:
Dumb()
{
a = 10;
cout <<"Default Constructor" <<endl;
}
Dumb (const Dumb &obj)
{
this->a = obj.a +2;
cout <<"copy constroctor" <<endl;
}
const Dumb operator = (const Dumb & right)
{
Dumb X = right;
cout <<"operator = " <<endl;
return X;
}
Dumb operator++()
{
cout << ++a <<endl;
return *this;
}
};
int main()
{
cout <<"1: ";
Dumb dumb;
cout <<"2: ";
Dumb dumber = dumb;
cout <<"3: ";
dumb = dumber;
cout <<"4: ";
++dumber;
return 0;
}
Question: what do you expect from the above program ? and explain your answers (no exlain No credit)
Explanation / Answer
#include <iostream>
using namespace std;
class Dumb //class name dumb
{
private:
int a;
public:
Dumb()
{
a = 10; //a value is 10
cout <<"Default Constructor" <<endl; // default value of the constructor a is 10
}
Dumb (const Dumb &obj)
{
this->a = obj.a +2; //ojbect a is called the value of a is now 10+2=12
cout <<"copy constroctor" <<endl;
}
const Dumb operator = (const Dumb & right) //operator value taken from right side
{
Dumb X = right; //right side value of the operator
cout <<"operator = " <<endl; //operator is =
return X;
}
Dumb operator++() /
{
cout << ++a <<endl; //a is incremented by 1 now the value of a=12+1=13
return *this;
}
};
int main()
{
cout <<"1: ";
Dumb dumb;
cout <<"2: ";
Dumb dumber = dumb;
cout <<"3: ";
dumb = dumber;
cout <<"4: ";
++dumber;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.