Question: Implement a complete C++ program that includes a class definition for a class named Eggs. The Eggs class should be written such that the given
Implement a complete C++ program that includes a class definition for a class named Eggs.
The Eggs class should be written such that the given main function produces the output shown below. As always, make sure that your output mimics the format of the provided output precisely. The Eggs class must contain an appropriate data member or data members. Provide constructor definition(s), if necessary. Provide an overloaded operator definition for +, which returns the sum of two Eggs objects. Implement a smash member function which subtracts a specified number of eggs from the eggs stored in an Eggs object. Implement smash so that it can be called in a cascaded/chained manner (see main below). Implement overloaded input and output operators. For the input operator, no input validation is necessary. For the output operator, print the number of eggs in an Eggs object by separating them into dozens and singles.
A dozen eggs equals 12 eggs. Therefore, if an Eggs object holds 27, the output operator should print 2 dozen, 3 single(s)
Note:
As always, for every member function and overloaded operator, use the appropriate access modifier const,static, or nothing.
As always, for every parameter, declare it appropriately using pass-by-value, pass-by-reference, and/orconst.
int main()
{
Eggs eggs1, eggs2;
Eggs eggs3(13);
Eggs eggs4;
cout << "Number of eggs in the 4th group: ";
cin >> eggs4;
eggs1 = eggs2 + eggs3 + eggs4;
eggs1.smash(1).smash(2);
cout << eggs1 << endl;
cout << eggs3 << endl;
} // end main
Sample session:
Number of eggs in the 4th group: 30
3 dozen, 4 single(s)
1 dozen, 1 single(s)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
