In: Computer Science
● The Faculty & Staff parking permit allows a car to park in YELLOW and GREEN slots. User
can purchase multiple Faculty & Staffparking permit.
● The Student parking permit allows a car to park in GREEN slots. User can purchase multiple
student parking permit.
● The Resident parking permit allows a car to park in ORANGE and GREEN slots. User can add
a premium package to this kind of permit that allows one of user’s friend to share this permit, but
each user can only purchase one Resident parking permit.
● The Visitor parking permit allows a car to park in ORANGE, YELLOW and GREEN slots.
The permit is only valid for one day and user can only purchase one Visitor parking permit.
User can purchase more than one type of ticket at a time, as many Faculty & Staff and student as
they choose.
Your goal is to write a program that sells the permits and using the existing functions in
hw4a.cpp.
//--------------------------------------------------------------------------- // This is the main program that you need to write //--------------------------------------------------------------------------- int main () { // Variable Declarations char Choice = '\0'; // what the user enters int NumPermits = 0; // how many permits they want to buy int TotalPermits = 0; // total number of permit sold so far float Price = 0.0; // the price of one set of permit float TotalPrice = 0.0; // the total price of all permits char ExitChoice = 'N'; //whether or not the user wants to exit // Print your name and ID cout << "Name: \n" <<"ID: \n\n"; // Loop until the user is done // Print the main menu describing the tickets offered // Ask the user type what permit they want to purchase next // If the user selects Faculty&Staff parking permit calculate the price of tickets // If the user selects Student parking permit be sure to note the reference parameters // If the user selects Resident parking permit, ask if they want the premium package // If the user selected visitor parking permit, make sure they decided to order them // Add the permit price to a running total //Add the number of permits to a running total // Ask if they want to continue (Y or N) // When the loop is done // Print out the total number of permits sold, and the amount of all the permits, with a $. return 0; }
#include <iostream>
using namespace std;
int main ()
{
// Variable Declarations
char Choice = '\0'; // what the user enters
int NumPermits = 0; // how many permits they want to buy
int TotalPermits = 0; // total number of permit sold so far
float Price = 0.0; // the price of one set of permit
float TotalPrice = 0.0; // the total price of all permits
char ExitChoice = 'N'; //whether or not the user wants to exit
char name[20];
char id[20];
cout<<"Enter Your name and ID"<<endl;
cin>>name>>id;
// Print your name and ID
cout << name <<"\n"<<id<<"\n";
// Loop until the user is done
while(Choice!=ExitChoice)
{
// main menu describing the tickets offered
cout<<"1.The Faculty & Staff parking permit allows a car
to park in YELLOW and GREEN slots. User "
<<"can purchase multiple Faculty & Staff parking
permit."<<endl;
cout<<"Price of one permit is 2$"<<endl;
cout<<"2.The Student parking permit allows a car to park in
GREEN slots. User can purchase multiple"<<
"student parking permit."<<endl;
cout<<"Price of one permit is 1$"<<endl;
cout<<"3.The Resident parking permit allows a car to park in
ORANGE and GREEN slots. User can add "<<
"a premium package to this kind of permit that allows one of user's
friend to share this permit, but"<<
"each user can only purchase one Resident parking
permit."<<endl;
cout<<"Price of one permit is 3$ and if you want premium
package it cost will be 5$"<<endl;
cout<<"4.The Visitor parking permit allows a car to park in
ORANGE, YELLOW and GREEN slots."<<
"The permit is only valid for one day and user can only purchase
one Visitor parking permit."
<<endl;
cout<<"Price of permit is 4$"<<endl;
cout<<"Enter your Choice"<<endl;
int n;
cin>>n;
switch(n)
{
case 1: cout<<"how many permit you want to
purchase"<<endl;// selects Faculty&Staff parking
permit
cin>>NumPermits;
TotalPrice+=(NumPermits*2);
TotalPermits+=NumPermits;
break;
case 2: cout<<"how many permit you want to
purchase"<<endl;//selects Student parking permit
cin>>NumPermits;
TotalPrice+=(NumPermits*1);
TotalPermits+=NumPermits;
break;
case 3: cout<<"Want to add permium package to this permint Y
OR N"<<endl;// selects Resident parking permit
char a;
cin>>a;
if(a=='Y')
{
TotalPrice+=5;
}else
{
TotalPrice+=3;
}
TotalPermits+=1;
break;
case 4: cout<<"This is Valid only one day,want to buy Y OR
N"<<endl;//selected visitor parking permit
cin>>a;
if(a=='Y')
{
TotalPrice+=4;
TotalPermits+=1;
}else
{
cout<<"You cancel the Purchase"<<endl;
}
break;
}
cout<<"Want To Continue Y OR N"<<endl;//asking for
continue
cin>>Choice;
}
cout<<"TotalPermits "<<TotalPermits<<"
TotalPrice"<<TotalPrice<<"$";//print the value after
user done
return 0;
}
/*
input :-
paras
138/15
1
3
Y
3
Y
Y
4
Y
N
output:-
Enter Your name and ID
paras
138/15
1.The Faculty & Staff parking permit allows a car to park in
YELLOW and GREEN slots. User can purchase multiple Faculty &
Staff parking permit.
Price of one permit is 2$
2.The Student parking permit allows a car to park in GREEN slots.
User can purchase multiple student parking permit.
Price of one permit is 1$
3.The Resident parking permit allows a car to park in ORANGE and
GREEN slots. User can add a premium package to this kind of permit
that allows one of user's friend to share this permit, but each
user can only purchase one Resident parking permit.
Price of one permit is 3$ and if you want premium package it cost
will be 5$
4.The Visitor parking permit allows a car to park in ORANGE, YELLOW
and GREEN slots.The permit is only valid for one day and user can
only purchase one Visitor parking permit.
Price of permit is 4$
Enter your Choice
how many permit you want to purchase
Want To Continue Y OR N
1.The Faculty & Staff parking permit allows a car to park in
YELLOW and GREEN slots. User can purchase multiple Faculty &
Staff parking permit.
Price of one permit is 2$
2.The Student parking permit allows a car to park in GREEN slots.
User can purchase multiple student parking permit.
Price of one permit is 1$
3.The Resident parking permit allows a car to park in ORANGE and
GREEN slots. User can add a premium package to this kind of permit
that allows one of user's friend to share this permit, but each
user can only purchase one Resident parking permit.
Price of one permit is 3$ and if you want premium package it cost
will be 5$
4.The Visitor parking permit allows a car to park in ORANGE, YELLOW
and GREEN slots.The permit is only valid for one day and user can
only purchase one Visitor parking permit.
Price of permit is 4$
Enter your Choice
Want to add premium package to this permit Y OR N
Want To Continue Y OR N
1.The Faculty & Staff parking permit allows a car to park in
YELLOW and GREEN slots. User can purchase multiple Faculty &
Staff parking permit.
Price of one permit is 2$
2.The Student parking permit allows a car to park in GREEN slots.
User can purchase multiple student parking permit.
Price of one permit is 1$
3.The Resident parking permit allows a car to park in ORANGE and
GREEN slots. User can add a premium package to this kind of permit
that allows one of user's friend to share this permit, but each
user can only purchase one Resident parking permit.
Price of one permit is 3$ and if you want premium package it cost
will be 5$
4.The Visitor parking permit allows a car to park in ORANGE, YELLOW
and GREEN slots.The permit is only valid for one day and user can
only purchase one Visitor parking permit.
Price of permit is 4$
Enter your Choice
This is Valid only one day,want to buy Y OR N
Want To Continue Y OR N
TotalPermits:-5 TotalPrice:-15$'
*/