The C++ Side Restaurant wants you to write a program that simulates a simple cas
ID: 3529113 • Letter: T
Question
The C++ Side Restaurant wants you to write a program that simulates a simple cash register. The program should ask the user if a customer is to be processed. If the user responds yes, the program prompts the user to enter the price of the meal. Then the program calculates the sales tax (8.25% of the meal price) and the total price, which it should display to the user. Next, the program asks the user to enter the amount tendered, and displays the amount tendered, the total price, and the customerExplanation / Answer
// Change.h class Change { private: int numTwenties; int numTens; int numFives; int numOnes; int numQuarters; int numDimes; int numNickels; int numPennies; public: Change(); Change( double dollars ); Change( int twenties, int tens, int fives, int ones, int quarters, int dimes, int nickels, int pennies ); double AmountInDollars(); void SetAmount( double dollars ); // I would probably add a method for setting/getting each of the twenties/tens/etc. void SetTwenties( int twenties ); int GetTwenties(); }; CPP / C++ / C Code: // Change.cpp // Default constructor Change::Change() { SetAmount( 0.00 ); } Change::Change( double dollars ) { SetAmount( dollars ); } void SetAmount( double dollars ) { numTwenties = 0; numTens = 0; numFives = 0; numOnes = 0; numQuarters = 0; numDimes = 0; numNickels = 0; numPennies = 0; while( dollars >= 20.00 ) { numTwenties++; dollars -= 20.00; } while( dollars >= 10.00 ) { numTens++; dollars -= 10.00; } while( dollars >= 5.00 ) { numFives++; dollars -= 5.00; } while( dollars >= 1.00 ) { numOnes++; dollars -= 1.00; } while( dollars >= 0.25 ) { numQuarters++; dollars -= 0.25; } while( dollars >= 0.10 ) { numDimes++; dollars -= 0.10; } while( dollars >= 0.05 ) { numNickels++; dollars -= 0.05; } while( dollars >= 0.01 ) { numPennies++; dollars -= 0.01; } } double AmountInDollars() { return 20.0*numTwenties + 10.0*numTens + 5.0*numFives + numOnes + 0.25*numQuarters + 0.1*numDimes + 0.05*numNickels + 0.01*numPennies; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.