Created
June 15, 2018 02:11
-
-
Save tienhieuD/f4b6f46dc568b9b0ea0eb1ba1938051c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| #include<iostream> | |
| #include<conio.h> | |
| using namespace std; | |
| class Sophuc | |
| { | |
| private: | |
| float thuc, ao; | |
| public: | |
| Sophuc( int thuc=0 , int ao=0) { | |
| this->thuc = thuc; | |
| this->ao = ao; | |
| } | |
| friend istream & operator >> (istream &in, Sophuc &p); | |
| friend ostream & operator << (ostream &out, Sophuc &p); | |
| Sophuc operator + (Sophuc& b) | |
| { | |
| Sophuc c; | |
| c.thuc = thuc + b.thuc; | |
| c.ao = ao + b.ao; | |
| return c; | |
| } | |
| Sophuc operator + (float b) | |
| { | |
| Sophuc d; | |
| d.thuc = thuc + b; | |
| d.ao = ao; | |
| return d; | |
| } | |
| }; | |
| istream & operator >> (istream &in, Sophuc &p) | |
| { | |
| cout<<"Nhap phan thuc: "; in>>p.thuc; | |
| cout<<"Nhap phan ao: "; in>>p.ao; | |
| return in; | |
| }; | |
| ostream & operator << (ostream &out, Sophuc &p) | |
| { | |
| out<<p.thuc<<"+"<<p.ao<<"i"; | |
| return out; | |
| }; | |
| template <class T, class S> | |
| T Sum (T a, S b) { | |
| T result; | |
| result = a+b; | |
| return (result); | |
| } | |
| int main() | |
| { | |
| Sophuc a(0,0), b(0,0), c(0,0), d(0,0); | |
| float e; | |
| cin>>a; | |
| cin>>b; | |
| cout<<"So phuc a la: "<<a; | |
| cout<<"So phuc b la: "<<b<<endl; | |
| c=Sum<Sophuc, Sophuc>(a, b); | |
| c=Sum<Sophuc, float>(a, 12.2); | |
| cout<<c; | |
| cout<<"Nhap e: "; | |
| cin>>e; | |
| d=a+e; | |
| cout<<d; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment