online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <vector> using namespace std; int main() { vector<double> distance = {617, 2079, 3929, 7833, 8276}; //Q1 Destination distance (miles) double speed = 590; //Q1 Boeing 777 Speed (mph) double fuel_consumption = 5; //Q1 Gallons of fuel per mile (gallons per mile) double density = 6;//Q1 Density: pounds of fuel per gallon (pounds per gallon) double capacity = 420;//Q1 Capacity of Boeing 777 (people) vector<double> load_factor = {30, 65, 60, 55, 40};//Q1 Load factors of destinations (%) double avg_passenger_weight = 137; //Q1 Average passenger weight (pounds) double cargo_weight = 44400;//Q1 Cargo weight (pounds) double empty_weight = 353600;//Q1 Boeing 777 empty weight (pounds) double fuel_cost_per_gallon = 1; //Q1 Cost of fuel per gallon ($ per gallon) vector<double> landing_fee = {0.012, 0.006, 0.010, 0.010, 0.004}; //Q1 Landing fee of destinations ($ per pound of total original weight before takeoff) double staff = 25; //Q1 Number of staff per flight (People per flight) double wage = 35; //Q1 Hourly wage for each staff ($ per hour) vector<double> ticket_price = {180, 250, 540, 1130, 1200}; //Q1 Ticket price for destinations ($) vector<double> flight_time(5); //Q2 Initialize vector to store flight times (hours) for each destination vector<double> passengers(5);//Q3 Initialize vector to store numbers of passengers for each destination vector<double> passenger_weight(5);//Q4 Initialize vector to store passenger weights (pounds) for each destination vector<double> gallons_fuel(5);//Q5 Initialize vector to store gallons of fuel used for each destination vector<double> fuel_weight(5);//Q6 Initialize vector to store pounds of fuel used for each destination vector<double> total_weight(5);//Q7 Initialize vector to store total weight before takeoff (pounds) for each destination vector<double> fuel_cost(5);//Q8 Initialize vector to store total fuel cost ($) for each destination vector<double> wage_cost(5);//Q9 Initialize vector to store total wage cost ($) for each destination vector<double> landing_cost(5);//Q10 Initialize vector to store total landing cost ($) for each destination vector<double> other_cost(5);//Q11 Initialize vector to store total other costs ($) for each destination vector<double> total_cost(5);//Q12 Initialize vector to store total cost ($) for each destination vector<double> revenue(5);//Q13 Initialize vector to store ticket revenue ($) for each destination vector<double> net_profit(5);//Q14 Initialize vector to store net profit for each destination vector<double> NPPP(5);//Q15 Initialize vector to store net profit per passenger for each destination vector<double> NPPH(5);//Q15 Initialize vector to store net profit per hour for each destination //Run for loop to loop through all the destinations. //Inside the for loop, calculate all the quantities that we need (in Q2 to 15) for(int i = 0; i<=4; ++i){ flight_time[i] = distance[i] / speed; //Q2 Flight time = flight distance / speed of aircraft passengers[i] = capacity * (load_factor[i] / 100); //Q3 Multiply load factor by capacity to find passenger numbers //Note that dividing by 100 is to change from percent to decimal passenger_weight[i] = passengers[i] * avg_passenger_weight;//Q4 Total Passenger weight is no. of passengers * average passenger weight gallons_fuel[i] = distance[i] * fuel_consumption;//Q5 gallons of fuel used is distance * gallons of fuel per mile fuel_weight[i] = gallons_fuel[i] * density;//Q6 total weight of fuel needed is gallons of fuel * density of fuel (density is pounds per gallon) total_weight[i] = empty_weight + fuel_weight[i] + passenger_weight[i] + cargo_weight; //Q7 Sum all the weight contributions to get total weight fuel_cost[i] = gallons_fuel[i] * fuel_cost_per_gallon;//Q8 Cost of fuel = gallons of fuel * price per gallon of fuel wage_cost[i] = flight_time[i] * staff * wage;//Q9 Wage cost = No. of Staff * Wage per hour for each staff * Hours of Flight landing_cost[i] = landing_fee[i] * total_weight[i];//Q10 Landing cost = landing fee * total weight //Note that this is because landing fee is in $ per pound of total weight before takeoff, which is the "total weight" we found earlier other_cost[i] = distance[i] * 25; //Q11 Other costs is distance to destination * 25 total_cost[i] = fuel_cost[i] + wage_cost[i] + landing_cost[i] + other_cost[i]; // Q12 Add all costs to get total cost revenue[i] = ticket_price[i] * passengers[i];//Q13 Total revenue (income) is how many passengers * ticket price net_profit[i] = 0.8 * (revenue[i] - total_cost[i]);//Q14 Profit is revenue minus cost. Multiply by 0.8 to find net profit after tax (tax is 20%) NPPP[i] = net_profit[i] / passengers[i];//Q15 NPPP = Net Profit / No. of Passengers NPPH[i] = net_profit[i] / flight_time[i];//Q15 NPPH = Net Profit / No. of Hours flown } //REPORT (Q16) cout<<"This is a report on Wolverine Airline's potential Boeing 777 destinations."<<endl<<endl; cout<<"Destination 0: New York, Destination 1: San Francisco, Destination 2: Paris, Destination 3: Hong Kong, Destination 4: Cape Town."<<endl<<endl; //Run for loop to loop through all the destinations. //Inside for loop, print report for each destination. for (int i =0; i<=4; ++i){ cout<< "Results for Destination "<<i<<":"<<endl; cout<< "Flight distance (miles): "<<distance[i]<<endl; cout<< "Flight time (hours): "<<flight_time[i]<<endl; cout<< "Number of passengers: "<<passengers[i]<<endl; cout<< "Net profit per passenger ($ per passenger): "<<NPPP[i]<<endl; cout<< "Net profit per hour ($ per hour): "<<NPPH[i]<<endl; //If net profit for destination is > $0, say it is profitable. Otherwise, say it isn't. if(net_profit[i] > 0){ cout<<"Destination "<< i << " is profitable"<<endl<<endl; }else{ cout<<"Destination "<< i << " is not profitable"<<endl<<endl; } } //Q17: ALCULATING HIGHEST NPPP AND NPPH int highest_NPPP = 0; //Initialize int to store destination number of highest NPPP destination int highest_NPPH = 0;//Initialize int to store destination number of highest NPPH destination // For loop to loop through all destinations and compare NPPP and NPPH with the "highest" ones. If NPPP // or NPPH is larger, change the "highest" value to the destination with the higher value. // Notice it starts from 1, not 0 because we don't have to compare 0 with 0, the original "highest" value. for(int i = 1; i<=4; ++i){ //Loop through the 4 other destinations if(NPPP[i]>NPPP[highest_NPPP]){ //If NPPP of i'th destination is higher than destination with highest_NPPP so far, highest_NPPP = i; //set new highest NPPP destination to i'th destination } if(NPPH[i]>NPPH[highest_NPPH]){ highest_NPPH = i; } } //Q18, 19 REPORTING HIGHEST NPPP AND NPPH cout<<"The destination with the highest net profit per passenger (NPPP) is Destination: "<<highest_NPPP<<endl; cout<<"The destination with the highest net profit per hour (NPPH) is Destination: "<<highest_NPPH<<endl; return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue