Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Separate the program into three4 files: the class interface, the class implementation, and the driver. ------------------------------------------------------------------------------------ //Program: Money counter #include #include #include using namespace std;

Separate the program into three4 files: the class interface, the class implementation, and the driver.

------------------------------------------------------------------------------------ //Program: Money counter

#include #include #include using namespace std;

class Counter{ public: void incr1 (); // increment by 1 void incr10 (); // increment by 10s void incr100 (); // increment by 100s void incr1000 (); // increment by 1000s void reset (); // reset the calculator int CounterValue (); bool over; int value; Counter (int max); private: int num; int max; };

// set letters parameters for the count bool letters(char valueEntered) { if (valueEntered == 'c') return true; if (valueEntered == 'm') return true; if (valueEntered == 'd') return true; if (valueEntered == 't') return true; if (valueEntered == 'r') return true; return false; } Counter::Counter(int letterEntered) { num = 0; max = letterEntered; over =false; return; }

// all the increments void Counter::incr1() { num +=1; } void Counter::incr10() { num += 10; } void Counter::incr100() { num += 100; } void Counter::incr1000() { num += 1000; }

// reset function to reset to zero void Counter::reset() { num = 0*num; } int Counter::CounterValue() { return num; }

int main() { char valueEntered; Counter counter(1000000); // give the user a list of available options cout << "Select one of the following: (C) for cents (M) for dimes (D) for dollars (T) for hundreds (R) to reset" << endl; cout << "Enter your selection: "; cin >> valueEntered; // calculate the total until the user requests to reset back to zero by clicking R // c to add cents, m to add in the dime section, d to add dollars, t to add thousands, r to reset to zero while (letters(valueEntered)) { switch (valueEntered){ {case 'c': if (valueEntered == 'c') counter.incr1(); cout << "You spent this much: $" << counter.CounterValue() << endl; break;} {case 'm': if (valueEntered == 'm') counter.incr10(); cout << "You spent this much: $" << counter.CounterValue() << endl; break;} {case 'd': if (valueEntered == 'd') counter.incr100(); cout << "You spent this much: $" << counter.CounterValue() << endl; break;} {case 't': if (valueEntered == 't') counter.incr1000(); cout << "You spent this much: $" << counter.CounterValue() << endl; break;} {case 'r': if (valueEntered == 'r'){ counter.reset(); cout << "Reset Successful" << endl; break;} } } cout << "Enter a selection: "; cin >> valueEntered; } cout << endl; cout << "You spent: $"; cout << counter.CounterValue() << endl; system ("pause"); // program pauses and reruns and show the total }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago