Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class cComplex{
- public:
- double a;
- double b;
- void init(){
- a = b = 0;
- }
- void set(double x, double y){
- a = x;
- b = y;
- }
- void print(){
- if(b >= 0){
- cout << a << "+" << b << "i" << endl;
- }else{
- cout << a << b << "i" << endl;
- }
- }
- cComplex add(cComplex o){
- cComplex sum;
- sum.a = a + o.a;
- sum.b = b + o.b;
- return sum;
- }
- };
- int main(){
- cComplex i, my, me;
- i.init();
- my.init();
- i.print();
- my.print();
- i.set(2, 3);
- my.set(1, -1);
- i.print();
- my.print();
- me = i.add(my);
- me.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement