For this assignment, you are required to design, implement and test a program for the program specification provided below; you are to use the top-down approach for software development. This assignment is your opportunity to demonstrate that you understand the basics of:
The implementation of your program, using C++, should conform to the following constraints; it should:
NOTE: Code that has compilation errors when compiled will be marked but you cannot expect to achieve a pass mark the best mark you could possibly achieve is 7/20. If you are unable to get your code to compile please see your tutor/lecturer or comment out the offending code prior to handing in your work. If your code compiles with warnings marks will be deducted.
The body mass index (BMI), or Quetelet index, is a statistical measure of the weight of a person scaled according to height. The body mass index (BMI), or Quetelet index, is a statistical measure of the weight of a person scaled according to height. (Wikipedia, 2008)
Your task is to write a small program to assist with calculating the BMI. The BMI is calculated using the following equation: see image. where weight is measured in kg and the height in metres. The BMI is split into the following subdivisions: see image
Your program is going to be used to store the height and weight 5 volunteers (using an array) and then calculate the BMI of each of these volunteers. The program has been broken down into a number of tasks to assist you with your development. You should write your code so that if the number of volunteers changes in the future the changes to the code will be kept to a minimum.
For each of the tasks provided you should provide basic design information such as any data validation, calculations that need to be performed and a first level algorithm.
Design and implement a function that takes as its arguments two values representing the height in metres and their weight in kilograms and returns the BMI.
Design and implement a function that fills a 2 dimensional array (which has been passed as an argument) capable of storing the height and weight of 5 volunteers. The function should read in the data from a file. The program should stop reading the file when it reaches the limit of the array.
Challenge Task: The program would be more flexible using dynamic memory for the array. Write a function that will count and return the number of records in the file. Then declare an array (using the 'new' operator) which will create enough space for all of the records. Don't forget to use 'delete' to remove the space once you've finished with it. Only attempt this task when you are satisfied the rest of the program is working correctly (and make sure you take a backup first).
Design and implement a function that displays the contents of the data in the array (passed as an argument) and calculates the BMI of each of the volunteers. Your data is to be displayed appropriately in a table with the weight and height being displayed to two decimal places and BMI to one decimal place. For example: see image
The output should also be sent to a file (called 'records.txt').
Write a function that sorts the data in the array according to its bmi value.
First create a copy of the array. This copy (call it sortedBMIArray) should contain MISSING SOMETHING HERE??
Selection sort (think back to programming 1) should be used to do this. You will need a function to swap two records in the array both values (height and weight) should be swapped. The swap function should have two int parameters (for the elements to be swapped). The array 'sortedBMIArray' should also be passed in to the function.
The bmi values should not be stored in the array. They should be calculated (using the function from task 1) as they are needed.
Use the function from task 3 to display the data from the sortedBMIArray
Once you have each of the above tasks design and implement a menu system that can be used to test your code, such as:
This menu, should be used so that it can be used to test all of the tasks completed above. The menu should be put inside a while loop which will continue to run until the user selects the 'Exit' option.