You are on page 1of 2

#include<iostream>

using namespace std;

class complex{

private:

int real, img;

const char ch = '+';

const char ch1 = 'i';

public:

void getdata(){

cout<<"Enter the real part of your complex number:"<<endl;

cin>>real;

cout<<"Enter the imaginary part of your complex number:"<<endl;

cin>>img;

void show(){

cout<<"The real part is "<< real <<" and imaginary part is "<<
img<<endl;

void sum(complex c1, complex c2){

complex c3;

c3.real = c1.real + c2.real;

c3.img = c1.img + c2.img;

cout<<"The sum is:" << c3.real<< ch<< ch1 << c3.img;

};
int main(){

complex a,b,c,d;

a.getdata();

a.show();

b.getdata();

b.show();

c.sum(a,b);

return 0;

You might also like