Module 6 - Lab - Car Lot

 Objective

In this lab assignment, you will create a C++ program that uses parallel arrays to store car names and their respective Miles Per Gallon (MPG) values. You will implement a function called displayCarDetails that takes both arrays as arguments and outputs the car details, including whether it is "Economical" or a "Gas Guzzler" based on its fuel consumption.

Requirements:

  1. Create a C++ program that contains the following functions:
    a. void displayCarDetails(string[], double[], int): This function takes two parallel arrays (cars and mpg) and their size as input. It displays the car details, including car name, MPG, and whether it is "Economical" or a "Gas Guzzler" based on its MPG value.

  2. Pre-populate two parallel arrays with 5 elements each:
    a. cars[]: This string array will hold the names of 5 cars (e.g., "Car A", "Car B", etc.).
    b. mpg[]: This double array will hold the MPG values of the corresponding cars.

  3. Use the displayCarDetails function to output the car details.

  4. The program should calculate whether a car is "Economical" or a "Gas Guzzler" based on the following rule:

    • If the MPG is greater than 30.0, the car is considered "Economical."

    • Otherwise, the car is considered a "Gas Guzzler."

Sample Output:

Welcome to the Car Fuel Efficiency Analyzer! Car MPG Status ----------------------------------- Car A 35.2 Economical Car B 28.6 Gas Guzzler Car C 33.8 Economical Car D 19.7 Gas Guzzler Car E 25.0 Gas Guzzler

Note: In this lab assignment, the program uses pre-populated parallel arrays with car names and their respective MPG values. The displayCarDetails function takes care of determining whether each car is "Economical" or a "Gas Guzzler" based on its MPG value.

Please format the results similar to the above.

Challange (optional): Create a function that returns the Average MPG of all the cars (extra 15 points)

 

Deliverable

Upload the following:

  1. Full source code (.cpp file or .txt file)

  2. Screenshot of the Console with the code executing

COSC-1336 / ITSE-1302 Computer Science - Author: Dr. Kevin Roark