WordPress Hosting
Free Photos
WordPress Themes


#include <iostream> using namespace std; class Phanso{ public: int tu, mau; public: Phanso(int a=1, int b=1){ this->tu=a; this->mau=b; } void Show(); Phanso operator *(Phanso &p); Phanso operator ++(){ return Phanso(++this->tu,++this->mau); } }; Phanso operator -(Phanso &p1, Phanso &p2){ return Phanso(p1.tu*p2.mau-p2.tu*p1.mau,p1.mau*p2.mau); } Phanso operator +(Phanso &p1, Phanso &p2){ return Phanso(p1.tu*p2.mau+p2.tu*p1.mau,p1.mau*p2.mau); } //Phanso operator *(Phanso &p1, Phanso &p2){ // return Phanso(p1.tu*p2.tu,p1.mau*p2.mau); //} class number{ private : int x; public: number(int a=1){ this->x=a; } friend istream& operator >>(istream&i,number&n); }; istream & operator >>(istream &i, Phanso &p){ cout<<"Nhap tu so: "; i>>p.tu; cout<<"Nhap mau so: "; i>>p.mau; return i; } ostream & operator <<(ostream &o, Phanso &p){ o<<"Phan so: "<<p.tu<<"/"<<p.mau<<endl; return o; } Phanso operator ++(Phanso &p, int a=1){ return Phanso(++p.tu,++p.mau); } int main(){ Phanso p1; cin>>p1; cout<<p1; ++p1; p1++; cout<<p1; //Phanso p2(2,3); //p2.Show(); //Phanso p3 = p1.operator*(p2); //p3.Show(); return 0; } Phanso Phanso::operator *(Phanso &p){ return Phanso(this->tu*p.tu, this->mau*p.mau); }; Phanso operator /(Phanso &p1, Phanso &p2){ return Phanso(p1.tu*p2.mau,p1.mau*p2.tu); } void Phanso::Show(){ cout<<"Phan so = "<<this->tu<<"/"<<this->mau<<endl; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.