"Define a class for rational numbers. A rational number is a number that can be represented as the quotient of
two integers. For example, 1/2, 3/4, 64/2, and so forth are all rational numbers. (By 1/2 and so on we mean the
everyday fraction, not the integer division this expression would produce in a C++ program.)
Represent rational numbers as two values of type int, one for the numerator and one for the denominator.
Call the class Rational.
Include a constructor with two arguments that can be used to set the member variables of an object to
any legitimate values.
Also include a constructor that has only a single parameter of type int; call this single parameter
wholeNumber and define the constructor so that the object will be initialized to the rational number
wholeNumber/1.
Include a default constructor that initializes an object to 0 (that is, to 0/1). "
Verbatim
As far as I can see, there is nothing to do except overload and input fractions/rational numbers.
Other than that I don't know what the point of the assignment is other than fractions
"Overload the input and output operators >> and <<. Numbers are to be input and output in the form 1/2,
15/32, 300/401, and so forth. Note that the numerator, the denominator, or both may contain a minus sign, so -
1/2, 15/-32, and -300/-401 are also possible inputs.
Overload all the following operators so that they correctly apply to the type Rational: ==, +, -, *, and /.
Declare a predefined class vector object (please read the book for details about the class vector) and
add these 5 rational numbers to the vector object. Access the elements in the vector and print them.
Then, delete the element in the middle of the vector. At this point, you need to figure out how you can
delete an element from a vector? Then, please print the values again to see the change in the vector. "
This is all I have so far:
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
|
#include <iostream>
#include <vector>
using namespace std;
class Rational{
public:
int x, y;
int fraction(int, int);
int wholeNumber(int);
private:
};
int main()
{
Rational rat;
cout<<"Enter your number: "<<endl;
cin>>rat.x;
cin.ignore(1);
cin>>rat.y;
rat.y;
cout<<rat.x<<"/"<<rat.y;
system("Pause");
return 0;
}
|