CLASS Access Specifiers
source link: https://sqlwithmanoj.com/2010/01/12/c-program-to-implement-toll-tax-problem-by-using-class-access-specifiers-and-switch-case-q12/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C++ Program to implement Toll Tax Problem by using CLASS Access Specifiers and SWITCH CASE – Q12
Q12. Program to implement Toll Tax Problem by using CLASS Access Specifiers and SWITCH CASE:
Calculate the toll tax for cars passing by a toll bridge @ Rs 5 per car (use the concept static data members). Calculate and Print the following details:
– Total no of cars passed with paying the tax
– Total amount of tax paid
– Total no of cars passed without paying tax.
… from College notes (BCA/MCA assignments):
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
class
TollBridge{
private
:
static
int
car_yes, car_no;
static
int
amt;
public
:
static
void
GetCar();
static
void
PutCar();
};
int
TollBridge::car_yes = 0;
int
TollBridge::car_no = 0;
int
TollBridge::amt = 0;
void
TollBridge :: GetCar(){
char
ch;
cout<<
"\n Total Cars Passed: "
<<car_yes+car_no;
cout<<
"\n This Car:- "
;
cout<<
"\n Paid Tax (y/n) ?: "
;
cin>>ch;
if
(ch ==
'y'
){
car_yes++;
amt += 5;
}
else
car_no++;
}
void
TollBridge :: PutCar(){
cout<<
"\n Total Car Passed: "
<<car_yes+car_no<<endl;
cout<<
"\n\t Car Passed by giving Tax: "
<<car_yes;
cout<<
"\n\t\t Amount Recieved: "
<<amt<<endl;
cout<<
"\n Car Passed by not giving Tax: "
<<car_no;
}
void
main(){
int
ch;
char
choice;
while
(1){
clrscr();
cout<<
"\n TOLL TAX PLAZA"
;
cout<<
"\n ~~~~~~~~~~~~~~"
;
cout<<
"\n 1 -> Entry of CARS."
;
cout<<
"\n 2 -> Report of CARS."
;
cout<<
"\n 3 -> Exit."
;
cout<<
"\n Enter your choice: "
;
cin>>ch;
switch
(ch){
case
1:
while
(1){
TollBridge::GetCar();
cout<<"\n Do you want to
continue
(y/n) ?: ";
cin>>choice;
if
(choice ==
'n'
)
break
;
}
break
;
case
2:
TollBridge::PutCar();
getch();
break
;
default
:
exit
(1);
}
// end of switch.
}
// end of while.
}
// end of main.
Output:
TOLL TAX PLAZA
1 -> Entry of CARS.
2 -> Report of CARS.
3 -> Exit.
Enter your choice: 1
Total Cars Passed: 0
This Car:-
Paid Tax (y/n) ?: y
Do you want to continue (y/n) ?: y
Total Cars Passed: 1
This Car:-
Paid Tax (y/n) ?: y
Do you want to continue (y/n) ?: y
Total Cars Passed: 2
This Car:-
Paid Tax (y/n) ?: y
Do you want to continue (y/n) ?: y
Total Cars Passed: 3
This Car:-
Paid Tax (y/n) ?: n
Do you want to continue (y/n) ?: y
Total Cars Passed: 4
This Car:-
Paid Tax (y/n) ?: n
Do you want to continue (y/n) ?: y
Do you want to continue (y/n) ?: n
TOLL TAX PLAZA
1 -> Entry of CARS.
2 -> Report of CARS.
3 -> Exit.
Enter your choice: 2
Total Car Passed: 5
Car Passed by giving Tax: 3
Amount Recieved: 15
Car Passed by not giving Tax: 2
Related
Recommend
-
27
Raymond August 30th, 2019 Windows adopted Unicode before most other operating systems. [citation ne...
-
6
Type Specifiers in C, Part 3mikeash.com: just this guy, you know? Friday Q&A 2009-07-10: Type Specifiers in C, Part 3 by Mike Ash Here at la...
-
3
Type Specifiers in C, Part 2mikeash.com: just this guy, you know? Friday Q&A 2009-07-03: Type Specifiers in C, Part 2 by Mike Ash Welcome to...
-
3
Home > Cpp > C++ Program to maintain a Cricket Team by using CLASS with PUBLIC & PRIVATE Access Specifiers – Q9 C...
-
4
C++ For C# Developers: Part 34 – Fold Expressions and Elaborated Type Specifiers January 4, 2021 Tags: generic,
-
4
In this article, we will learn how to access variable from another class in java. There are two ways to get variables from another class. Create an object of another class in the main class Extend another class in...
-
3
Copy link Contributor FabianWolff commented
-
8
Home > Cpp > C++ Program to maintain Student Result by using CLASS with PUBLIC & PRIVATE Access Specifiers – Q7
-
15
Home > Cpp > C++ Program to work with Purchase Order Problem by using Pointers and CLASS with PUBLIC & PRIVATE Access Spec...
-
2
Conversation Contributor...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK