//Michael G Stebbins.
//driver file for complex class.
//This program Adds, Subtracts and multiplys complex numbers.
#include"Complex.h"
#include<iostream.h>
#include<stdlib.h>
void enterData();
double t1,t2, r1, r2, i1, i2;
main()//main
{
complex a; //object
int c;
cout<<"\n\n\tThis program will add, subtract or multiply complex numbers.\n"
<<"\tChoose the selection then follow the directions\n";
cout<<"\n\tEnter 0 to add, 1 to subtract, 2 to multiply and 3 to exit: ";
cin>> c;
cout<<endl;
while ( (c >= 0) && ( c <= 2)) //loop till exit number is enterd
{
if( c == 0) //choice0
{
enterData();
a.choice0(r1,r2,i1,i2);
cout<<"\n\n\tThe total is "<<a.getTotal1()<<" + "<<a.getTotal2()<<"i"<<"\n"<<endl;
cout<<"\n\n\tThis program will add, subtract or multiply complex numbers.\n"
<<"\tChoose the selection then follow the directions\n";
cout<<"\n\tEnter 0 to add, 1 to subtract, 2 to multiply and 3 to exit: ";
cin>>c;
cout<<endl;
}
if( c == 1) //choice0
{
enterData();
a.choice1(r1,r2,i1,i2);
cout<<"\n\n\tThe total is "<<a.getTotal1()<<" - "<<a.getTotal2()<<"i"<<"\n"<<endl;
cout<<"\n\n\tThis program will add, subtract or multiply complex numbers.\n"
<<"\tChoose the selection then follow the directions\n";
cout<<"\n\tEnter 0 to add, 1 to subtract, 2 to multiply and 3 to exit: ";
cin>>c;
cout<<endl;
}
if( c == 2) //choice0
{
enterData();
a.choice2(r1,r2,i1,i2);
cout<<"\n\n\tThe total is "<<a.getTotal1()<<" x "<<a.getTotal2()<<"i"<<"\n"<<endl;
cout<<"\n\n\tThis program will add, subtract or multiply complex numbers.\n"
<<"\tChoose the selection then follow the directions\n";
cout<<"\n\tEnter 0 to add, 1 to subtract, 2 to multiply and 3 to exit: ";
cin>>c;
cout<<endl;
}
}
return 0;
}//end main
void enterData()//enter data
{
const int size = 20;//
char imaginary1[size], imaginary2[size];//array for imaginary numbers
cout<<"Enter the first complex number.\n";
cout<<"Enter the real part: ";
cin>>r1;
cout<<"Enter the imaginary: ";
cin>>imaginary1;
char *string = imaginary1, *stringPtr;
i1 = strtod(string, & stringPtr); //conversion to double
cout<<"\nEnter the second complex number.\n";
cout<<"Enter the real part: ";
cin>>r2;
cout<<"Enter the imaginary part: ";
cin>>imaginary2;
char *string2 = imaginary2, *stringPtr2;
i2 = strtod(string2, & stringPtr2); //conversion to double
}