Errors overloading "<<" and ">>" functions...

Doing a program for adding, subtracting, multiplying, and comparing two complex numbers and printing the results. I'm pretty sure my syntax is correct, but the occurring errors are preventing me from finishing the rest of my program. My program is as follows. If anyone has anything to offer it would be greatly appreciated. I'm at a loss right now. Sorry if this appears slightly disorganized.


class ComplexNumber
{
public:
ComplexNumber(); //Default constructer, intitialize values to 0
ComplexNumber(int realamt, int imaginaryamt);
friend ComplexNumber operator +(const ComplexNumber& firstamt, const ComplexNumber& secamt);
friend ComplexNumber operator -(const ComplexNumber& firstamt, const ComplexNumber& secamt);
friend ComplexNumber operator *(const ComplexNumber& firstamt, const ComplexNumber& secamt);
friend ostream& operator <<(ostream& outs, const ComplexNumber& thevalue);
friend istream& operator >>(istream& ins, ComplexNumber& avalue);
friend bool operator ==(const ComplexNumber& firstamt, const ComplexNumber& secamt);

public:
int real, imaginary;

};

#include <iostream>
#include <cstdlib>
#include <cctype>

using namespace std;

int main ( )
{
int r1, r2, i1, i2;

cout<<"Enter the real number in the first pair: "<<endl;
cin>>r1;
cout<<"Enter the imaginary coefficient in the first pair: "<<endl;
cin>>i1;
cout<<"Enter the real number in the second pair: "<<endl;
cin>>r2;
cout<<"Enter the imaginary coefficient in the second pair: "<<endl;
cin>>i2;

ComplexNumber firstpair(r1,i1), secondpair(r2,i2), total;
total= firstpair + secondpair;
cout<<total<<endl;
total= firstpair - secondpair;
cout<<"\n"<<total<<endl;
total= firstpair * secondpair;
cout<<"\n"<<total<<endl;
if(firstpair==secondpair)
cout<<"The two pairs are the same";
else
cout<<"The two pairs are different";


system ("PAUSE");
return 0;
}

////////////////////////FUNCTIONS/////////////////////////

ComplexNumber::ComplexNumber(int realamt, int imaginaryamt)
{
real=realamt;
imaginary=imaginaryamt;
}

ComplexNumber operator +(const ComplexNumber& firstamt, const ComplexNumber& secondamt)//adds the two pairs
{
int totalreal, totalimaginary;
ComplexNumber result;

totalreal=firstamt.real + secondamt.real;
totalimaginary=firstamt.imaginary + secondamt.imaginary;
result.real= totalreal;
result.imaginary= totalimaginary;
return result;
}

ComplexNumber operator -(const ComplexNumber& firstamt, const ComplexNumber& secondamt)//substracts pair 2 from pair 1
{
int totalreal, totalimaginary;
ComplexNumber result;

totalreal=firstamt.real - secondamt.real;
totalimaginary=firstamt.imaginary - secondamt.imaginary;
result.real= totalreal;
result.imaginary= totalimaginary;
return result;
}

ComplexNumber operator *(const ComplexNumber& firstamt, const ComplexNumber& secondamt)//multiplies pairs
{
int totalreal, totalimaginary;
ComplexNumber result;

totalreal= (firstamt.real*secondamt.real)-(firstamt.imaginary*secondamt.imaginary);
totalimaginary=(firstamt.real*secondamt.imaginary)+(firstamt.imaginary*secondamt.real);
result.real= totalreal;
result.imaginary= totalimaginary;
return result;
}

ostream& operator <<(ostream& outs, const ComplexNumber& thevalue)
{
outs<<"The combination of these two pairs is "<<thevalue.real<<thevalue.imaginary<<"i";
return outs;
}

istream& operator >>(istream& ins, ComplexNumber& avalue)
{
ins>>avalue.real>>avalue.imaginary;
return ins;
}

bool operator ==(const ComplexNumber& firstamt, const ComplexNumber& secamt)//compares the two pairs
{
return (firstamt == secamt);
}
///////////////////////////////////////////////////////////////////////////

The errors I'm receiving are as follows:

1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(99): error C2872: 'ostream' : ambiguous symbol
1> could be 'c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(9) : int ostream'
1> or 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\iosfwd(636) : std::ostream'
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(99): error C2143: syntax error : missing ';' before '&'
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(99): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(99): error C2086: 'int ostream' : redefinition
1> c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(9) : see declaration of 'ostream'
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(99): error C2872: 'ostream' : ambiguous symbol
1> could be 'c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(9) : int ostream'
1> or 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\iosfwd(636) : std::ostream'
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(99): error C2872: 'ostream' : ambiguous symbol
1> could be 'c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(9) : int ostream'
1> or 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\iosfwd(636) : std::ostream'
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(99): error C2065: 'outs' : undeclared identifier
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(99): error C2059: syntax error : 'const'
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(100): error C2143: syntax error : missing ';' before '{'
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(100): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(105): error C2872: 'istream' : ambiguous symbol
1> could be 'c:\users\jesse\documents\visual studio 2010\projects\jbcomplexnumbers\jbcomplexnumbers\jbcomplexnumbers.cpp(10) : int istream'
1> or 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\iosfwd(635) : std::istream'


