Storing Fractions in an Array

I am currently working on an assignment using classes with fractions. I am almost finished but the last part of the assignment is to store 3 fractions in an array and print them. Arrays confuse me to no end. Could someone point me in the right direction? Here is my code so far:

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
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

class fraction
{
private:
	int numerator, denominator; //Data members that store the numerator and denominator respectively.

public:
	fraction(); //A default constructor that takes no parameters.

	fraction(int n, int d); //A constructor that takes 2 int parameters

	void print(); //A public method that will print out the fraction

	void set_numerator(int num); //A public method that sets the numerator to the desired value.

	void set_denominator(int denom); //A public method that sets the denominator to the desired value.
};



int main(){
fraction fraction1;
	int num1;
	int denom1;
		do{
		cout << "Enter your Numerator and Denominator" << endl;
		cin >> num1;
		cin >> denom1;
		fraction1.set_numerator(num1);
		fraction1.set_denominator(denom1);
		fraction1.print();
		}while(denom1 != 0);






return 0;
}

fraction::fraction()
{
	numerator = 0;
	denominator = 1;  //Set numerator to 0 and denominator to 1.
	int set_numerator(0);
	int set_denominator(1);  //Alternatively, call set_numerator(0) and set_denominator(1)
}

fraction::fraction(int n, int d)
{
	int set_numerator(n);
	int set_denominator(d);	//call set_numerator(n), call set_denominator(d)
}

void fraction::print()
{
	cout << numerator << "/" << denominator << endl;  //print out (numerator)/(denominator)
}

void fraction::set_numerator(int num)
{
	numerator = num;  //set numerator to num.
}

void fraction::set_denominator(int denom)
{
	denominator = denom;
	if(denom == 0){
		cout << "You cannot divide by 0. Thou art not Chuck Norris." << endl;
		
	}
}

Topic archived. No new replies allowed.