can't figure out this long list of errors

Hello, this is my first post. I've been stuck on an assignment for quite some time now, I have to create a mixed numbers class along with a few functions and 10+ operator overloads. I'm getting stuck on overloading << and >>. I think including my errors separately would be more helpful, I apologize since I'm new and not sure as to what people are used to here.

*errors*: http://pastebin.com/qxiZkYGY

I realize I'm probably making many mistakes, I can't interpret the errors though. If it's helpful, here is a link to the actual assignment:
http://www.cs.fsu.edu/~myers/cop3330/hw/hw03.html
and a link to the main.cpp I'm using:
http://www.cs.fsu.edu/~myers/cop3330/hw/hw3files/main.cpp

my header file:
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
#include <iostream>
#include <iomanip>
using namespace std;

class Mixed
{
public:
Mixed(int i, int n, int d);
Mixed();

int Evaluate() const;
void Simplify();
void ToFraction();


Mixed istream& operator>>(istream& is, Mixed& m);
Mixed ostream& operator<<(ostream& os, Mixed& m);

bool operator ==(const Mixed& m1, const Mixed& m2);
bool operator >(const Mixed& m1, const Mixed& m2);
bool operator <(const Mixed& m1, const Mixed& m2);
bool operator >=(const Mixed& m1, const Mixed& m2);
bool operator <=(const Mixed& m1, const Mixed& m2);
bool operator !=(const Mixed& m1, const Mixed& m2);
const Mixed operator +(const Mixed& m1, const Mixed & m2);
const Mixed operator -(const Mixed& m1, const Mixed& m2);
const Mixed operator *(const Mixed& m1, Mixed& m2);
const Mixed operator /(const Mixed& m1, Mixed & m2);
Mixed Mixed::operator++ (int);
Mixed Mixed::operator++ ();
Mixed Mixed::operator-- (int);
Mixed Mixed::operator-- ();

private:
int integer;
int numerator;
int denominator;

};


the .cpp:

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
#include "Mixed.h"

//constructors

Mixed::Mixed (int i, int n, int d)
{
        if ((i != 0 && n < 0) || d <= 0)
        {
                integer = 0;
                numerator = 0;
                denominator = 0;
        }
        else
        integer = i;
        numerator = n;
        denominator = d;
}

Mixed::Mixed (): integer(d), numerator(0), denominator(0)
{                               }

int Mixed::Evaluate() const
{
        double decimalValue = numerator / denominator;
        return (integer, decimalValue);
}

void Mixed::Simplify()
{
        int newdenom = denominator;
        int newnumer = numerator;

        for (i = newdenom * newnumber; i > 1; i--)
        {
			if ((newdenom % i == 0) && (newnumer % i == 0))
                {
                        newdenom /= i;
                        newnumer /= i;
                        integer++;
                }
        }
}

void Mixed::ToFraction()
{
        newNumerator = (denominator * integer) + numerator;
        cout << newNumerator << "/" << denominator;
}

istream& operator >>(istream& is, Mixed& m)
 char slash, negSign;

        if ((m.integer != 0 && m.numerator < 0) || m.denominator <=0)
                return Mixed(0);

        if (m.integer < 0)
        {
        is >> negSign >> m.integer >> " " >> m.numerator >>
                slash >> m.denominator;
        }
        if (m.integer == 0 && m.numerator < 0)
        {
        is >> m.integer >> " " >> negSign >> m.numerator >>
                slash >> m.denominator;
        }
        if (m.integer == 0 && m.numerator > 0)
        is >> m.integer >> " " >> m.numerator >> slash >> m.denominator;
        return is;
}

