List of all available Websheets
Viewing cpp/cs104/polymorphism/virtfunc2 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 | Predict what will be printed by this program. |
Remarks Comments, history, license, etc. | Copied from problem cpp/cs104/polymorphism/virtfunc1 (author: redekopp@usc.edu) Copied from problem cpp/cs104/polymorphism/shapes (author: redekopp@usc.edu) |
Engine | |
Template / Reference solution |
using namespace std; class Packager { public: virtual ~Packager() {} string package(string& s) { return material() + s + material(); } protected: virtual string material() { return "-"; } private: }; class APackager : public Packager { protected: string material() { return "A"; } }; class DblPackager : public APackager { public: string package(string& s) { return material() + Packager::package(s) + material(); } }; int main() { Packager *p = new Packager; APackager *a = new DblPackager; DblPackager *d = new DblPackager; string s1 = "123"; cout << p->package(s1) << endl; cout << a->package(s1) << endl; cout << d->package(s1) << endl; delete p; delete a; delete d; 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'.