How do I save values from a class? And overload operators?

I have this:
Class
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
class Rational
 {
 public:
	 int fraction(){//default to do 0/1 auto
	 numerator = 0;
	 denominator = 1;}
      
	 int fraction(int n, int d ){
	 numerator = n;
	 denominator = d; 
	 return 0;}

	 int fraction(int d){
		 d = denominator;
		 if (d == 0) {cout<<"Cannot divide by 0!"<<endl;}
	 else denominator = d;
	 return denominator;
	 }
	
	 int Number(int wholeNumber){
	 wholeNumber = numerator;
	 denominator = 1;
	 }
	 
	 friend ostream& operator << (ostream& outStream, const Rational& r );
	 friend istream& operator >> (istream& inStream, Rational& r);
 private:
  int numerator, denominator;
 };

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 Rational rat1, rat2, rat3, rat4 ,rat5;
	cout<<"Enter a rational number: ";
		cin >> rat1;
		cout<<endl;
	cout<<"Enter another rational number: ";
         cin>>rat2;
         cout <<endl;
   cout<<"Enter another rational number: ";
         cin>>rat3;
         cout<<endl;
   cout<<"Enter another rational number: ";
         cin>>rat4;
         cout<<endl;
   cout<<"Enter another rational number: ";
         cin>>rat5;
         cout<<endl;


But none of the values print out if I do something like cout<<rat5 How do I make it save my values so I can use it?
Because I need to use this

If( (ratNum1/ratNum2) == (ratNum3)
cout << ratNum1+ratNum4;
else
cout << ratNum1-ratNum5;

to see if my function overloads correctly and I get many errors when I paste that in (after I change variable names of course)
You don't define default ctor, copy ctor and assignment operator so defaults will be provided. Define them yourself to control them. Why do you use fraction() and Number() instead?

You don't define operators >> and << so this is an error.

You don't specify any operator/ so this won't work ratNum1/ratNum2.
Topic archived. No new replies allowed.