Question

In: Computer Science

Three small airplanes flight a 1000-mile route. Write a program that inputs the airplane make, model,...

Three small airplanes flight a 1000-mile route. Write a program that inputs the airplane make,
model, and the number of gallons of fuel used by each airplane. After calling a calcMPG()
function once for each airplane have main determine and display which airplane is the most
fuel-efficient, and how many miles per gallon it got. The calcMPG() function should be passed
the distance flew and the gallons of gas consumed as arguments and should return the miles
per gallon obtained. Code must be written in C++

Solutions

Expert Solution

Answer: Hey!! Kindly finds your solution below. Let me know if any issue.Thanks.

Copy to Code: This code has function to calculate MPG of an airplane that return MPG of airplane. In main, user input information about all three airplanes and calculate their MPG store into an array, Then compare all MPG's and find max and print info about that airplane that gives best MPG.

#include<iostream>
using namespace std;
double calcMPG(double dis,double gallons)//function calcMPG() takes arguments
{
   double miles;
   miles = dis/gallons;
   return miles;
}
int main()
{
   string make[3],model[3];//arrays and variables
   double miles[3],d = 1000,g,temp;
  
   for(int i=0;i<3;i++)//for loop to take inputs for three airplanes
   {   cout<<"Enter airplane make: ";
       cin>>make[i];//takes input for make
       cout<<"enter airplane model: ";
       cin>>model[i];//takes input for model
       cout<<"Enter gallons of gas used: ";
       cin>>g;//takes input for gallons gas
       miles[i] = calcMPG(d,g);//call function to get MPG
   }
   temp = miles[0];
   int c =1;
   for(int i=1;i<3;i++)//find Fuel-Efficient plane (which MPG is max)
   {
       if(temp<miles[i])
       {
           temp=miles[i];
           c = i;
       }
   }
   cout<<"Fuel-Efficient airplane: ";//print info about Fuel-Efficient plane
   cout<<"\nAirplane Make: "<<make[c];
   cout<<"\nModel: "<<model[c];
   cout<<"\nMPG: "<<temp;
   return 0;
}
      
Screenshot of code and output:


Related Solutions

Write a program Write a program whose inputs are three integers, and whose output is the...
Write a program Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 C++ please
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
Write a program that accepts the lengths of three sides of a triangle as inputs. The...
Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides. Use The triangle is a right triangle. and The triangle is not a right triangle. as your final outputs. An example of the program input...
Write a program whose inputs are three integers, and whose output is the smallest of the...
Write a program whose inputs are three integers, and whose output is the smallest of the three values
Write a program whose inputs are three integers, and whose output is the smallest of the...
Write a program whose inputs are three integers, and whose output is the smallest of the three values. Use else-if selection and comparative operators such as '<=' or '>=' to evaluate the number that is the smallest value. If one or more values are the same and the lowest value your program should be able to report the lowest value correctly. Don't forget to first scanf in the users input. Ex: If the input is: 7 15 3 the output...
Question 3 The Fly-High Airplane Company builds small jet airplanes to sell to corporations for use...
Question 3 The Fly-High Airplane Company builds small jet airplanes to sell to corporations for use by their executives. To meet the needs of these executives, the company's customers sometimes order a custom design of the airplanes being purchased. When this occurs, a substantial start-up cost is incurred to initiate the production of these airplanes. Fly-High has recently received purchase requests from three customers with short deadlines. However, because the company's production facilities already are almost completely tied up filling...
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
in coral write a program whose inputs are three integers, and whose output is the largest...
in coral write a program whose inputs are three integers, and whose output is the largest of the three values. Ex: If the input is 7 15 3, the output is: 15
Write a program that inputs three integers in the range [1..13] that represent a hand of...
Write a program that inputs three integers in the range [1..13] that represent a hand of three cards. Your program should output an English evaluation of the hand. In the output, cards will be described as follows: - 2–10 are described by the words for their numeric values: two, three, etc. - 1 is called an ace, 11 is called a jack, 12 is called a queen, and 13 is called a king. The evaluation of a hand is based...
Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values.
 in Coral Simulator  Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. If the input is 7 15 3, the output is: largest: 15 smallest: 3 Your program should define and call two functions: Function LargestNumber(integer num1, integer num2, integer num3) returns integer largestNum Function SmallestNumber(integer num1, integer num2, integer num3) returns integer smallestNum The function LargestNumber should return the largest number of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT