Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MenuStream
//g++ 7.4.0 ////////////////////////////////////////////////////////////////////////////////MenuStream // //this code is created by Rezaul Hoque on August 02,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //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 <sstream> #include <string> //stream manipulator std::ostream& l(std::ostream& os) { return (os<<"\n"); } void fill(char c) { std::cout.width(40); std::cout.fill(c); std::cout<<l; } class Menu{ friend std::istream & operator>>(std::istream& istr,Menu& in);//input operator friend std::ostream & operator<<(std::ostream& ostr ,const Menu& print);//output operator int p,q,t; public: Menu (){}//default constructor Menu (int mp,int mq){ p=mp;q=mq;}//Menu(int,int ) constructor Menu (const Menu& c){p=c.p; q=c.q;}//copy constructor Menu& operator=(const Menu& eq){ p=eq.p; q=eq.q; return *this;}//assignment operator int& operator[](int);//subscript operator double total(){return p*q;} }; std::istream & operator>>(std::istream & istr,Menu& in) { std::cout<<"\nprice: \n"; istr>>in.p; std::cout<<"\nquantity:\n"; istr>>in.q; return istr; } std::ostream & operator<<(std::ostream & ostr,const Menu& print) { ostr<<"\nprice:\n"<<print.p<<"\nquantity:\n"<<print.q; return ostr; } int main() { fill('@'); std::stringstream s("Example of stream"); s.seekp(0,std::ios::end); s<<" operator overloading"; std::cout<<s.str()<<l; fill('-'); fill('-'); Menu x,y,z; std::cin>>x>>y; z=y; std::cout<<"X:"<<l<<x<<l<<"Total:"<<l<<x.total()<<"\nY:"<<l<<y<<l<<"Total:"<<l<<z.total()<<l; fill('-'); fill('-'); fill('@'); return 0; }
run
|
edit
|
history
|
help
0
string
alma
alm7ly
1
1234
st_match
2d array sum
ewfgrthry
motores
funpointer