CSCI 261 - Programming Concepts

Spring 2019 - A4 - Calculator

Quick Links: Canvas | Mines | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |

This assignment is due by Thursday, February 21, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L4A, L4B, L4C, L4D .

· Instructions · Rubric · Submission ·



Concepts



This assignment exercises your ability to define functions and make function calls.


Calculator Functions



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 must place your function prototypes and function definitions in separate files.


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. Be sure to add a Quit option so the user can end the program gracefully.
  • 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.


The Functions



Your program must have the following functions that perform the described tasks:

  • The function prototypes must be placed in a separate header file. The function definitions must be placed in a separate implementation file.
  • The main() function cannot be changed.
  • User input must be validated to prevent future errors (such as a menu item that does not exist, negative heights/weights, etc.).

Grading Rubric


Your submission will be graded according to the following rubric.

PointsRequirement Description
2 All code submitted properly.
8 All labs completed and submitted
L4A, L4B, L4C, L4D
4 Functional requirements above met.
16 Functions are implemented correctly and match specifications.
2 (1) Comments used
(2) Coding style followed
(3) Appropriate variable names, constants, and data types used
(4) Instructions followed
32 Total Points

This assignment is due by Thursday, February 21, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L4A, L4B, L4C, L4D .


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. The following instructions are copied from How to Submit Homework.


It is critical that you follow these steps when submitting homework.

If you do not follow these instructions, your assignment will receive a major deduction. Why all the fuss? Because we have several hundred of these assignments to grade, and we use computer tools to automate as much of the process as possible. If you deviate from these instructions, our grading tools will not work. And that makes us very unhappy. And when we're unhappy, we give penalties. Thus, make us happy.


Submission Instructions



Here are step-by-step instructions for submitting your homework properly:
  1. File and folder names are extremely important in this process. Please double-check carefully, to ensure things are named correctly.
    1. The top-level folder of your project must be named Set4
    2. Inside Set4, create 5 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g. L4A, L4B, L4C, L4D, and A4).
    3. Copy your main.cpp , additional header & source files, plus the CMakeLists.txt file into the subdirectories of Set4 (steps 1-2), zip this Set4 folder (steps 3-4), and then submit the zipped file (steps 5-11) to Canvas.
    4. For example, when you zip/submit Set4, there will be 5 sub-folders called L4A, L4B, L4C, L4D, and A4 inside the Set4 folder, and each of these sub-folders will have a file called main.cpp, additional header & source files, plus the CMakeLists.txt file .

  2. Using Windows Explorer (not to be confused with Internet Explorer), find the file named "main.cpp" located inside the folder for the particular lab or homework assignment you will submit.

    STOP: Are you really sure you are viewing the correct assignment's folder?

  3. Now, for A4, right click on the main.cpp to copy the file. Then, return to the Set4/A4 folder and right click to paste the file. In other words, put a copy of your homework's main.cpp source code into the Set4/A4 folder. Repeat this for each additional header & source file you have with this assignment, plus CMakeLists.txt.

    Follow the same steps for L4A, to put a copy of your lab's main.cpp into the Set4/L4A folder. Repeat this process for Set4/L4B, Set4/L4C, Set4/L4D.

    STOP: Are you sure your Set4 folder now has all your code to submit?

  4. Now, right-click on the "Set4" folder.
    1. In the pop-up menu that opens, move the mouse "Send to..." and expand the sub-menu.
    2. In the sub-menu that opens, select "Compressed (zipped) folder".

    STOP: Are you really sure you are zipping a Set4 folder with sub-folders that each contain a main.cpp file in it?

  5. After the previous step, you should now see a "Set4.zip" file.

  6. Now visit the Canvas page for this course and click the "Assignments" button in the sidebar.

  7. Find Set4, click on it, find the "Submist Assignment" area, and then click the "Choose File" button.

  8. Find the "Set4.zip" file created earlier and click the "Open" button.

    STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?

  9. WAIT! There's one more super-important step. Click on the blue "Submit Assignment" button to submit your homework.

  10. No, really, make sure you click the "Submit Assignment" button to actually submit your homework. Clicking the "Choose File" button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!

  11. Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!
In summary, you must zip the "Set4" folder and only the "Set4" folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this homework, and you must click the "Submit Assignment" button. Not doing these steps is like bringing your homework to class but forgetting to hand it in. No concessions will be made for incorrectly submitted work. If you incorrectly submit your homework, we will not be able to give you full credit. And that makes us unhappy.


This assignment is due by Thursday, February 21, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L4A, L4B, L4C, L4D .

Last Updated: 02/06/19 04:46


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