CSCI 261 - Programming Concepts (C++)

Spring 2017 - Assignment 07 - Calculator

Quick Links: Blackboard | Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This assignment is due by Tuesday, March 14, 2017 11:59pm.


Instructions



One common application for simple programs is to perform conversions or calculations for the user. In this homework assignment, you will write a program that gives the user a few choices for calculations. Specifically, you will write functions to calculate someone's Body Mass Index (BMI), convert from pounds to kilograms, convert from feet to meters, and one additional calculation of your choice.

For each calculation in your program, you should write (at least) two functions. One function should perform the calculation and return the result, and the other function should accept necessary data from the user, call the calculation function, and then display the result. You should also have a menu function which presents the user with the possible choices for calculations (e.g., user can choose BMI calculation or convert from pounds to kilograms).

Why do we divide your program into functions this way? The primary reason for using functions is so that code is more easily identified and reused. This division ensures that your calculation is universal and can be reused elsewhere.


Get Started



To begin, create an empty project. For the main() , copy/paste the following into your homework project.
int main() {
// DO NOT change this main function

     menu();

     return 0;

} // end of Main Function
Note that the main function calls a menu function, which you need to write. Note also that you are not allowed to change the main function. Thus, your menu function will need to call another function which is associated with the calculation chosen by the user. Fortunately, calling a function from another function works the same way as calling a function from main (as main is also a function).

You should place your function definitions below your main() . To do that, think about what you need to add above your main() to give your functions global scope that can be called from everywhere. (We will discuss function prototypes on Friday.)


The Functions



Your program must have the following functions that perform the described tasks:
  • menu, which has no parameters and no return value. This function displays the list of available calculations to the user, and then accepts a choice from the user. For practice, use a switch statement to decide which function gets called.
  • poundsToKilograms, which has no parameters and no return value. This function asks the user to input the number of pounds to convert, calls doPoundsToKilograms to do the calculation, and then outputs the result returned.
  • doPoundsToKilograms, which has one double parameter (pounds) and returns a double (kilograms). This function does the pounds to kilogram conversion, and then returns the results. Note: 1 pound is about 0.454 kilograms.
  • feetToMeters, which has no parameters and no return value. This function asks the user to input the number of feet to convert, calls doFeetToMeters to do the calculation, and then outputs the result returned.
  • doFeetToMeters, which has one double parameter (feet) and returns a double (meters). This function does the feet to meter conversion, and then returns the results. Note: 1 foot is about 0.3048 meters.
  • bodyMassIndex, which has no parameters and no return value. This function asks the user to input height (in feet) and weight (in pounds). Then, this function calls doPoundsToKilograms and doFeetToMeters to do conversions, and then calls doBMI to do the calculation. Finally, this function outputs the result returned.
  • doBMI, which has two double parameters (kilograms and meters) and returns a double (BMI). This function calculates the BMI, and then returns the results. Note: BMI is calculated as (weight (kg)) / (height (m) * height (m)).
  • Add (at least) two more functions to your program that calculates something you think would be useful for your calculator (i.e., (1) an input function with no parameters and no return value and (2) a calculation function with at least one parameter used in the calculation). Make this function accessible from your menu function and test it completely.


Grading Rubric


Your submission will be graded according to the following rubric.

Points Requirement Description
6 Labs completed
13 Assignment meets functional requirements outlined above
4 (1) Comments used (2) Coding style followed (3) Appropriate variable names, constants, and data types used (4) Instructions followed (5) Assignment compiles


Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.

In summary, for homework due on Tuesday, March 14 follow these specific steps:
  • create a directory called week07.
  • within week07, create four subdirectories: Lab07A, Lab07B, Lab07C, and A07.
  • within your new week07/Lab07A directory, copy in your main.cpp file from your Lab07A solution.
  • within your new week07/Lab07B directory, copy in your main.cpp file from your Lab07B solution.
  • within your new week07/Lab07C directory, copy in your main.cpp file from your Lab07C solution.
  • within your new week07/A07 directory, copy in your main.cpp file from your A07 solution.
  • compress the week07 directory (see Step 3 here for details).
  • submit the week07.zip file to Blackboard (see Steps 5-10 here for details).
  • after you submit, download the file and double check it contains all that you think it contains!

This assignment is due by Tuesday, March 14, 2017 11:59pm.
Last Updated: 01/01/70 00:00


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0