I cannot seem to correct the remaining errors in the code.
This is the header
#ifndef DECIMAL_H
#define DECIMAL_H
#include <iostream>
using std::ostream;
using std::istream;
// class Decimal definition
class Decimal
{
public:
friend istream operator>>( istream &, Decimal & );
Decimal( double = 0.0 );
void setInteger( double );
void setDecimal( double );
Decimal &operator=( const Decimal );
Decimal operator+( Decimal );
Decimal operator+=( Decimal );
Decimal &operator++();
Decimal operator++( int );
bool operator==( const Decimal );
private:
friend ostream &operator<<( ostream &, const Decimal & );
double integer;
double decimal;
}; // end class Decimal
#endif // DECIMAL_H
Line 106 brings up an error
#include <iostream>
using std::cout;
using std::cin;
#include <cmath>
#include "Decimal.h"
// constructor
Decimal::Decimal( double n )
{
decimal = modf( n, &integer );
} // end class Decimal constructor
// function operator<< definition
ostream & operator<<( ostream &output, const Decimal &d )
{
double n = 0;
n = floor( d.decimal * 100 );
if ( n < 0 )
n = 0 - floor( d.decimal * 100 );
if ( d.decimal != 0 ) {
output << floor( d.integer ) << ".";
if ( n > 10 )
output << n;
else
output << "0" << n;
} // end if
else
output << d.integer;
} // end function operator<<
// function operator>> definition
istream operator>>( istream &input, Decimal &d )
{
double n;
cout << "Enter a number: ";
input >> n;
// decimal = modf( n, &integer );
return input;
} // end function operator>>
// function operator= definition
Decimal &Decimal::operator=( const Decimal d )
{
integer = d.integer;
decimal = d.decimal;
return *this;
} // end function operator=
// function setDecimal definition
void Decimal::setDecimal( double d )
{
decimal = d;
} // end function setDecimal
// function setInteger definition
void Decimal::setInteger( double i )
{
integer = i;
} // end function setInteger
// function operator+ definition
Decimal Decimal::operator+( Decimal d )
{
Decimal result;
result.setDecimal( decimal + d.decimal );
result.setInteger( integer + d.integer );
if ( result.decimal >= 1 )
{
--result.decimal;
++result.integer;
} // end if
else if ( result.decimal <= -1 )
{
++result.decimal;
--result.integer;
} // end if
return result;
} // end function operator+
// function operator+= definition
Decimal Decimal::operator+=( Decimal d )
{
*this = *this += d;
return *this;
} // end function operator+=
// function operator++ definition
Decimal &Decimal::operator++()
{
++integer;
return integer;
} // end function operator++
// function operator++ definition
Decimal Decimal::operator++( int )
{
Decimal temp = *this;
++integer;
return *this;
} // end function operator++
// function operator== definition
bool Decimal::operator==( const Decimal d )
{
return ( integer == d.integer && decimal == d.decimal );
} // end function operator==
Line 30 keeps giving an error
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include "Decimal.h"
int main()
{
Decimal test1;
Decimal test2;
Decimal test3( 1.234 );
cout << "Initial values:\n"
<< test1 << endl << test2 << endl << test3
<< endl << endl;
cin >> test1 >> test2;
cout << "The sum of test1 and test2 is: "
<< test1 + test2 << endl;
test3 += test1++ + ++test2;
cout << "\nfinal values:\n"
<< "test1 = " << test1 << endl
<< "test2 = " << test2 << endl
<< "test3 = " << test3 << endl;
if ( test1 != test3 )
cout << "test1 and test3 are not equal to each other\n";
return 0;
} // end main