Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Representative of Complex number.cpp #371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions Creatr Representative of Complex number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include <iostream>
#include <cmath>
using namespace std;
int r,i,num;
class complex
{ int real,img; public: complexnum(int ,int ); void display();
void addreal(); void addimg();
void subreal();
void subimg();
};
complex::complexnum(int r,int i)
{
real=r;
img=i;
}
void complex::display()
{
char ch;
if(img>=0)
ch='+';
else
ch='-';
cout<<" "<<real<<ch<<abs(img)<<"i"<<endl;
}
void complex::addreal()
{
cout<<"Enter the no to add:\n";
cin>>num;
real=r+num;
}
void complex::addimg()
{
cout<<"Enter the no to add:\n";
cin>>num;
img=i+num;
}
void complex::subreal()
{
cout<<"Enter the no to sub:\n";
cin>>num;
real=r-num;
}
void complex::subimg()
{
cout<<"Enter the no to sub:\n";
cin>>num;
img=i-num;
}
int main()
{
complex c;
cout<<"Enter the real part of complex number:\n"; cin>>r;
cout<<"Enter the imaginary part of complex number:\n";
cin>>i;
c.complexnum (r,i);
int ch;
do
{
cout<<" What do you want to do:\n";
cout<<" 1.Display complex number\n 2.Add a real number\n 3.Subtract a real number\n 4.Add a imaginary number\n 5.Subtract a imaginary number\n 6.Exit\n";
cin>>ch;
switch(ch)
{
case 1:cout<<" The complex number is:\n";
c.display();
break;
case 2:c.addreal();
cout<<"result:\n";
c.display();
break;
case 3:c.subreal();
cout<<"result:\n";
c.display();
break;
case 4:c.addimg();
cout<<"result:\n";
c.display();
break;
case 5:c.subimg();
cout<<"result:\n";
c.display();
break;
case 6: cout<<"Exiting now";
break;
default:cout<<"Invalid Choice\n";
}
}while(ch!=6);
return 0;
}