Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c++ Problem description You have a database of flights in a following format. From To Seat type Price ($) Austin Houston E 109 Austin
in c++
Problem description You have a database of flights in a following format. From To Seat type Price ($) Austin Houston E 109 Austin New York B 352 Washington D.C. Seattle PE 139 Austin New York E 94 Dallas Austin 1st 93 Washington D.C. Seattle E 110 Chicago Las Vegas B 149 Austin New York 1st 210 Where From column contains a city of departure and To col- umn contains a city of arrival. Seat type contains a seat type (E- economy, PE-premium economy, 1st-first class, B-business), Price column has a ticket price in dollars and Distance column contains a straight line distance between two cities. The database is stored in a file with the newline as a column sep- arator and double newline as a row separator (see the attached file tickets.txt file). You have to write the program that can answer user queries about tickets. Your program should be able to (1) display all tickets in a readable format, (2) show tickets for a given departure and destination cities, (3) find the cheapest ticket Note: you can assume that your input file has no more than 100 flights stored, so you can create an array of flights with 100 elements in it and then use only as many as you read from the file. Implementation The program should run in a while loop. Each iteration the program should ask to enter the menu option (1-4). Depending on the menu option the program should do the following: 1. Show all the tickets in a database in a human readable format. 2. Ask for a departure and destination cities and show all tickets with these departure and destination cities. 3. Print the cheapest ticket 4. Exit the program. The program should contain at least 4 functions (excluding main). 1. readTickets. Given the file input stream, and empty array of flights, read the ticket file and return a size of an array. 2. printTickets. Given the array of tickets and its size it prints those tickets in a human readable format. 3. pringTicketsFromTo. Given the array of tickets, its size and a city name it prints flights from the given city. 4. "findCheapest Ticket. Given the array of tickets, its size and flightIndex integer passed by reference it finds the highest dis- tance to price ratio, puts the index of the respective flight into "flightIndex variable and returns the price. IMPORTANT: It should not print anything. Execution The following is an example of the program execution. User input is in red. : Select the action: 1) Display all flights 2) Show the flights that depart from a given city 3) Find a flight with the best distance to price ratio 4) Exit the program 1 From Seat type Price Austin Houston E 109.99 Austin New York B 352.00 Washington D.C. Seattle PE 139.20 Austin New York E 94.00 Dallas Austin 1st 93.50 Washington D.C. Seattle E 110.00 Chicago Las Vegas B 149.00 Austin New York 1st 210.00 Select the action: 1) Display all flights 2) Show the flights that depart from a given city 3) Find a flight with the best distance to price ratio 4) Exit the program 2. Enter departure city: Austin Enter arrival city: New York From Seat type Price Austin New York B 352.00 Austin New York E 94.00 Austin New York 1st 210.00 Select the action: 1) Display all flights 2) Show the flights that depart from a given city 3) Find a flight with the best distance to price ratio 4) Exit the program 3 The cheapest ticket costs $93.50 From Seat type Price Dallas Austin 1st 93.50 Select the action: 1) Display all flights 2) Show the flights that depart from a given city 3) Find a flight with the best distance to price ratio 4) Exit the program 4 Exiting the program Additional requirements Your program must compile and run, otherwise you will receive a score of 0. Your program must give correct results for any valid input data. If more than one flight has the highest ratio, your program should output one of these flights. Please do not use any features of C++ that we have not yet covered in class. Do not use classes! Style: See the Style Guidelines document on the course cite on Canvas. Especially pay attention to the comments required for the top of the file and for each function. The grader will (poten- tially) deduct points if your program violates the style guidelines. Austin Houston E 109.99 Austin New York B 352 Washington D.C. Seattle PE 139.2 Austin New York E 94 Dallas Austin 1st 93.5 Washington D.C. Seattle E 110 Chicago Las Vegas B 149 Austin New York 1st 210 Problem description You have a database of flights in a following format. From To Seat type Price ($) Austin Houston E 109 Austin New York B 352 Washington D.C. Seattle PE 139 Austin New York E 94 Dallas Austin 1st 93 Washington D.C. Seattle E 110 Chicago Las Vegas B 149 Austin New York 1st 210 Where From column contains a city of departure and To col- umn contains a city of arrival. Seat type contains a seat type (E- economy, PE-premium economy, 1st-first class, B-business), Price column has a ticket price in dollars and Distance column contains a straight line distance between two cities. The database is stored in a file with the newline as a column sep- arator and double newline as a row separator (see the attached file tickets.txt file). You have to write the program that can answer user queries about tickets. Your program should be able to (1) display all tickets in a readable format, (2) show tickets for a given departure and destination cities, (3) find the cheapest ticket Note: you can assume that your input file has no more than 100 flights stored, so you can create an array of flights with 100 elements in it and then use only as many as you read from the file. Implementation The program should run in a while loop. Each iteration the program should ask to enter the menu option (1-4). Depending on the menu option the program should do the following: 1. Show all the tickets in a database in a human readable format. 2. Ask for a departure and destination cities and show all tickets with these departure and destination cities. 3. Print the cheapest ticket 4. Exit the program. The program should contain at least 4 functions (excluding main). 1. readTickets. Given the file input stream, and empty array of flights, read the ticket file and return a size of an array. 2. printTickets. Given the array of tickets and its size it prints those tickets in a human readable format. 3. pringTicketsFromTo. Given the array of tickets, its size and a city name it prints flights from the given city. 4. "findCheapest Ticket. Given the array of tickets, its size and flightIndex integer passed by reference it finds the highest dis- tance to price ratio, puts the index of the respective flight into "flightIndex variable and returns the price. IMPORTANT: It should not print anything. Execution The following is an example of the program execution. User input is in red. : Select the action: 1) Display all flights 2) Show the flights that depart from a given city 3) Find a flight with the best distance to price ratio 4) Exit the program 1 From Seat type Price Austin Houston E 109.99 Austin New York B 352.00 Washington D.C. Seattle PE 139.20 Austin New York E 94.00 Dallas Austin 1st 93.50 Washington D.C. Seattle E 110.00 Chicago Las Vegas B 149.00 Austin New York 1st 210.00 Select the action: 1) Display all flights 2) Show the flights that depart from a given city 3) Find a flight with the best distance to price ratio 4) Exit the program 2. Enter departure city: Austin Enter arrival city: New York From Seat type Price Austin New York B 352.00 Austin New York E 94.00 Austin New York 1st 210.00 Select the action: 1) Display all flights 2) Show the flights that depart from a given city 3) Find a flight with the best distance to price ratio 4) Exit the program 3 The cheapest ticket costs $93.50 From Seat type Price Dallas Austin 1st 93.50 Select the action: 1) Display all flights 2) Show the flights that depart from a given city 3) Find a flight with the best distance to price ratio 4) Exit the program 4 Exiting the program Additional requirements Your program must compile and run, otherwise you will receive a score of 0. Your program must give correct results for any valid input data. If more than one flight has the highest ratio, your program should output one of these flights. Please do not use any features of C++ that we have not yet covered in class. Do not use classes! Style: See the Style Guidelines document on the course cite on Canvas. Especially pay attention to the comments required for the top of the file and for each function. The grader will (poten- tially) deduct points if your program violates the style guidelines. Austin Houston E 109.99 Austin New York B 352 Washington D.C. Seattle PE 139.2 Austin New York E 94 Dallas Austin 1st 93.5 Washington D.C. Seattle E 110 Chicago Las Vegas B 149 Austin New York 1st 210Step 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