Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7) Given the following definition for the class Money: class Money private: int

ID: 2250051 • Letter: 7

Question

7) Given the following definition for the class Money: class Money private: int dollars; int cents; public: void setValue (int d, int c); void addValue (int d, int c); X; void Money::setValue(int d, int c) dollars d; cents = c; From the 4 options below, select the correct addValue function definition such that each time a cent amount is added, the total dollar amount is properly updated once we go over 99 cents. That is, the number of cents after the addition should never exceed 99 and if exceeded it should add a unit to the dollar amount. a) void Money::addValue(int d, int c) dollars dollarsd cents cents C; b) void Money: :addValue(int d, int c) dollars = dollars + d; cents if (cents 99) cents + c; dollars = dollars (cents % 100); cents = cents / 100; c) void Money::addValue(int d, int c) dollars = dollars + d; cents if (cents 99) cents + c; dollars = dollars + (cents / 100); cents = cents / 100; d) void Money::addValue(int d, int c) dollars = dollars + d; cents cents + c; if (cents99) dollars -dollars (cents 100); cents = cents 100;

Explanation / Answer

d) void Money :: addValue (int d, int c)

{

dollars = dollars + d;

cents = cents + c;

if (cents> 99)

{

dollars = dollars + (cents / 100);

}

cents = cents% 100;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote