Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Last active January 19, 2017 12:57
Show Gist options
  • Select an option

  • Save mirsahib/4eade745bd0c4226c93416886afa9ace to your computer and use it in GitHub Desktop.

Select an option

Save mirsahib/4eade745bd0c4226c93416886afa9ace to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
class ComplexNo{
private:
int real;
int img;
public:
void getNo(){
cout<<"Enter Real Number: ";cin>>real;
cout<<"Enter Imaginary Number: ";cin>>img;
}
void getNo(int x){
real=x;
cout<<"Real Number is fixed as "<<x<<endl;
cout<<"Enter imaginary number ";cin>>img;
}
void getNo(int x,int y){
real=x;
img=y;
cout<<"Real Number is fixed as "<<x<<endl;
cout<<"Imaginary Number is fixed as "<<y<<endl;
}
void getNo(ComplexNo a){
real = a.real;
img = a.img;
}
ComplexNo operatorPlus(ComplexNo x){
ComplexNo temp;
temp.real = this.real+x.real;
temp.img = this.img+x.img;
return temp;
}
void display(){
if(img>0){
cout<<"Real Number: "<<real<<"+"<<img<<"i"<<endl;
}else{
cout<<"Real Number: "<<real<<"-"<<abs(img)<<"i"<<endl;
}
}
};
int main()
{
ComplexNo c1,c2,c3;
c1.getNo(12,3);c1.display();
c2.getNo(3,4);c2.display();
c3.getNo(c1.operatorPlus(c2));c3.display();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment