Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef struct SP{
- double rel;
- double img;
- } SP;
- SP setSP(int _rel, int _img);
- void display(SP c);
- SP operator + (SP c1, SP c2); // overload +
- SP operator - (SP c1, SP c2); // overload -
- int main(){
- SP c1, c2, c3, c4;
- c1 = setSP(1, -2);
- c2 = setSP(3, 4);
- c3 = c1 + c2;
- printf("Tong hai so: "); display(c3);
- c4 = c1 - c2;
- printf("Hieu hai so: "); display(c4);
- return 0;
- }
- SP setSP(int _rel, int _img){
- SP c;
- c.rel = _rel; c.img = _img;
- return c;
- }
- void display(SP c){
- cout << c.rel <<" + i*" << c.img << endl;
- }
- SP operator + (SP c1, SP c2){
- SP c;
- c.rel = c1.rel + c2.rel;
- c.img = c1.img + c2.img;
- return c;
- }
- SP operator - (SP c1, SP c2){
- SP c;
- c.rel = c1.rel - c2.rel;
- c.img = c1.img - c2.img;
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment