Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MoaJhalMury
//g++ 7.4.0 //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> #include <string> using namespace std; class Mury{ protected: int price,qty; string color, taste; public: string getCol() const { return color;} string getTast() const { return taste;} void set(int a, int b, string p, string q) { price =a; qty=b; color= p; taste=q;} virtual int cost() =0;//pure virtual member function (PVF) void printcost() { cout<<this->getCol()<<",\t"; cout<<this->getTast()<<",\t"; cout<<" and costs Tk "; cout <<this->cost();//PVF can be called from abstract base class cout <<endl; } }; class Moa : public Mury{ public: int cost() { return (price * qty);} }; class JhalMury: public Mury { public: int cost(){ return price;} }; int main() { Moa m; JhalMury j; Mury * p1 = &m; Mury * p2 = &j; p1->set(5,2,"Red","Sweet"); p2->set(10,1,"White","Hot & Spicy"); cout<<" Moa is "; p1->printcost(); cout <<"\n"; cout<<" JhalMury is "; p2->printcost(); return 0; }
run
|
edit
|
history
|
help
0
Using C's sprinf() Function to Format Output String
Test 20(2020)
Following order Indegree
OTHER - Two robots
Height of a binary tree
cppPyGuessTheNum2
MemCpySetChar
poprawione_i_podzielone_1
precision and fixed point notation
Variadic template example