ostream& operator <<(ostream& os, const Mixed& m)
{
        if (m.integer == 0 && m.numerator <= 0 && m.denominator <= 0)
                os << '0';
        if (m.denominator <= 0)
                os << '0';
        if (m.integer !=0 && m.numerator < 0)
                os << '0';
        if (m.integer == 0 && m.numerator > 0 && m.denominator > 0)
                os << m.numerator << '/' << m.denominator;
        if (m.integer == 0 && m.numerator < 0 && m.denominator > 0)
                os << '-' << m.numerator << '/' << m.denominator;
        if (m.integer < 0 && m.numerator == 0 && m.denominator == 0)
               os << '-' << m.integer;
        if (m.integer > 0 && m.numerator == 0 && m.denominator == 0)
                os << m.integer;
        if (m.integer < 0 && m.numerator > 0 && m.denominator > 0)
                os << '-' << m.integer << " " << m.numerator <<
                             '/' << m.denominator;
        if (m.integer > 0 && m.numerator > 0 && m.denominator > 0)
                os << m.integer << " " << m.numerator <<
                        '/' << m.denominator;

        return os;
}

bool operator ==(const Mixed& m1, const Mixed& m2)
{
        return ((m1.integer == m2.integer) && (m1.numerator == m2.numerator)
                    && (m1.denominator == m2.denominator));
}

bool operator >(const Mixed& m1, const Mixed& m2)
{
        int NumOne = m1.numerator * m2.denominator;
        int NumTwo = m2.numerator * m1.denominator;

        if (m1.integer > m2.integer)
                return true;
        else if (m1.integer < m2.integer)
                return false;
        else if (m1.integer == m2.integer)
                if (NumOne > NumTwo)
                return true;
                else return false;
}
bool operator <(const Mixed& m1, const Mixed& m2)
{
        return (!operator>());

}

bool operator >=(const Mixed& m1, const Mixed& m2)
{
        return (operator>() && operator==());
}

bool operator <=(const Mixed& m1, const Mixed& m2)
{
        return (operator<() && operator==());
}

bool operator !=(const Mixed& m1, const Mixed& m2)
{
        return (!operator==());
}

const Mixed operator +(const Mixed& m1, const Mixed & m2)
{
        Mixed sum;              //declares a mixed number to hold the result

        sum.integer = (m1.integer + m2.integer);
        sum.numerator = (m1.numerator * m2.denominator)
                         + (m2.numerator * m1.numerator);
        sum.denominator = (m1.denominator * m2.denominator);

        return Simplify(sum);
}

const Mixed operator -(const Mixed& m1, const Mixed& m2)
{
        Mixed difference;

        difference.integer = (m1.integer - m2.integer);
        difference.numerator = (m1.numerator * m2.denominator)
                                - (m2.numerator * m1.numerator);
        difference.denominator = (m1.denominator * m2.denominator);

        return Simplify(difference);
}

const Mixed operator *(const Mixed& m1, Mixed& m2)
{
        Mixed product;

        product.integer = (m1.integer  * m2.integer);
        product.numerator = (m1.numerator * m2.numerator);
        product.denominator = (m1.denominator * m2.denominator);

        return Simplify(product);
}

const Mixed operator /(const Mixed& m1, Mixed & m2)
{
        Mixed quotient;

        if (m1.denominator == 0 || m2.denominator == 0)
                return 0;

        //convert into improper fraction
        int NumOne = m1.denominator * m1.integer + m1.numerator;
        int NumTwo = m2.denominator * m2.integer + m2.numerator;

        int numResult = (numOne * m2.denominator);
		int denResult = (m1.denominator * numTwo);

        // convert fraction to mixed number
        quotient.integer = numResult / denResult;
        quotient.numerator = numResult - finalInt * denResult;
        quotient.denominator = denResult;

        return Simplify(quotient);
}

Mixed operator++ (int ignoreMe)  //postfix
{
        int temp1 = integer;
        int temp2 = numerator;
        int temp3 = denominator;
        integer++;

        return Mixed(temp1, temp2, temp3);
}

Mixed operator++ () //prefix
{
        integer++;
        return Mixed(integer, numerator, denominator);
}

