Start New Discussion within our Software Development Community

alright, here i have this code i wrote....but it tells me now i have to have a public member function that will add two rational numbers, and have the result be stored in reduced form.......hmmmmmm......heres my code:

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

class rational {

int setrat( int x, int y); 
int getnum(); 
int getdenom(); 


int numerator;
int denominator;

}; // end of rational class

numerator = 1;
denominator = 1;
int rational::setrat( int x, int y) 
numerator = x;
denominator = y; 
int rational::getnum() 
return (numerator);
int rational::getdenom() 
return (denominator);


#include "Rationall.h"

int main()
using namespace std;
int x, y;
rational rationl; 

cout << "Enter in a fraction" << endl;
cout << "Enter in the numerator" << endl;
cin >> x;
cout << "Enter in the denominator" << endl;
cin >> y;

rationl.setrat( x, y );

cout << "The fraction: " << endl;
cout << rationl.getnum() << rationl.getdenom() << endl;

return 0; 

[The title does not provoke much interest or specify what you are really trying to do. Expend a little more thought for something like, "Adding and Reducing Fractions". Such things show you have thought about the problem and perhaps done some searching for related information.]

With regard to reducing the fractions, you may want to search for a GCD (greatest common divisor) algorithm or code.

Then show an attempt to add fractions, rather than just posting code that makes absolutely no attempt and tries to exract completed homework from the members here. It is rude and insulting to do this "fill in the blanks for me" stuff.

This article has been dead for over six months. Start a new discussion instead.