CSCI 261 - Programming Concepts (C++)Fall 2016 - Lab 03BQuick Links: Blackboard | EECS | Mines | Piazza | zyBooks |
||||||||||||||||||||||||||||||||||||||||||||||
| Home | Contact | Syllabus | Assignments | Schedule | Resources | | ||||||||||||||||||||||||||||||||||||||||||||||
This lab is due by September 14, 2016 08:00am.
Triangle Classifier + Options MenuThe goal of this lab is to practice the use of the switch statement. Your solution will be submitted with Week03 next Wednesday.
Let's StartFor this lab, we are providing you with some initial code. First create yourself an empty project, and then add a new C++ source file called main.cpp. In your main.cpp, copy/paste the code that is available here.
InstructionsIn Lab 03A you created a program that classifies triangles based on three side measurements provided by the user. For Lab 03B, you need to offer to the user the following menu of options:
1. Enter measurements
2. Print measurements 3. Check triangle feasibility 4. Classify triangle 5. Print triangle perimeter 6. Print triangle area 7. Print triangle summary 8. Exit The initial code provided in the Lab03B_main.cpp file does several tasks for you: (1) reads the user's choice, (2) verifies that the chosen option is a number between 1 and 8, and (3) quits the execution of the program if the user chooses option 8 (exit). The initial code provided also includes a
do-while loop, which is a C++ repetition statement that we will cover next week; just leave this code alone for now. Your task is to add code to this initial program that implements each of these menu options, which are explained in more detail below. NOTE: a good chunk of the code you wrote for Lab 03A is useful for this lab; feel free to cut/paste what you have already written (if useful).
Option 1: Enter MeasurementsAsk the user to enter three real value measurements (i.e., > 0). Read these measurements using the already declared variables named inputA, inputB, and inputC. If any of the measurements provided by the user is invalid (i.e., <= 0), then print an error message and immediately quit the entire program (return 0). If all three measurements are valid, copy the variables to the already declared variables named a, b, and c, such that c is the largest. Once done, set the boolean variable isTriangle to false, as you have yet to test whether the measurements provided form a triangle.
Option 2: Print MeasurementsIn this option, you should print the measurements (i.e., variables a, b, and c) in ascending order.
Option 3: Check Triangle FeasibilityFor this option, you should check whether the input provided forms a triangle. Depending on your calculation, you should set the boolean variable isTriangle to be true or false.
Option 4: Classify TriangleYou should classify a triangle IF (and only if) a triangle exists (i.e., isTriangle is true). If this boolean variable is true, tell the user whether the triangle is a right, acute, or obtuse triangle. Otherwise, politely remind them that a triangle does not exist. (Hint: reuse your Lab03A code)
Option 5: Print triangle perimterYou should compute the perimeter of a triangle IF (and only if) a triangle exists. If a triangle exists, tell the user the perimeter of the triangle. Otherwise, politely remind them that a triangle does not exist.
Option 6: Print triangle areaYou should compute the area of a triangle IF (and only if) a triangle exists. If a triangle exists, tell the user the area of the triangle. Otherwise, politely remind them that a triangle does not exist. (Hint: use the Information Superhighway to find a formula for calculating the area of a triangle given the length of its sides.)
Option 7: Print triangle summaryYou should print the triangle summary IF (and only if) a triangle exists. If a triangle exists, tell the user all of the above information in one condensed format. Otherwise, politely remind them that a triangle does not exist. Your output should look as follows:
Triangle sides: 3
4 5 Classification: Right Triangle Perimeter: 12 Area: 6 Option 8: ExitDuh - exit!
Program UseA smart user of this program will first choose Option 1 (to enter measurements), then Option 2 (to verify measurements entered are correct), then Option 3 (to check whether the measurements form a triangle), then Option 4 (to classify the triangle), then Option 5 (to print the perimeter), then Option 6 (to print the area), then Option 7 (to print a summary) and then Option 8 (to quit). Unlike the real world, you can assume only smart users of your program exist.
Test ValuesHere are some known input/output values that you can test against. Be sure to try your own to verify the code works!
Lab Submission
You will submit your solution to this lab with the rest of Week03. Detailed instructions for doing this are posted in Assignment 03.
This lab is due by September 14, 2016 08:00am.
| ||||||||||||||||||||||||||||||||||||||||||||||
Last Updated: 01/01/70 00:00
|