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:

  • Program design
  • Program implementation
  • Debugging
  • Documentation
  • Testing

The implementation of your program, using C++, should conform to the following constraints; it should:

  • include at least one working and appropriate example of :
    • a two-dimensional array
    • a switch statement
    • an if statement
    • a while loop
    • a for loop
    • pointers
  • basic data validation for example invalid heights, weights and menu selections
  • make appropriate use of functions all of your code should not be included in the main function
  • a header file containing prototypes for functions, const definitions and other #include options.
  • be completed using appropriate coding standards
  • successfully compile using Visual Studio 2008 without errors or warnings. If you develop your code on another system please allow enough time to transfer the file and test that it runs successfully as this is the development environment on which your assignment will be marked..

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.

Program Specification:

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.

Task One:

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.

Task Two:

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).

Task Three:

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').

Task Four:

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

Task Five:

Once you have each of the above tasks design and implement a menu system that can be used to test your code, such as:

  • Calculate a single BMI
  • Enter data
  • Display data
  • Sort array and display
  • Exit

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.

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.