Menu

Saturday, 3 August 2013

Chapter 6, Problem 2:Object Oriented Programming by Robert Lafore in C++ Solution Manual

//Engr Ahmad Furqan Attari
//Chapter 6, Program 2
#include <iostream>
#include <conio.h>
using namespace std;
char getkey(void);
class toolBooth
{
private:
unsigned int cars;
double money;
public:
toolBooth():cars(0),money(0)
{}
void payingCar(void)
{
cars++;
money+=0.5;
}
void nopayCar(void)
{
cars++;
}
void display(void)
{
cout<<"Total number of cars passed: "<<cars<<endl
<<"Total amount of money collected: "<<money<<endl;
}
};
void main(void)
{
char choice;
toolBooth booth;
do
{
cout<<"Enter p to count paying car"<<endl
<<"Enter n to count nopaying car"<<endl
<<"Enter Esc to show result and exit "<<endl
<<"Enter your choice: ";
choice=getkey();
switch(choice)
{
case 'p':
cout<<'p'<<endl;
booth.payingCar();
break;
case 'n':
cout<<'n'<<endl;
booth.nopayCar();
break;
case 27:
cout<<"Esc"<<endl;
booth.display();
break;
default:
cout<<"Invalid input "<<endl;
}
}while(choice!=27);
getch();
}
char getkey(void)
{
char ch;
if((ch=getch())==0)
return getch();
else
return ch;
}

No comments:

Post a Comment