hello every one ,
i am working on this code for a week , but i have a problem that every time i try to debug it i receive many errors i can't understand them
here is my code
/*
Simple program to compute the two possible roots of a quadratic equation.
*/
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <ostream>
using namespace std;
#define mR00t 20
struct cmplxNumber{
double dReal, dImaginary;
} ;
bool ComputeRoots( double dCoefA, double dCoefB, double dCoefC,
cmplxNumber & Root1, cmplxNumber & Root2);
ostream & PrintComplex( ostream & outDevice, cmplxNumber Root );
int main()
{
// Need some variable storage for parameters
double dCoefA = 0.0, dCoefB = 0.0, dCoefC = 0.0;
cmplxNumber R00t1 [mR00t] , R00t2 [mR00t] ;
char choice ;
int count = 0 ;
int dataReadedFromFile = 0;
do
{
cout << " please , enter 1 for reading data from file " << endl ;
cout << " pleasse , enter 2 for displaying the stored resoults " << endl ;
cout << " please , enter 3 for computing the complex numbers " << endl ;
cout << " please, enter 4 for compute the roots " << endl ;
cout << " please enter 5 to exit this program " << endl ;
cin >> choice ;
if ( choice == '1' )
{
ifstream rawData ;
rawData.open ("RAW.DATA.txt") ;
if ( ! rawData.good () )
{
cout << " sorry ..... the program can't open this file " << endl ;
system ("pause") ;
break ;
}
else
{
cout << " the program reading the data from the file now " << endl ;
do
{
rawData>> dCoefA >> dCoefB >>dCoefC;
cout << dCoefA << " " << dCoefB << " " << dCoefC << endl ;
cmplxNumber Root1, Root2 ;
ComputeRoots( dCoefA, dCoefB, dCoefC, Root2, Root1 );
cout << "\n\nThe first root is " << Root1.dReal;
if( Root1.dImaginary < 0.0 ) {
cout << " - " << abs(Root1.dImaginary) << " j" << endl;
}
else if( Root1.dImaginary > 0.0 ) {
cout << " + " << Root1.dImaginary << " j" << endl;
}
else
cout << endl;
cout << "\n\nThe second root is ";
PrintComplex( cout, Root2 );
R00t1[count] = Root1 ;
R00t2[count] = Root2 ;
count ++ ;
} while ( ! rawData.eof () && (count < mR00t) ) ;
cout << " the end of the data " << endl ;
system ("pause") ;
continue ;
}
continue ;
}
if (choice == '2')
{
cout << " the program will display the stored resoults " << endl ;
dataReadedFromFile = count ;
cout << " the program readed "<< dataReadedFromFile << " from the file " << endl ;
count = 0 ;
do
{
cout << " the first root is " ;
PrintComplex( cout, R00t1[count] );
cout << endl ;
cout << " the second root is " ;
PrintComplex( cout, R00t2[count] );
cout << endl ;
count ++ ;
}while ( count < dataReadedFromFile ) ;
system ("pause") ;
continue ;
}
if ( choice == '3' )
{
cout << "the program will compute complex nubers and display the average " << endl ;
ifstream DATA2 ;
DATA2.open ("RAW.DATA2.txt");
ofstream REPORT ;
REPORT.open ("REPORT.txt") ;
if ( ! DATA2.good () )
{
cout << " the program can't open the file " << endl ;
break ;
}
else if (! REPORT.good () )
{
cout << " the program can't open the output file " << endl ;
break ;
}
else
{
cmplxNumber real , imaginary ;
real.dReal = 0.0 ;
imaginary.dImaginary = 0.0 ;
double sum = 0.0 ;
double sum2 = 0.0;
double aver = 0.0 ;
double Rreal[40], Iimaginary[40] ;
cout << " the program is reading the data from the file " << endl ;
count = 0 ;
cout << endl ;
do
{
DATA2 >> real.dReal >> imaginary.dImaginary ;
Rreal[count] = real.dReal ;
Iimaginary[count] = imaginary.dImaginary ;
sum = real.dReal + imaginary.dImaginary ;
cout << "the real point is " << real.dReal << endl ;
cout << "the imaginary point is " << imaginary.dImaginary << endl ;
cout << " the total for them is " << sum << endl ;
REPORT << " the total is " << sum << endl ;
sum2 = (sum2 + sum ) ;
count ++ ;
cout << endl;
} while ( ! DATA2.eof () && count < 40);
cout << count << endl ;
aver = (sum2 / count) ;
cout << " the total for all the sums is " << sum2 << endl ;
cout << " the average for the total is " << sum2 <<" / " << count ;
cout << " = " << aver << endl ;
REPORT << "the average for the points total is " << sum2 << " / " << count ;
REPORT << " = " <<aver << endl ;
DATA2.close () ;
REPORT.close () ;
}
system ("pause") ;
continue ;
}
if (choice == '4')
{
count = 0 ;
cmplxNumber A , B ,C;
do
{
A = R00t1[count] ;
B = R00t2[count] ;
C = add (A + B );
cout << " the resoult of adding the two roots is " ;
PrintComplex( cout, C );
C = (A - B) ;
cout << endl;
cout << " the resoult of subtracting the first root from the second root is " ;
PrintComplex( cout, C );
cout << endl ;
count ++ ;
} while ( count < dataReadedFromFile ) ;
}
if ( choice == '5')
{
cout << " the program will exit " << endl ;
system ("pause");
break ;
}
} while ( mR00t == 20 );
}
bool ComputeRoots( double dCoefA, double dCoefB, double dCoefC,
cmplxNumber & Root1, cmplxNumber & Root2)
{
double dInter1, dInter2;
dInter1 = dCoefB * dCoefB; // get the square of B
dInter2 = 4.0 * dCoefA * dCoefC;
if(dInter1 < dInter2 ) {
Root1.dImaginary = pow(abs(dInter1 - dInter2), 0.5)/ (2.0 * dCoefA);
Root2.dImaginary = -pow(abs(dInter1 - dInter2), 0.5)/ (2.0 * dCoefA);
Root1.dReal = Root2.dReal = -dCoefB / (2.0 * dCoefA);
} else {
Root1.dReal = (-dCoefB + pow(dInter1 - dInter2, 0.5))/ (2.0 * dCoefA);
Root2.dReal = (-dCoefB - pow(dInter1 - dInter2, 0.5))/ (2.0 * dCoefA);
Root1.dImaginary = Root2.dImaginary = 0.0;
}
return true;
}
// declaration of function using 'things' from the stream devices is
// fairly exacting. MUST use references to the device variables.
ostream & PrintComplex( ostream & outDevice, cmplxNumber Root )
{
outDevice << Root.dReal;
if( Root.dImaginary < 0.0 ) {
outDevice << " - " << abs(Root.dImaginary) << " j" << endl;
}
else if( Root.dImaginary > 0.0 ) {
outDevice << " + " << Root.dImaginary << " j" << endl;
}
else
cout << endl;
return outDevice;
}
the errors are
Error 1 error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'cmplxNumber' c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 170
Error 2 error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'cmplxNumber' c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 170
Error 3 error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'cmplxNumber' c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 170
Error 4 error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'cmplxNumber' c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 170
Error 5 error C2676: binary '+' : 'cmplxNumber' does not define this operator or a conversion to a type acceptable to the predefined operator c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 170
Error 6 error C3861: 'add': identifier not found c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 170
Error 7 error C2784: 'reverse_iterator<_RanIt>::difference_type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'cmplxNumber' c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 173
Error 8 error C2784: '_Base1::difference_type std::operator -(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'cmplxNumber' c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 173
Error 9 error C2676: binary '-' : 'cmplxNumber' does not define this operator or a conversion to a type acceptable to the predefined operator c:\users\michael\documents\visual studio 2008\projects\hw 3 _ shokery\hw3_shokery.cpp 173