In need of help. Won't compile.

Been working on a program and well I wanna compile it. Before it because more of a bigger mess. Someone please help me or point me in the right direction of where to resolve my mistakes.

The code

Rational.H

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
#include <iostream>
using namespace std;
#ifndef _RATIONAL_H_
#define _RATIONAL_H_




class Rational
{
long long _p;
long long _q;
void _reduce();


public:
Rational();
Rational ( long long P, long long Q);
Rational (const Rational&);


Rational& operator= (const Rational& r);
Rational& operator+= (const Rational& r);
Rational& operator-= (const Rational& r);
Rational& operator*= (const Rational& r);
Rational& operator/= (const Rational& r);

friend ostream& operator<< (ostream& os, const Rational& r );
friend istream& operator>> (istream& is, Rational& r);

Rational operator+ (const Rational&) const;
Rational operator+ (long long) const;
friend Rational operator+ (long long, const Rational& );

Rational operator- (const Rational&) const;
Rational operator- (long long) const;
friend Rational operator- (long long, const Rational&);

Rational operator* (const Rational&) const;
Rational operator* (long long) const;
friend Rational operator* (long long, const Rational&);


Rational operator/ (const Rational&) const;
Rational operator/ (long long) const;
friend Rational operator/ (long long, const Rational&);

bool operator== (const Rational&) const;
bool operator== (long long) const;
friend bool operator== (long long, const Rational&);

bool operator!= (const Rational&) const;
bool operator!= (long long) const;
friend bool operator != (long long, const Rational&);

bool operator > (const Rational&) const;
bool operator > (long long) const;
friend bool operator > (long long, const Rational&);

bool operator < (const Rational&) const;
bool operator < (long long) const;
friend bool operator < (long long, const Rational&);

bool operator >= (const Rational&) const;
bool operator >= (long long) const;
friend bool operator >= (long long, const Rational&);

bool operator <= (const Rational& ) const;
bool operator <= (long long ) const;
friend bool operator <= (long  long , const Rational& );

Rational  operator++ (int);
Rational  operator-- (int);
Rational& operator++ ();
Rational& operator-- ();
Rational operator- () ;
Rational operator+ ();
};
#endif 



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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "Rational.h"
#include <iostream>


void Rational::_reduce()
{
 if ( _q <= 0 )
 {
  if ( _q == 0 )
  {
    cout << "_q == 0 ";
    cin.get();
  }

   _p *= -1;
   _q *= -1;

 }
}

Rational::Rational();
{
_p =0;
_q =1;

}
Rational::Rational( long long P, long long Q = 1 )
{
 if ( Q==0) Q =1;
 _p = P;
 _q = Q;

}
Rational::Rational ( const Rational& r )
{
 _p = r._p;
 _q = r._q
}

Rational& Rational::operator= (const Rational& r )
{
 if (this== &r) return *this;
 _p = r._p
 _q = r._q
 _reduce();
 return *this; 
}
Rational& Rational::operator+= (const Rational& r )
{
_p = (_p*r._q) +( r._p*_q);
_q *= r._q;
_reduce();
return *this;
}
Rational& Rational::operator-= (const Rational& r )
{

_reduce();
return operator+=(-r)
}
Rational& Rational::operator*= (const Rational& r )
{
_p *= r._p;
_q *= r._q;
_reduce();
return *this;
}
Rational& Rational::operator/= (const Rational& r )
{
 if (r._p == 0)
 {
 cin.get();
 }
 _p *= r._q;
 _q *= r._p;
 _reduce();
 return *this;
}



ostream& operator<< (ostream& os, const Rational& r)
{
os << r._p << " " << r._q;
return os;
}
istream& operator>> (istream& is, Rational& r)
{
char a;
long long P;
long long Q;
is >> P >> a >> Q;
r = Rational (P,Q);
return is;
}


Rational Rational::operator+ (const Rational& r) const;
{
return Rational (*this)+= r;
}
Rational Rational::operator+ (long long L) const;
{
return (*this) + Rational (L);
}
Rational Rational::operator+ (long long L, const Rational& r)
{
return Rational(L) + r;
}


Rational Rational::operator- (const Rational& r) const;
{
return Rational (*this) -= r;
}
Rational Rational::operator- (long long L) const;
{
return (*this) - Rational (L);
}
Rational Rational::operator- (long long L, const Rational& r)
{
return Rational (L) - r;
}

Rational Rational::operator* (const Rational& r) const;
{
return Rational (*this) *= r;
}
Rational Rational::operator* (long long L ) const;
{
return Rational (*this) * Rational (L);
}
Rational Rational::operator* (long long L , const Rational& r)
{
return Rational (L) * r;
}

Rational Rational::operator/ (const Rational& r) const;
{
return Rational (*this) /= r;
}
Rational Rational::operator/ (long long L) const;
{
return Rational (*this) / Rational (L);
}
Rational Rational::operator/ (long long L , const Rational& r)
{
return Rational (L) / r;
}