error C2065: 'ins' : undeclared identifier
undeclared identifier
error C2275: 'ComplexNumber' : illegal use of this type as an expression
see declaration of 'ComplexNumber'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C1903: unable to recover from previous error(s); stopping compilation
You need to include the appropriate header <istream> and <ostream> before the declaration of class ComplexNumber
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class ComplexNumber
 {
 public:
 ComplexNumber(); //Default constructer, intitialize values to 0
 ComplexNumber(int realamt, int imaginaryamt);
 friend ComplexNumber operator +(const ComplexNumber& firstamt, const ComplexNumber& secamt);
 friend ComplexNumber operator -(const ComplexNumber& firstamt, const ComplexNumber& secamt);
 friend ComplexNumber operator *(const ComplexNumber& firstamt, const ComplexNumber& secamt);
 friend ostream& operator <<(ostream& outs, const ComplexNumber& thevalue);
 friend istream& operator >>(istream& ins, ComplexNumber& avalue);
 friend bool operator ==(const ComplexNumber& firstamt, const ComplexNumber& secamt);
 
public:
 int real, imaginary;
 
};
 
#include <iostream>
 #include <cstdlib>
 #include <cctype>
 
using namespace std; 

int main ( )
 {
 int r1, r2, i1, i2;
 
cout<<"Enter the real number in the first pair: "<<endl;
 cin>>r1;
 cout<<"Enter the imaginary coefficient in the first pair: "<<endl;
 cin>>i1;
 cout<<"Enter the real number in the second pair: "<<endl;
 cin>>r2;
 cout<<"Enter the imaginary coefficient in the second pair: "<<endl;
 cin>>i2;
 
ComplexNumber firstpair(r1,i1), secondpair(r2,i2), total;
 total= firstpair + secondpair;
 cout<<total<<endl;
 total= firstpair - secondpair;
 cout<<"\n"<<total<<endl;
 total= firstpair * secondpair;
 cout<<"\n"<<total<<endl;
 if(firstpair==secondpair)
 cout<<"The two pairs are the same";
 else
 cout<<"The two pairs are different";
 

system ("PAUSE");
 return 0;
 }
 
////////////////////////FUNCTIONS/////////////////////////
 
ComplexNumber::ComplexNumber(int realamt, int imaginaryamt)
 {
 real=realamt;
 imaginary=imaginaryamt;
 }
 
ComplexNumber operator +(const ComplexNumber& firstamt, const ComplexNumber& secondamt)//adds the two pairs
 {
 int totalreal, totalimaginary;
 ComplexNumber result;
 
totalreal=firstamt.real + secondamt.real;
 totalimaginary=firstamt.imaginary + secondamt.imaginary;
 result.real= totalreal;
 result.imaginary= totalimaginary;
 return result;
 }
 
ComplexNumber operator -(const ComplexNumber& firstamt, const ComplexNumber& secondamt)//substracts pair 2 from pair 1
 {
 int totalreal, totalimaginary;
 ComplexNumber result;
 
totalreal=firstamt.real - secondamt.real;
 totalimaginary=firstamt.imaginary - secondamt.imaginary;
 result.real= totalreal;
 result.imaginary= totalimaginary;
 return result;
 }
 
ComplexNumber operator *(const ComplexNumber& firstamt, const ComplexNumber& secondamt)//multiplies pairs
 {
 int totalreal, totalimaginary;
 ComplexNumber result;
 
totalreal= (firstamt.real*secondamt.real)-(firstamt.imaginary*secondamt.imaginary);
 totalimaginary=(firstamt.real*secondamt.imaginary)+(firstamt.imaginary*secondamt.real);
 result.real= totalreal;
 result.imaginary= totalimaginary;
 return result;
 }
 
ostream& operator <<(ostream& outs, const ComplexNumber& thevalue)
 {
 outs<<"The combination of these two pairs is "<<thevalue.real<<thevalue.imaginary<<"i";
 return outs;
 }
 
istream& operator >>(istream& ins, ComplexNumber& avalue)
 {
 ins>>avalue.real>>avalue.imaginary;
 return ins;
 }
 
bool operator ==(const ComplexNumber& firstamt, const ComplexNumber& secamt)//compares the two pairs
 {
 return (firstamt == secamt);
 }
 

THIS LOOKS BETTER AND READABLE
Topic archived. No new replies allowed.