Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPyAbs
//g++ 7.4.0 //cppPyAbs: C++ equivalent of PyAbs program (created on January 09,2022) //this code is created by Rezaul Hoque on January 10,2022;contact: jewelmrh@yahoo.com,Dhaka, Bangladesh //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 Food{ protected: int price,qty,charge; string name,color; public: void set(string p,string q,int a,int b,int c){ name=p;color= q;price=a;qty=b;charge=c;} string getNam() const {return name;} string getCol() const { return color;} virtual int cost()=0; void print(){ std::cout<<this->getNam()<<"\t"; std::cout<<this->getCol()<<"\t\t"; std::cout<<this->cost()<<"\n"; } }; class CookedFood : public Food{ public: int cost() { return price*qty;} }; class BakedFood : public Food{ public: int cost() { return (price*qty)+charge;} }; int main() { CookedFood c,d; BakedFood b,k; CookedFood * p1=&c; CookedFood *p3=&d; BakedFood * p2=&b; BakedFood * p4=&k; p1->set("Pakora ","Yellow",5,4,0); p3->set("Jilebi ","Golden",10,5,0); p2->set("Rice Cake","White",10,5,10); p4->set("Vanilla Cake","Brown",35,1,10); std::cout<<"C++ equivalent of PyAbs program: \n"; std::cout<<"Food"<<"\t\t"<<"Color"<<"\t\t"<<"Cost\n"; std::cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"; p1->print(); p3->print(); p2->print(); p4->print(); return 0; }
run
|
edit
|
history
|
help
0
pbds
deux
4149 coj TL
Simple Interest Calculator
Handling new types without using RTTI
TempBubbleDouble
Power of an element
1
no_error
MovConstrAssign4