Write a class definition for a Fraction class. Its member fields are num and den, both of type int. The constructor builds the default fraction 1/1. It has the following operations:

void plusEquals(Fraction second); //Adds the second fraction to this fraction like the operator += void minusEquals (Fraction second); //Subtracts the second fraction from this fraction void timesEquals (Fraction second); //Divides this fraction by the second fraction void dividesEquals (Fraction second); // Divides this fraction by the second fraction void reduce(); // Reduces this fraction to lowest terms double todecimal(); //returns the decimal value of this fraction void scan(istream&); //scans a fraction written with a slash as in ¾ void print(ostream&); //prints a fraction using a slash Fraction(); //constructs a default fraction with denominator 1, numerator 0 Fraction(int n, int d); //constructs a fraction given value for num and den

2. Write a menu-driven driver program designed to allow thorough testing of your Fraction class.

void plusEquals(Fraction second); //Adds the second fraction to this fraction like the operator += void minusEquals (Fraction second); //Subtracts the second fraction from this fraction void timesEquals (Fraction second); //Divides this fraction by the second fraction void dividesEquals (Fraction second); // Divides this fraction by the second fraction void reduce(); // Reduces this fraction to lowest terms double todecimal(); //returns the decimal value of this fraction void scan(istream&); //scans a fraction written with a slash as in ¾ void print(ostream&); //prints a fraction using a slash Fraction(); //constructs a default fraction with denominator 1, numerator 0 Fraction(int n, int d); //constructs a fraction given value for num and den

2. Write a menu-driven driver program designed to allow thorough testing of your Fraction class.

You've pretty much been told exactly what the class should contain. Write the declaration. Then write the code for the methods given. The tutorial referenced by Zhuge explains the basics of a class.

Topic archived. No new replies allowed.