Mixed operator-- (int ignoreMe)  //postfix
{
        int temp1 = integer;
        int temp2 = numerator;
        int temp3 = denominator;
        integer--;

        return Mixed(temp1, temp2, temp3);
}

Mixed operator-- () //prefix
{
        integer--;
        return Mixed(integer, numerator, denominator);
}



I really appreciate any kind of help, thanks very much.
Here's some.

Simplify takes no arguments but you repeatedly try to feed it one.

numOne is probably meant to be NumOne. Likewise numTwo.

finalInt came out of nowhere.

1
2
Mixed::Mixed (): integer(d), numerator(0), denominator(0)
{                               }
d does not exist.


for (i = newdenom * newnumber; i > 1; i--) should be
for (int i = newdenom * newnumber; i > 1; i--)

newnumber is presumably meant to be newnumer

In Mixed::ToFraction() you use newNumerator out of nowhere. It's emant to be an int, I presume?

1
2
istream& operator >>(istream& is, Mixed& m)
 char slash, negSign;
should be
1
2
3
istream& operator >>(istream& is, Mixed& m)
{
 char slash, negSign;


return Mixed(0);
You're not permitted to cast an int to a Mixed.

This whole operator declaration block is a real mess.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool operator ==(const Mixed& m1, const Mixed& m2);
bool operator >(const Mixed& m1, const Mixed& m2);
bool operator <(const Mixed& m1, const Mixed& m2);
bool operator >=(const Mixed& m1, const Mixed& m2);
bool operator <=(const Mixed& m1, const Mixed& m2);
bool operator !=(const Mixed& m1, const Mixed& m2);
const Mixed operator +(const Mixed& m1, const Mixed & m2);
const Mixed operator -(const Mixed& m1, const Mixed& m2);
const Mixed operator *(const Mixed& m1, Mixed& m2);
const Mixed operator /(const Mixed& m1, Mixed & m2);
Mixed Mixed::operator++ (int);
Mixed Mixed::operator++ ();
Mixed Mixed::operator-- (int);
Mixed Mixed::operator-- ();

You need to go back and read up on operator overloading.


There's more and more. I think the biggest thing for you to take from this is that you should compile repeatedly as you write. Turning up at the compiler with 250 lines of code you've never compiled before is asking for trouble.
Last edited on
Thanks, I changed the operator/ overload many times and didn't sort through the variables enough. The simplify function still confuses me, I know it must be some kind of for loop that adds one to the integer value whenever n%d = 0.

He also said the default constructor should take in one int where when a single value is passed in, integer becomes that value. Otherwise defaults to zero.So should I change it to
1
2
3
4
5
Mixed::Mixed (): integer(d), numerator(0), denominator(0)
{        
          integer = d;

}

? Thanks again for your help Moschops
1
2
3
4
5
Mixed::Mixed (): integer(d), numerator(0), denominator(0)
{        
          integer = d;

}


is functionally equivalent to

1
2
3
4
5
6
Mixed::Mixed ()
{        
          integer = d;
          numerator = 0;
          denominator = 0;
}


So where exactly did d come from there? Perhaps you meant this:

1
2
3
4
5
6
Mixed::Mixed (int d)
{           
         integer = d;
         numerator = 0;
         denominator = 0;
}


which is functionally equivalent to:

1
2
3
Mixed::Mixed (int d): integer(d), numerator(0), denominator(0)
{        
}


Last edited on
I think you should start a whole new set of code and one by one, transplant declarations and associated definitions across. Each time, compile it, fix the errors. You'll find it much easier to fix one or two errors at a time.
Thanks. I actually had
1
2
3
4
5
6
Mixed::Mixed (int d)
{           
         integer = d;
         numerator = 0;
         denominator = 0;
}

originally and changed it later to what I wrote in my first post. Now I think the main bulk of the errors are due to incorrectly overloading istream and ostream. I will continue to work on it, thanks.
Topic archived. No new replies allowed.