please dont use arrays, basic as possible. Programming Fundamentals for Computer
ID: 3598064 • Letter: P
Question
please dont use arrays, basic as possible.
Programming Fundamentals for Computer Science Obicctives: to learn to code, compile and run a program containing repetition structures. Program Planning Due: Program Listing and Output Due: Assignment: Plan and code a program utilizing one or more repetition structures to solve the following problem: Write a program for Pentagon Parking Lot for all customers that use the lot during the day. The lot opens at 6:00 AM and closes at 10:00 PM. Charges for vehicles are based upon the following rates: Cars: First 2 hours Next 3 hours Next 48 hours Free $1.00 per hour S 50 per hour Tnucks: First hour Next 2 hours Next 2 hours Free $2.00 per hour $1.00 per hour Senior Citizens: No Charge Have the user enter a character designation for rate of charge (C, T, S), the starting time and ending time (in military time) for parking lot use. Determine the total number of hours. (Any part of an hour is to be counted as a full hour.) Compute the appropriate charge and print out a ticket for each customer. Be sure to check for invalid data and handle it appropriately. Print out the total fees for each type of rate charged during the entire day. InDU Rate designation (C, T, S), starting time, ending time, Itemized listing of charges for each vehicle, and an itemized summary of all charges for the day. hutput Note: Adequately check entered data for validity. Use adequate test data to process all valid data and any possible combination of invalid data. Label all output clearly. Be sure your output file contains user prompts and what was entered by the user in addition to the results of your program processing. BE SURE TO INCLUDE ADEQUATE ERROR HANDLING IN YOUR PROGRAM AND ERROR DATA WHEN YOU RUN THE PROGRAM TO DEMONSTRATE ERROR HANDLING.Explanation / Answer
//Program in C++. Comments are included wherever necessary.
#include <iostream>
using namespace std;
int main()
{
cout<<"Welcome!! ";
bool flag=true;
while(flag)
{
cout<<"Please enter Rate Designation: (C/T/S) or Press 'Q' to quit ";
char rd;
cin>>rd;
if(rd=='Q')
{
flag=false;
continue;
}
if(rd!='C' && rd!='T' && rd!='S')
{
cout<<"Invalid Input, Try again ";
continue;
}
cout<<"Please enter starting time: ";
int start;
cin>>start;
//checking validity of hours
int temp;
temp=start;
if(temp<600 || temp>2200)
{
cout<<"Invalid input. Parking Lot timings are between 0600 and 2200, Try again ";
continue;
}
//checking validity of minutes
temp=start%100;
if(temp<0 || temp>59)
{
cout<<"Invalid input. Parking Lot timings are between 0600 and 2200, Try again ";
continue;
}
cout<<"Please enter ending time: ";
int end;
cin>>end;
//checking validity of hours
temp=end;
if(temp<0600 || temp>2200)
{
cout<<"Invalid input. Parking Lot timings are between 0600 and 2200, Try again ";
continue;
}
//checking validity of minutes
temp=end%100;
if(temp<0 || temp>59)
{
cout<<"Invalid input. Parking Lot timings are between 0600 and 2200, Try again ";
continue;
}
if(start>end)
{
cout<<"Invalid input. Try again ";
continue;
}
//Total ticket hours
int hrs;
if(end%100==0)
{
hrs=(end/100)-(start/100);
}
else
{
hrs=(end/100)-(start/100)+1;
}
//Calculating ticket amount
//For senior citizens
if(rd=='S')
{
cout<<"Category: Senior Citizen ";
cout<<"Total hours: "<<hrs<<endl;
cout<<"Ticket amount: $0"<<endl;
}
//For Cars
if(rd=='C')
{
cout<<"Category: Cars ";
cout<<"Total hours: "<<hrs<<endl;
int a,b;
float amount=0;
if(hrs>=2)
{
hrs=hrs-2;
if(hrs>=3)
{
hrs=hrs-3;
amount=amount+3;
if(hrs>0)
{
amount=amount+0.5*hrs;
}
}
else
{
amount=amount+hrs*1;
}
}
cout<<"Ticket amount: $"<<amount<<endl;
}
//For Trucks
if(rd=='T')
{
cout<<"Category: Trucks ";
cout<<"Total hours: "<<hrs<<endl;
int a,b;
float amount=0;
if(hrs>=1)
{
hrs=hrs-1;
if(hrs>=2)
{
hrs=hrs-2;
amount=amount+4;
if(hrs>0)
{
amount=amount+hrs;
}
}
else
{
amount=amount+hrs*2;
}
}
cout<<"Ticket amount: $"<<amount<<endl;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.