Objectives

This assessment item relates to the course learning outcomes numbers l, 2, 4, 6, 7 and 8 as stated on page 1. It is designed to test your understanding of arrays, functions, sorting and searching.

Assignment specification

Write a C++ program to read, randomly generate, store, sort, search and display the fuel consumption rates (litres/100 kilometres) ofN cars (e.g. 4.9, 7.2, 8.9, 15.0, 23.5, etc.). The minimum and maximum fuel consumption rates are 4.5 and 25.5 respectively. N should be declared as a constant in your program and it should be equal to the largest digit of your student id number. Assume N13, if the largest digit of your student id number is less than 3. You must use a single dimension array to store fuel consumption rates. Your program should display and execute a menu with the following options. A switch statement must be used to execute the following menu options.

  • Read fuel consumption rates for N cars and store them in the array.
  • Randomly generate fuel consumption rates for N cars and store them in the array.
  • Calculate and display the average fuel consumption rate for N cars.
  • Find and display the index for car with best (lowest) fuel consumption rate.
  • Find and display fuel consumption rates in reverse order.
  • Sort and display fuel consumption rates stored between index 0 and N/2 in descending order.
  • Search and display fuel consumption rate which is less than a given fuel consumption rate.
  • Exit

Task

  • Read fuel consumption rates for N cars and store them in the array This option reads fuel consumption rates for N cars from the keyboard and stores them i.n the array. The fuel consumption rates must be greater than or equal to 4.5 and less than or equal to 25.5.
  • Randomly generate fuel consumption rates for N cars and store them in the array This option generates fuel consumption rates for N cars using rand() function and stores them in the array. The randomly generated fuel consumption rates must be greater than or equal to 4.5 and less than or equal to 25.5.
  • Calculate and display the average fuel consumption rate for N cars This option calculates and displays the average fuel consumption rate for N cars.
  • Find and display the index for car with best (lowest) fuel consumption rate This option calculates and displays the index for car with best (lowest) fuel consumption rate. If there is more than one best (lowest) fuel consumption rate then displays index for all.
  • Find and display fuel consumption rates in reverse order This option finds and displays fuel consumption rates in reverse order. The reverse order means that first fuel consumption rate entered from the keyboard/randomly generated is displayed last and last fuel consumption rate entered from the keyboard/randomly generated is displayed first.
  • Sort and display fuel consumption rates stored between index O and N/2 in descending order This option sorts and displays fuel consumption rates stored between index 0 and N/2 in the array in descending order. If N is 5, array locations between O and 2 (including 0 and 2) should be sorted in descending order. You can use any sorting algorithm which uses at least two for loops and one if statement.
  • Search and display fuel consumption rate which is less than a given fuel consumption rate This option searches and displays all stored fuel consumption rates which are less than the given fuel consumption rate. The program asks the user to enter the given fuel consumption rate using the keyboard and searches for it. If the fuel consumption rate less than the fuel consumption rate entered from the keyboard is found then the program displays fuel consumption rate/rates otherwise it displays an appropriate message.
  • Exit

The progam should display the message “Thanks for using the program”, your id number and exit. The whole program should work in a loop to enable the user to read fuel consumption rates, randomly generate fuel consumption rates. calculate and display the average fuel consumption rate, find and display the index for car with best fuel consumption rate, find and display fuel consumption rates in reverse order, sort and display fuel consumption rates stored between index 0 and N/2 in descending order, search and display fuel consumption rate which is less than a given fuel consumption rate and exit.

Program Design

You may use any design that meets the specification. However, a good design will adhere to the following guidelines:

  • be logically correct
  • be easy to read and maintain
  • be well—structured
  • use functions and parameter passing

Design suggestions

A well-structured program might contain functions to perform the following main tasks:

  • Welcome message and menu display
  • Read fuel consumption rates for N cars and store them in the array
  • Randomly generate fuel consumption rates for N cars and store them in the array
  • Calculate and display the average fuel consumption rate for N cars
  • Find and display the index for car with best (lowest) fuel consumption rate
  • Find and display fuel consumption rates in reverse order
  • Sort and display fuel consumption rates stored between index 0 and N/2 in descending order
  • Search and display fuel consumption rate which is less than a given fuel consumption rate
  • Exit

Testing

Testing is important. You should:

  • list the different types of test cases
  • list the sample data used for each test case
  • display the results of using the sample data in each test case.

The program should contain main function and user defined functions. Arrays can be used in this assignment. You should not use things which are not pan of this course. You will be penalised 25% of the total marks for the assignment, if you use things (eg. classes, linked list, etc.) which are not covered in this course.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.