//Michael G Stebbins.
//Member function definitions for complex class.
//This program Adds, Subtracts and multiplys complex numbers.
//Checks for data size
#include<iostream.h>
#include<iomanip.h>
#include"Complex.h"
complex::complex(double w1, double x1, double y1, double z1, double t1, double t2)
{
w=w1, x=x1, y=y1, z=z1, total1=t1, total2=t2;
}
complex::~complex()//destructor not needed but used
{
cout<<"\tObjects destroyed are <total1>= "<<total1
<<"\n\t\t\t <total2>= "<<total2
<<"\n\t\t\t Real1= "<<w
<<"\n\t\t\t Real2= "<<x
<<"\n\t\t\t Imaginary1= "<<y
<<"\n\t\t\t imaginary2= "<<z<<endl;
}
void complex::setValues(double w1, double x1, double y1, double z1)//default
{
L= -10000000 ;
H= 10000000;
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
if((w1< L)||(x1< L)||(y1< L)||(z1 <=L)||(w1> H)||(x1> H)||(y1> H)||(z1> H)) //out of bounds
{ //chk
cout<<"\n\n\t\t*****ERROR!!!!! ERROR!!!!! ERROR!!!!!*****";
cout<<"\n\nData must be > "<< L <<" or < than "<< H <<"\n";
cout<<"The following entries are out of bounds\n\n";
if((w1 < L)||(w1 > H))
{
cout<<"\tThe first real number: "<<w1<<" was reset to (0)\n";
}
if((x1 < L)||(x1 > H))
{
cout<<"\tThe second real number: "<<x1<<" was reset to (0)\n";
}
if((y1 < L)||(y1 > H))
{
cout<<"\tThe first imaginary number: "<<y1<<" was reset to (0)\n";
}
if((1 < L)||(z1 > H))
{
cout<<"\tThe second imaginary number: "<<z1<<" was reset to (0)\n";
}
cout<<"\n\t*****THE TOTALS BELOW ARE NOT ACCURATE DUE TO RESET OF DATA*****.";
}
w = ( ((w1 > L)&&(w1 < H)) ? w1 : 0);//set to 0 if out of bounds
x = ( ((x1 > L)&&(x1 < H)) ? x1 : 0);
y = ( ((y1 > L)&&(y1 < H)) ? y1 : 0);
z = ( ((z1 > L)&&(z1 < H)) ? z1 : 0);
}
void complex::choice0(double w1, double x1, double y1, double z1)//Add
{
setValues(w1,x1,y1,z1);
total1 = (w + x);
total2 = (y + z);
}
void complex::choice1(double w1, double x1, double y1, double z1)//subtract
{
setValues(w1,x1,y1,z1);
total1 = (w - x);
total2 = (y - z);
}
void complex::choice2(double w1, double x1, double y1, double z1)//Multiply
{
setValues(w1,x1,y1,z1);
total1 = ((w * x)+((y * z) * (-1)));
total2 = ((x * y)+(w * z));
}
double complex::getTotal1()//get total 1
{
return total1;
}
double complex::getTotal2()//get total 2
{
return total2;
}