List of all available Websheets
Viewing cpp/cs104/inheritance/con_des by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Class C inherits from B which inherits from A. <p> For the object allocations and deallocations in main(), predict what will be printed by the constructors and destructors. <p> Remember: <ul> <li>Constructors start at the base and work outward.</li> <li>Destructors start at the outer-most level and work inward.</li> </ul> |
Remarks Comments, history, license, etc. | Copied from problem cpp/cs104/inheritance/person_stu_ex (author: redekopp@usc.edu) |
Engine | |
Template / Reference solution |
using namespace std; \[ REDACTED \show:
using namespace std; class A { int a; public: A() { a=0; cout << "A:" << a << endl; } ~A() { cout << "~A" << endl; } A(int mya) { a = mya; cout << "A:" << a << endl; } }; class B : public A { int b; public: B() { b = 0; cout << "B:" << b << endl; } ~B() { cout << "~B "; } B(int myb) { b = myb; cout << "B:" << b << endl; } }; class C : public B { int c; public: C() { c = 0; cout << "C:" << c << endl; } ~C() { cout << "~C "; } C(int myb, int myc) : B(myb) { c = myc; cout << "C:" << c << endl; } }; int main() { cout << "Allocating a B object" << endl; B b1; cout << "Allocating first C object" << endl; C* c1 = new C; cout << "Allocating second C object" << endl; C c2(4,5); cout << "Deleting c1 object" << endl; delete c1; cout << "Quitting" << endl; return 0; } ]\ |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [{}] |
Solution visibility | |
Is example? i.e., just a demo |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.