i was going to use this code but i don't know how to get it to print to the outFile and read from the inFile ... I tried but i keep getting so many errors
Code:
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
class complex
{
float real;
float imag;
public:
complex()
{}
complex(float x,float y)
{
real=x;
imag=y;
}
complex operator + (complex);
complex operator - (complex);
complex operator * (complex);
complex operator / (complex);
void display(void)
{
cout << real<< " +i" << imag<< endl;
}
};
complex complex :: operator +(complex c)
{
complex c2;
c2.real=real+c.real;
c2.imag=imag+c.imag;
return (c2);
}
complex complex :: operator -(complex c)
{
complex c2;
c2.real=real-c.real;
c2.imag=imag-c.imag;
return (c2);
}
complex complex :: operator *(complex c)
{
complex c2;
c2.real = ((real * c.real) - (imag * c.imag));
c2.imag = ((real * c.imag) + (imag * c.imag));
return (c2);
}
complex complex :: operator /(complex c)
{
complex c2;
c2.real=((real * c.real) + (imag * c.imag))/((real * c.real) + (imag * c.imag));
c2.imag=((imag * c.real) - (real * c.imag))/((real * c.real) + (imag * c.imag));
return (c2);
}
int main()
{
complex c1,c2,c3;
int op;
char ch,y,Y;
c1 = complex(5.6,2.7);
c2 = complex(3.5,5.6);
cout<< "Two Complex numbers Are :"<< endl;
c1.display();
c2.display();
do
{
cout<< endl<< "******** MENU *********"<< endl;
cout<< "1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5.Exit"<< endl;
cout<< "Enter Your Choice : ";
cin>>op;
switch(op)
{
case 1:
c3 = c1 + c2;
cout<< "Addition of Two complex Nos. :";
c3.display();
break;
case 2:
c3 = c1 - c2;
cout<< "Subtraction of Two complex Nos. :";
c3.display();
break;
case 3:
c3 = c1 * c2;
cout<<" Multiplication of Two complex Nos. :";
c3.display();
break;
case 4:
c3 = c1 / c2;
cout<< "division of Two complex Nos. :";
c3.display();
break;
case 5:exit(0);
default: cout<< endl<< "Aborting!!!!!!!INVALID CHOICE"<< endl;
}
cout<< " Do you want to continue(Y/y)";
cin>>ch;
}
while(ch=='y'||ch=='Y');
return 0;
}