<< Operand problems

I am working on a much more complex program than I am used to and I have no idea why << in my cout statement, and < in a if statement will not work. Any advice on the program overall will be helpful also! Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "151fraction.h"
#include <iostream>
using namespace std;

int main(){
	Fraction one(1,2);
	Fraction two(2,3);
	 (one.print()) ;
	Fraction product = one.multiply(two);
	product.print();
	Fraction added =one.add(two);
	added.print();
	Fraction subtracted = one.subtract(two);
	subtracted.print();
	Fraction divided = one.divide(two);
	cout<< "When the fractions are divided the answer is: " << divided.print() << endl;

	return 0;
}

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
/*
* 
* Stubbed Fraction Class Header File
*/
class Fraction{
private:
	int numerator;
	int denominator;
public:
	Fraction(int num = 0,int denom = 1);

	Fraction add(const Fraction&) const;
	Fraction subtract(const Fraction&) const;
	Fraction multiply(const Fraction&) const;
	Fraction divide(const Fraction&) const;

	void read() const;
	void print() const;
	void reduce();
	bool isSmaller(Fraction &f) const;


};



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
/*
* 
* Stubbed Fraction Class .CPP File
*/

#include "151fraction.h"
#include <iostream>
using namespace std;


// Constructor
Fraction::Fraction(int num, int denom){
	numerator = num;
	denominator = denom;
}

// Addition Method
Fraction Fraction::add(const Fraction &variable) const{
	Fraction added;
	added.numerator = ((numerator * variable.denominator) + (variable.numerator * denominator));
	added.denominator =  (denominator * variable.denominator);
	return added;
}

//Subtraction Method
Fraction Fraction::subtract(const Fraction &var) const{
	Fraction subtracted;
	subtracted.numerator = ((numerator * var.denominator) + (var.numerator * denominator));
	subtracted.denominator =  (denominator * var.denominator);
	return subtracted;;
}

//Multiplication Method
Fraction Fraction::multiply(const Fraction &multiplier) const{
	Fraction product;
	product.numerator = numerator * multiplier.numerator;
	product.denominator = denominator * multiplier.denominator;
	return product;
}

//Division Method
Fraction Fraction::divide(const Fraction &divisor) const{
	Fraction quotient;
	int temp = divisor.numerator;
	int newdenom = divisor.numerator;
	int newnum = divisor.denominator;
	quotient.numerator = numerator * newnum;
	quotient.denominator = denominator * newdenom;

	return quotient;
}


// Reading Method
void Fraction::read() const{

}

//Display Method
void Fraction::print() const{
	cout << numerator << "/" << denominator << endl;
}

//Reduce Method
void Fraction::reduce(){
}

//Comparison Method
bool Fraction::isSmaller(Fraction &f)const{
	if( (((double)numerator)/denominator)) < (((double)f.numerator)/f.denominator))){
		return true;};

}

There is no use to pass void to cout. Just place divided.print() routine in their own statement.
As for if, your parenthesises in condition aren't balanced. just remove them all and olace where needed.
line 71 and 30: redundant semicolons
Last edited on
Topic archived. No new replies allowed.