List of all available Websheets
Viewing cpp/cs104/polymorphism/virtf2 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/virtfunc2 (author: redekopp@usc.edu) 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 Bracketer { public: virtual ~Bracketer() {} \[ REDACTED \show: string bracket(string s) ]\ { return open() + s + close(); } protected: virtual string open() { return "<"; } virtual string close() { return ">"; } private: }; class SquareBracketer : public Bracketer { protected: string open() { return "["; } string close() { return "]"; } }; class DblBracketer : public SquareBracketer { public: string bracket(string s) { return open() + Bracketer::bracket(s) + close(); } }; void doIt(Bracketer& b, string s) { cout << b.bracket(s) << endl; } int main() { Bracketer b; SquareBracketer sb; DblBracketer dblb; string s1 = "123"; doIt(b, s1); doIt(sb, s1); \[ REDACTED \show: doIt(dblb, s1); //cout << dblb.bracket(s1) << 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'.