Problem with fraction class

My program is supposed to have a Fraction class that can add two fractions and be able to display an object's data values. I'm thinking that I should have a different manner of allowing the two fractions to be entered, but I'm not really sure how to go about it. Any suggestions?
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
  #include <iostream>
#include <cmath>

using namespace std;

int a, b, c;

class Fractions
{
    private:
 int num;
 int denom;
 public:
 Fractions(int=1, int=1);
 void operator!(void) const;
 Fractions operator+(const Fractions&) const;
};

Fractions::Fractions(int n, int d)
{
    if( d != 0)
    num= n;
    denom= d;
}

Fractions Fractions::operator+(const Fractions& f) const
{
    int nu;
    int de;
    cout << "Enter the first numerator: " << endl;
    cin >> num;
    cout << "Enter the second denominator: " << endl;
    cin >> denom;
    cout << "Enter the second numerator: " << endl;
    cin >> nu;
    cout << "Enter the second denominator: " << endl;
    cin >> de;
    if (de=0)
    {
        cout << "Please enter a non-zero number for the second denominator: " << endl;
        cin >> de;
    }
    a= num/denom;
    b= nu/de;
    c= a + b;
    c= (num * de+ denom * nu)/(denom * de);
    return c;
}

int main()
{  
   return 0;
}
The more preferable way for this to work would be so that in main(), you first input the numerator and denominator to the first fractions class. Those would then be put into the actual class via a constructor. Then repeat with a second, add the two, and display the results (preferably with a display command other than accessing the elements directly, but either works).
The Fractions class is supposed to have num and denom as integer data members
Yes, and they will remain as such. The way I proposed simply initializes them via constructor versus using a function within the actual fractions class as to add two fractions (which is a misnomer anyway since it would only make sense to add two fractions as two different classes using +, not actually requiring any input). Both are still data members, but they way they are assigned is through main, not a function within Fractions. Besides, in regards to object-oriented programming, it makes more sense.

Think of it this way- is the Fractions class supposed to act as a de-facto fraction operation menu, or is each object of the Fractions class supposed to act as a fraction with a numerator and denominator that can be added, subtracted, multiplied and divided by one-another?
Topic archived. No new replies allowed.