All pastes #39072 Raw Edit

lotus_anima

public cpp v1 · immutable
#39072 ·published 2006-01-29 23:37 UTC
rendered paste body
// Jan 29 2006 by Dustin McCormick < djmccormick@gmail.com >// Tested with gcc version 3.3.4 on GNU/Linux 2.4.29 i686//// gcc: 	http://gcc.gnu.org/// GNU: 	http://www.gnu.org/// Linux: 	http://www.kernel.org/#include <iostream>using namespace std;class Counter{    public:	Counter(int size);	Counter();	void reset();	void incr1(short int x=1);	void incr10(short int x=1);	void incr100(short int x=1);	void incr1000(short int x=1);	void showMenu();	void getOperation();	bool doOperation(char x, int y);	bool overflow();    private:	int countLimit;	int countCurrent;};int main(){	int size;	cout << "Welcome to the counter program.\n" << endl;	cout << "Please enter the maximum value that this counter will hold: ";	cin >> size; cout << endl;	Counter myCounter(size);	myCounter.showMenu();	return 0;}Counter::Counter(int size) : countLimit(size), countCurrent(0){}Counter::Counter() : countLimit(9999), countCurrent(0){}void Counter::reset(){	countCurrent = 0;}void Counter::incr1(short int x){	if(x > 9 || x < 0){		cout << "ERROR: Illegal argument @ Counter::incr1(x)" << endl;		exit(1);	} else{		countCurrent += (x*1);	}}void Counter::incr10(short int x){	if(x > 9 || x < 0){		cout << "ERROR: Illegal argument @ Counter::incr1(x)" << endl;		exit(1);	} else{		countCurrent += (x*10);	}}void Counter::incr100(short int x){	if(x > 9 || x < 0){		cout << "ERROR: Illegal argument @ Counter::incr1(x)" << endl;		exit(1);	} else{		countCurrent += (x*100);	}}void Counter::incr1000(short int x){	if(x > 9 || x < 0){		cout << "ERROR: Illegal argument @ Counter::incr1(x)" << endl;		exit(1);	} else{		countCurrent += (x*1000);	}}void Counter::showMenu(){	cout << "CENTS:\t\t\ta{1-9}" << endl;	cout << "DIMES:\t\t\ts{1-9}" << endl;	cout << "DOLLARS:\t\td{1-9}" << endl;	cout << "TENS OF DOLLARS:\tf{1-9}" << endl;	cout << "QUIT:\t\t\tx" << endl;	cout << "Example: a9, means 9 cents." << endl;}void Counter::getOperation(){	char x;	short int y;	cout << "\nOperation: ";	cin >> x;	cout << "\nNumber: ";	cin >> y;	Counter::doOperation(x, y);}bool Counter::doOperation(char x, int y){	bool continue = true;	switch(x){	    case 'a':		incr1(y);		break;	    case 's':		incr10(y);		break;	    case 'd':		incr100(y);		break;	    case 'f':		incr1000(y);		break;	    case 'x':		continue = false;		break;	    default:		cout << "ERROR: Illegal input @ Counter::showMenu" << endl;		cout << "continuing..." << endl;		break;	}	return continue;}bool Counter::overflow(){	if(countCurrent > countLimit){		return true;	} else{		return false; 	}}