bool Rational::operator== (const Rational& r) const; //2 implement this one
{
return (_p == r._p) && (_q == r._q);
}
bool Rational::operator== (long long L) const;
{
return *this == Rational (L);
}
bool Rational::operator== (long long L , const Rational& r)
{
return Rational(L) == r;
}

bool Rational::operator!= (const Rational& r) const;
{
return !(*this == r);
}
bool Rational::operator!= (long long L) const;
{
return *this != Rational (L);
}
bool Rational::operator!= (long long L, const Rational& r)
{
return Rational(L) != r;
}

bool Rational::operator> (const Rational& r) const; // implement this one
{
return (_p*r._q) > (r._p*_q);
}

bool Rational::operator> (long long L) const;
{
return *this < Rational(L);
}
bool Rational::operator> (long long L , const Rational& r)
{
return Rational(L) < r;
}


bool Rational::operator< (const Rational& r) const;
{
return (_p*r._q) < (r._p*_q);
}
bool Rational::operator< (long long L) const;
{
return *this < Rational (L);
}
bool Rational::operator< (long long L, const Rational& r)
{
return Rational(L) < r;
}
bool Rational::operator>= (const Rational& r) const;
{
return (_p*r._q) >= (r._p*q);
}
bool Rational::operator>= (long long L) const;
{
return *this >= Rational(L);
}
bool Rational::operator>= (long long L, const Rational& r)
{
return Rational(L) >= r;
}

bool Rational::operator<= (const Rational& r) const;
{
return (_p*r._q) <= (r._p*q);
}
bool Rational::operator<= (long L) const;
{
return *this <= Rational (L);
}
bool Rational::operator<= (long long L, const Rational& r)
{
return Rational (L) <= r;
}
Rational Rational::operator ++(int) //post
{
Rational ret(*this);
*this +=1;
return ret;
}

Rational Rational::operator --(int) //post
{
Rational ret(*this);
*this +=1;
return ret;
}
Rational& Rational::operator ++() //pre
{
*this +=1;
return *this;
}
Rational& Rational:: operator --() //pre
{
*this +=(-1);
return *this;
}
Rational Rational::operator -();
{
return *this * -1;
}
Rational Rational::operator +();
{
return *this;
}




What is the compiler saying?

