Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PrintShape
//g++ 7.4.0 //Print Shape: printing shape based on user's choice //code(except triangle) is created by Rezaul Hoque on May 15, 2021 //Triangle code credit goes to Simple Snippet Tech //please contact at jewelmrh@yahoo.com #include <iostream> using namespace std; class Object { public: virtual void print() const =0; }; class Rectangle : public Object { public: void print() const { for(int i=0; i<5;i++) { for (int j=0; j<8;j++) cout <<"#"; cout <<"\n"; } } }; class Square : public Object { public: void print() const { for(int i=0; i<5;i++) { for (int j=0; j<5;j++) cout <<"#"; cout <<"\n"; } } }; class Triangle: public Object {// code credit Simple Snippet Tech public: void print () const { for (int i = 1; i <= 5; i++) { for (int p = 5- i; p> 0; p--) { cout << " "; } for (int j = 1; j <= i; j++) { cout << "# "; } cout << "\n"; } } }; int main (){ Object * point = NULL;// point is pointer to an instance of class Object type int choice; bool fQuit = false; while (fQuit == false) { cout <<"(0) Quit (1) Rectangle (2) Square (3)Triangle:\n"; cin>>choice; switch(choice) { case 1: point = new Rectangle; break; case 2: point = new Square; break; case 3: point = new Triangle; break; default: fQuit = true ; break; } if (fQuit) break; point->print(); delete point; } return 0; }
run
|
edit
|
history
|
help
0
2222aaaa
string_match
cppPyDicCom
Primality Test | Fermat
Point on a ray--2133
quickselect
unicodeのテスト
Height of a binary tree
queue-with-fixed-size
Clementina