It would be helpful to post the input file or at least a goo sample if it so everyone knows what we are working with.
Have you done anything with how to store the information once read in?
Do you have any code yet or is it you just do not know what to do?
The instructions are bit sparse is this all of them?
I would start with the code to open the file and then read the file. You will need to figure out what you will be storing the information in a class or a struct? After that will you want an array or vector to store everything?
These are questions to work out before you get started. It may also help to put this down on paper first to get an idea of what you need.
Last point do this in small steps, get them working before you move on to the next step.
#include <iostream>
#include <fstream>
int main () {
constunsignedint NROUTES = 3 ; // The company has 3 routes
// there is no route 0, route_names[0] is not used
constchar* const route_names[NROUTES+1] = { "", "Panama- Bogota", "Panama- Miami", "Panama- Cancun" } ;
constunsignedint NSEATS = 100 ; // planes with a capacity of 100 passengers each.
// cancel a flight when the number of reserved tickets is less than 20%
constunsignedint MIN_RES_TICKETS = NSEATS * 20 / 100 ;
std::ifstream file( "reservations.txt" ) ; // open the file for input
// The file contains the route, number of reserved passages.
// read them in one by one and update the count of reserved seats
unsignedint num_seats_reserved[NSEATS+1] = {0} ; // num_seats_reserved[0] is ignored
unsignedint route_num ;
unsignedint cnt_res_seats ;
while( file >> route_num >> cnt_res_seats ) {
if( route_num <= NROUTES ) // valid route number
num_seats_reserved[route_num] += cnt_res_seats ;
}
for( unsignedint rt = 1 ; rt <= NROUTES ; ++rt ) { // for each route
std::cout << "route #" << rt << ". " << route_names[rt]
<< " reserved seats: " << num_seats_reserved[rt] << '\n' ;
if( num_seats_reserved[rt] >= MIN_RES_TICKETS ) { // the flight is not cancelled
// ... (TO DO)
}
else { // this flight is cancelled
// ... (TO DO)
}
}
// print totals (TO DO)
}