The errors
Rational.cpp:21:20: error: declaration of ‘Rational::Rational()’ outside of class is not definition [-fpermissive]
Rational::Rational();
^
Rational.cpp:22:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp: In copy constructor ‘Rational::Rational(const Rational&)’:
Rational.cpp:38:1: error: expected ‘;’ before ‘}’ token
}
^
Rational.cpp: In member function ‘Rational& Rational::operator=(const Rational&)’:
Rational.cpp:44:2: error: expected ‘;’ before ‘_q’
_q = r._q
^
Rational.cpp: In member function ‘Rational& Rational::operator-=(const Rational&)’:
Rational.cpp:59:20: error: passing ‘const Rational’ as ‘this’ argument of ‘Rational Rational::operator-()’ discards qualifiers [-fpermissive]
return operator+=(-r)
^
Rational.cpp:60:1: error: expected ‘;’ before ‘}’ token
}
^
Rational.cpp: At global scope:
Rational.cpp:98:50: error: declaration of ‘Rational Rational::operator+(const Rational&) const’ outside of class is not definition [-fpermissive]
Rational Rational::operator+ (const Rational& r) const;
^
Rational.cpp:99:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:102:44: error: declaration of ‘Rational Rational::operator+(long long int) const’ outside of class is not definition [-fpermissive]
Rational Rational::operator+ (long long L) const;
^
Rational.cpp:103:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:106:61: error: ‘Rational Rational::operator+(long long int, const Rational&)’ must take either zero or one argument
Rational Rational::operator+ (long long L, const Rational& r)
^
Rational.cpp:112:50: error: declaration of ‘Rational Rational::operator-(const Rational&) const’ outside of class is not definition [-fpermissive]
Rational Rational::operator- (const Rational& r) const;
^
Rational.cpp:113:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:116:44: error: declaration of ‘Rational Rational::operator-(long long int) const’ outside of class is not definition [-fpermissive]
Rational Rational::operator- (long long L) const;
^
Rational.cpp:117:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:120:61: error: ‘Rational Rational::operator-(long long int, const Rational&)’ must take either zero or one argument
Rational Rational::operator- (long long L, const Rational& r)
^
Rational.cpp:125:50: error: declaration of ‘Rational Rational::operator*(const Rational&) const’ outside of class is not definition [-fpermissive]
Rational Rational::operator* (const Rational& r) const;
^
Rational.cpp:126:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:129:45: error: declaration of ‘Rational Rational::operator*(long long int) const’ outside of class is not definition [-fpermissive]
Rational Rational::operator* (long long L ) const;
^
Rational.cpp:130:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:133:62: error: ‘Rational Rational::operator*(long long int, const Rational&)’ must take either zero or one argument
Rational Rational::operator* (long long L , const Rational& r)
^
Rational.cpp:138:50: error: declaration of ‘Rational Rational::operator/(const Rational&) const’ outside of class is not definition [-fpermissive]
Rational Rational::operator/ (const Rational& r) const;
^
Rational.cpp:139:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:142:44: error: declaration of ‘Rational Rational::operator/(long long int) const’ outside of class is not definition [-fpermissive]
Rational Rational::operator/ (long long L) const;
^
Rational.cpp:143:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:146:62: error: ‘Rational Rational::operator/(long long int, const Rational&)’ must take exactly one argument
Rational Rational::operator/ (long long L , const Rational& r)
^
Rational.cpp:151:47: error: declaration of ‘bool Rational::operator==(const Rational&) const’ outside of class is not definition [-fpermissive]
bool Rational::operator== (const Rational& r) const; //2 implement this one
^
Rational.cpp:152:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:155:41: error: declaration of ‘bool Rational::operator==(long long int) const’ outside of class is not definition [-fpermissive]
bool Rational::operator== (long long L) const;
^
Rational.cpp:156:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:159:59: error: ‘bool Rational::operator==(long long int, const Rational&)’ must take exactly one argument
bool Rational::operator== (long long L , const Rational& r)
^
Rational.cpp:164:47: error: declaration of ‘bool Rational::operator!=(const Rational&) const’ outside of class is not definition [-fpermissive]
bool Rational::operator!= (const Rational& r) const;
^
Rational.cpp:165:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:168:41: error: declaration of ‘bool Rational::operator!=(long long int) const’ outside of class is not definition [-fpermissive]
bool Rational::operator!= (long long L) const;
^
Rational.cpp:169:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:172:58: error: ‘bool Rational::operator!=(long long int, const Rational&)’ must take exactly one argument
bool Rational::operator!= (long long L, const Rational& r)
^
Rational.cpp:177:46: error: declaration of ‘bool Rational::operator>(const Rational&) const’ outside of class is not definition [-fpermissive]
bool Rational::operator> (const Rational& r) const; // implement this one
^
Rational.cpp:178:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:182:40: error: declaration of ‘bool Rational::operator>(long long int) const’ outside of class is not definition [-fpermissive]
bool Rational::operator> (long long L) const;
^
Rational.cpp:183:1: error: expected unqualified-id before ‘{’ token
{
^

Rational.cpp:186:58: error: ‘bool Rational::operator>(long long int, const Rational&)’ must take exactly one argument
bool Rational::operator> (long long L , const Rational& r)
^
Rational.cpp:192:46: error: declaration of ‘bool Rational::operator<(const Rational&) const’ outside of class is not definition [-fpermissive]
bool Rational::operator< (const Rational& r) const;
^
Rational.cpp:193:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:196:40: error: declaration of ‘bool Rational::operator<(long long int) const’ outside of class is not definition [-fpermissive]
bool Rational::operator< (long long L) const;
^
Rational.cpp:197:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:200:57: error: ‘bool Rational::operator<(long long int, const Rational&)’ must take exactly one argument
bool Rational::operator< (long long L, const Rational& r)
^
Rational.cpp:204:47: error: declaration of ‘bool Rational::operator>=(const Rational&) const’ outside of class is not definition [-fpermissive]
bool Rational::operator>= (const Rational& r) const;
^
Rational.cpp:205:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:208:41: error: declaration of ‘bool Rational::operator>=(long long int) const’ outside of class is not definition [-fpermissive]
bool Rational::operator>= (long long L) const;
^
Rational.cpp:209:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:212:58: error: ‘bool Rational::operator>=(long long int, const Rational&)’ must take exactly one argument
bool Rational::operator>= (long long L, const Rational& r)
^
Rational.cpp:217:47: error: declaration of ‘bool Rational::operator<=(const Rational&) const’ outside of class is not definition [-fpermissive]
bool Rational::operator<= (const Rational& r) const;
^
Rational.cpp:218:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:221:6: error: prototype for ‘bool Rational::operator<=(long int) const’ does not match any in class ‘Rational’
bool Rational::operator<= (long L) const;
^
In file included from Rational.cpp:1:0:
Rational.h:68:6: error: candidates are: bool Rational::operator<=(long long int) const
bool operator <= (long long ) const;
^
Rational.cpp:217:6: error: bool Rational::operator<=(const Rational&) const
bool Rational::operator<= (const Rational& r) const;
^
Rational.cpp:222:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:225:58: error: ‘bool Rational::operator<=(long long int, const Rational&)’ must take exactly one argument
bool Rational::operator<= (long long L, const Rational& r)
^
Rational.cpp:252:31: error: declaration of ‘Rational Rational::operator-()’ outside of class is not definition [-fpermissive]
Rational Rational::operator -();
^
Rational.cpp:253:1: error: expected unqualified-id before ‘{’ token
{
^
Rational.cpp:256:31: error: declaration of ‘Rational Rational::operator+()’ outside of class is not definition [-fpermissive]
Rational Rational::operator +();
^
Rational.cpp:257:1: error: expected unqualified-id before ‘{’ token
{
^
A lot of these errors are just missing semi colons. You need to look over your code more carefully before you have anyone on here look at it.
Topic archived. No new replies allowed.