Following is the definition for a class called Percent. Objects of type
Percent represent percentages such as 10% or 99%. Give the definitions
of the overloaded operators >> and << so that they can be used for input and output with objects of the class Percent. Assume that input always consists of an integer followed by the character ‘%’, such as 25%. All percentages are whole numbers and are stored in the int member variable named value. You do not need to define the other overloaded operators and do not need to define the constructor. You only have to define the overloaded operators >> and <<.
using namespace std;
class Percent
{
public:
friend bool operator ==(const Percent& first,
const Percent& second);
friend bool operator <(const Percent& first,
const Percent& second);
Percent( );
Percent(int percent_value );
friend istream& operator >>(istream& ins,
Percent& the_object);
//Percent.
//Precondition: If ins is a file input stream, then ins
//has already been connected to a file.
friend ostream& operator <<(ostream& outs,
const Percent& a_percent);
//Overloads the << operator for output values of type
//Percent.
//Precondition: If outs is a file output stream, then
//outs has already been connected to a file.
private:
int value;
};
Sorry the answer is not available at the moment…
If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.
Spread the 'tradition of sharing'.