Question
C++ This exercises our introduction to conditional statements. We will write a small program for Fordham Airlines to allow the customer to purchase flights, calculating
C++
This exercises our introduction to conditional statements.
We will write a small program for Fordham Airlines to allow the customer to purchase flights, calculating how much the customer owes, taking payment, and calculating change.
The airline sells tickets for travel during two time periods: daytime (departing 5am-7pm, inclusive) and nighttime (departing after 7pm up and before 5am).
The airline sells tickets for three destinations: Chicago, Miami, and Portland.
The airline sells tickets for two types of days: weekday and weekend (you could use 'D' for weekday and 'E' for weekend).
Pricing information:
For Miami travel, flight prices are as follows:
For weekday travel: $150 during the daytime, $100 during the nighttime
For weekend travel: $180 during the daytime, $120 during the nighttime
Chicago flights cost half the price of Miami flights, and Portland flights cost twice as much as Miami flights. For example, a Portland weekday flight during the nighttime is $200. A Chicago weekend flight during the daytime is $90.
This is the cost per ticket for each type of travel:
Your program is to work as follows:
1. Display a welcome message (e.g., Welcome to Fordham Airlines!)
2. Prompt the user to input his/her destination: Chicago, Miami, or Portland (I recommend you use letters to represent each input)
3. Prompt the user to input what time s/he wishes to travel (in army time, e.g., 800 for 8am or 1530 for 3:30pm)
4. Prompt the user to input what type of day (s) s/he is traveling: Weekday or Weekend (I recommend you use letters to represent each input)
5. Report the price per ticket of the specified type
6. Prompt the user for the number of tickets to be purchased
If the number of tickets is fewer than 0, report that the number of tickets ordered is invalid and the order has been cancelled, then exit; otherwise:
7. Compute and display the total amount due (no sales tax this time!)
8. Prompt the user to enter the amount s/he is paying
If the amount paid is less than the amount due, report that the amount paid is too little and the order has been cancelled, then exit; otherwise:
9. Display change and confirm the order has been placed
Suggestions:
Variables will hold values given by the user or values computed by you:
What are the types you should use for each of these?
Define destination as _________
Define ticketPrice as _________
Define flightTime as ____________
Define isWeekend as _________
Define isDayflight as _________
Define weekEndOrWeekDayLetter as _______
Define numTickets as __________
Define totalCost as __________
Define userPayment as ________
Define change as __________
After you print:
Welcome to Fordham Airlines!
What is your destination? ([C]hicago, [M]iami, [P]ortland)
You will read in destination //The user should enter either C, M or P.
After you print:
What time will you travel?
You will read in flightTime
Based on the value of flightTime, you can then set isDayflight as either true or false
You need to use the if statement with a Boolean expression.
Ask yourself: When is isDayflight true? When is isDayflight false?
Example assignment of a boolean:
isDayflight = true;
After you print:
What type of day are you traveling? (week[E]nd or week[D]ay)
You will read in weekEndOrWeekDayLetter // either E or D
Based on the value of weekEndOrWeekDayLetter, you can then set isWeekend as either true or false
Now, you can use a series of if statements to capture the different possibilities:
Example:
if(destination == P) && isDayflight && isWeekend) // variables are in bold
ticketPrice = 360;
else if ()
When you are printing float values of money, you can add these lines before you print money values:
cout.setf(ios::fixed);
cout.setf(ios::showpoint); // show decimals
// even if not needed
cout.precision(2); // 2 values to the right of the decimal
You should then be able to print:
Each ticket will cost: $ and your calculated ticketPrice
Print:
How many tickets do you want?
Read the number requested into numTickets and then calculate totalCost.
Print:
Amount paid?
Read in userPayment.
If it is not enough, write: That is too little! No tickets ordered. (No endline)
Otherwise calculate and report change.
SEE EXAMPLES on the next pages
Your code should work identically to the cases below. Please run each of these to check your code, in the order given. (You can try more later).
USE THESE WORDS. DO NOT BE CREATIVE. Creativity is saved for your programming.
Example execution: Portland, weekend, Nightflight
> ./fordhamAir.out
Welcome to Fordham Airlines!
What is your destination? ([C]hicago, [M]iami, [P]ortland) P
What time will you travel? (Enter time between 0-2359) 450
What type of day are you traveling? (week[E]nd or week[D]ay) E
Each ticket will cost: $240.00
How many tickets do you want? 2
You owe: $480.00
Amount paid? 100.00
That is too little! No tickets ordered.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started