Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

Imagine a tollbooth with a class called toll Booth. The two data items of a type unsigned int to hold the total number of cars, and a type double to hold the total amount of money collected. A constructor initializes both these to 0. A member function called payingCar() increments the car total and adds 0.50 to the cash total. Another function, called nopayCar() increments the car total but adds nothing to the cash total. Finally, a member function called displays the two totals.


#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
class tollbooth
{
unsigned int car;
double amt;
public:
tollbooth()
{
car=0;
amt=0;
}
void payingcar()
{
car++;
amt+=0.50;
}
void nopayingcar()
{
car++;
}
void display()
{
cout<<"Total cars: "<<car;
cout<<"Total amount: "<<amt;
}};
int main()
{
clrscr();
char ch,c;
tollbooth t;
do{
cout<<" 1 for paying \n 2 for nopaying \n 3 for exit \n";
cout<<"Enter choice \n";
cin>>ch;
switch(ch)
{
case'1':
t.payingcar();
cout<<"car added";
break;
case'2':
t.nopayingcar();
cout<<"car added";
break;
case'3':
t.display();
exit(0);
break;
}
cout<<"\n Do you want to continue";
cin>>c;
}
while(c=='y'||c=='Y');
return 0;
}



Output


Previous
Next Post »