List of all available Websheets
Viewing cpp/cs104/polymorphism/bracketer 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 Bracketer { public: virtual ~Bracketer() {} string bracket(string s) { return start() + s + end(); } protected: virtual string start() { return ""; } virtual string end() { return ""; } private: }; class SquareBracketer : public Bracketer { protected: string start() { return "["; } string end() { return "]"; } }; class AngleBracketer : public Bracketer { protected: string start() { return "<"; } string end() { return ">"; } }; int main() { Bracketer *b = new Bracketer; Bracketer *sb = new SquareBracketer; Bracketer *ab = new AngleBracketer; string s1 = "123"; cout << b->bracket(s1) << endl; cout << sb->bracket(s1) << endl; cout << ab->bracket(s1) << endl; delete b; delete sb; delete ab; 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'.