Hello everyone. I am in desperate need of help. I have this question:
You have been developing a Fraction class for Teacher's Pet Software. The class contains two public data fields: one numerator and one for denominator. In keeping with the object-oriented concept of encapsulation, you make the Fraction's data private. Client programs access the Fraction's data through public functions you create.
Here is what I have so far:
#include<iostream.h>
#include<conio.h>
class Fraction
{
public:
int numer;
int denom;
}
There is more to the question, but I'm trying to get one part at a time.
Here is the other part, I am trying my best to understand this, but for some reason I find C++ a little difficult to read.
Declare the Fraction's numerator and denominator to be private. Add two more private fields: a double that can hold the Fraction's decimal value and a static character field that can hold the Fraction's decimal value, and a static character field that holds the slash all Fractions use when displaying their values.
In the public portion of the Fraction's declaration section, protype an enterFractionValue() function that allows you to enter values for a Fraction's numerator and denominator. Do not allow the user to
enter a value of 0 for the denominator of any Fraction.
Within the enterFractionValue() function, after the two data fields have received valid values call a private calculateDecimalValue() function that computes the floating-point decimal equivalent of the Fraction.
In the public portion of the Fraction's declaration section, also protype a displayFraction() function that displays a Fraction. This function propts the user to enter a 1 to see the Fraction in fraction format (with the slash between the numerator and denominator), or a 2 to see the Fraction in floating-point format.
Write a main() program that declaraes a Fraction object and confirm that the class works correctly.
I am going to keep on working on it and keep checking for responses. I hope everyone is enjoying their day.