Explain each line in main (you can put it in the comments) and explain why the output looks how it looks. #include using namespace std; class A { public: A() { n=0; } A(int x) { n=x; } void f() { n++; } void g() { f(); n=n*2; f(); } int k() { return n; } void p() { cout<
Explain each line in main (you can put it in the comments) and explain why the output looks how it looks.
#include <iostream>
using namespace std;
class A
{
public:
A()
{
n=0;
}
A(int x)
{
n=x;
}
void f()
{
n++;
}
void g()
{
f();
n=n*2;
f();
}
int k()
{
return n;
}
void p()
{
cout<<n<<endl;
}
private:
int n;
};
void main()
{
A a;
A b(2);
A c=b;
A d=A(3);
a.f();
b.g();
c.f();
d.g();
d.p();
A e(a.k() + b.k() + c.k() + d.k());
e.p();
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- Recommended textbooks for youDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag…Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education