Monday 19 March 2012

Addition of real and imaginary part


#include<iostream>
using namespace std;
class complex
{
private:
int real;
int img;
public:
void set(int a, int b)
{
real=a;
img=b;
}
void get()
{
cout<<"enter real number: "<<endl;
cin>>real;
cout<<"enter imaginary number: "<<endl;
cin>>img;
}
void print()
{
cout<<"you entered:"<<real<<"+"<<img<<"i"<<endl;
cout<<"addition of real and imaginary part is: "<<real+img;
cout<<endl;
}
};

void main()
{
complex C1,C2;
C1.get();
C2.set(10,20);
C1.print();
}

No comments:

Post a Comment