Question: using this code for c + + : #include using namespace std; class Mass { public: Mass ( double kilograms = 0 . 0 ,
using this code for c: #include
using namespace std;
class Mass
public:
Massdouble kilograms double grams ;
void Print const;
Mass operatorMass rhs;
Mass operatordouble rhs;
private:
double kg;
double g;
;
Mass::Massdouble kilograms, double grams
kg kilograms;
g grams;
No need to accommodate for overflow or negative values
Your code goes here
Mass Mass::operatorconst Mass& rhs const
double totalKg kg rhskg;
double totalG g rhsg;
if totalG
totalKg totalG ;
totalG staticcasttotalG;
return MasstotalKg totalG;
void Mass::Print const
cout kg kilograms, g grams";
int main
double kilograms;
double grams;
double kilograms;
double grams;
cin kilograms;
cin grams;
cin kilograms;
cin grams;
Mass masskilograms grams;
Mass masskilograms grams;
Mass sum mass mass;
Mass sum mass kilograms;
massPrint;
cout endl;
massPrint;
cout endl;
cout "Sum: ;
sumPrint;
cout endl;
cout endl;
massPrint;
cout endl;
cout kilograms kilograms" endl;
cout "Sum: ;
sumPrint;
cout endl;
return ;
Four doubles are read from input, where the first two doubles are the kilograms and grams of mass and the second two doubles are the kilograms and grams of mass Define two functions to overload the operator. The first function overloads the operator to add two masses. The second function overloads the operator to add a mass and a double representing the number of kilograms.
Ex: If the input is then the output is:
kilograms, grams
kilograms, grams
Sum: kilograms, grams
kilograms, grams
kilograms
Sum: kilograms, grams
Note: The sum of two masses is:
the sum of the number of kilograms
the sum of the number of grams
Note: The sum of a mass and a double representing the number of kilograms is:
the sum of the number of kilograms and the double
the number of grams is unchanged
Jump to level
Four doubles are read from input, where the first two doubles are the kilograms and grams of mass and the second two doubles
are the kilograms and grams of mass Define two functions to overload the operator. The first function overloads the
operator to add two masses. The second function overloads the operator to add a mass and a double representing the number
of kilograms.
Ex: If the input is then the output is:
kilograms, grams
kilograms, grams
Sum: kilograms, grams
kilograms, grams
kilograms
Sum: kilograms, grams
Note: The sum of two masses is:
the sum of the number of kilograms
the sum of the number of grams
Note: The sum of a mass and a double representing the number of kilograms is:
the sum of the number of kilograms and the double
the number of grams is unchanged #include g grams;
No need to accommodate for overflow or negative values
Your code goes here
void Mass::Print const
cout kg kilograms, g grams";
int main
double kilograms;
double grams;
double kilograms;
double grams; cin kilograms;
cin grams;
cin kilograms;
cin grams;
Mass masskilograms grams;
Mass masskilograms grams;
Mass sum mass mass;
Mass sum mass kilograms;
massPrint;
cout endl;
massPrint;
cout endl;
cout "Sum: :cout endl;
cout "Sum: ;
sumPrint;
cout endl;
cout endl;
massPrint;
cout endl;
cout kilograms kilograms" endl;
cout "Sum: ;
sumPrint;
cout endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
