CIS 150 C++ Programming Project: Selection, output formatting
Objectives
- Use selection
- Get user input
- Perform calculations
- Demonstrate output formatting
Program requirements
- Include documentation comments at the start of the file.
- Follow the course style guidelines including indentation, naming conventions, spaces instead of tabs, etc.
- Display a menu with four options as follows:
Convert inches to:
1. feet
2. yards
3. centimeters
4. meters
Enter choice:
- Get the menu choice from the keyboard.
- If the user entered a choice not available on the menu, display an error message and end the program.
- If the user entered a valid choice, prompt the user for and get the number of inches. This should be required to be an integer (NOT a floating point number).
- Do the appropriate conversion and display the result with a meaningful message. Feet and yards must display integer values. Centimeters and meters must display floating-point values with one digit after the decimal point.
Conversion formulas
- To convert inches to feet the formula is: feet = inches / 12. Use modulus to get the inches left over. Display both feet and inches.
- To convert inches to yards the formula is: inches / 36. Use modulus to get the feet and inches left over. Display yards, feet and inches. Remember that the value for feet should not include those in yards.
- To convert inches to centimeters the formula is: inches / .39370. Display 1 digit to the right of the decimal point.
- To convert inches to meters the formula is: inches / 39.370. Display 1 digit to the right of the decimal point.
Points
- 2 points: Proper documentation comments
- 3 points: Follows style guidelines used in class (indentation, no tabs, variables names start with lowercase letter, etc.)
- 2 points: Menu displays properly (as shown in sample runs)
- 2 points: Program prompts user and gets menu choice from user
- 2 points: Program ends with error message for invalid menu choice
- 3 points: Inches to feet conversion done properly (to feet and leftover inches) and has meaningful result message
- 5 points: Inches to yards conversion done properly (to yards, feet and leftover inches) and has meaningful result message
- 3 points: Inches to centimeters conversion done properly and has meaningful result message
- 3 points: Inches to meters conversion done properly and has meaningful result message
- 4 points: Output formatting is integer for yards, feet, and inches, and has one digit showing after the decimal for meters and centimeters
Example runs
Note: These example runs show several runs of the sample program.
Convert inches to:
1. feet
2. yards
3. centimeters
4. meters
Enter choice: 6
Error: Invalid menu choice
Convert inches to:
1. feet
2. yards
3. centimeters
4. meters
Enter choice: 1
Enter the number of inches: 27
That is 2 feet, 3 inches
Convert inches to:
1. feet
2. yards
3. centimeters
4. meters
Enter choice: 2
Enter the number of inches: 99
That is 2 yards, 2 feet, 3 inches
Convert inches to:
1. feet
2. yards
3. centimeters
4. meters
Enter choice: 3
Enter the number of inches: 27
That is 68.6 centimeters
Convert inches to:
1. feet
2. yards
3. centimeters
4. meters
Enter choice: 4
Enter the number of inches: 27
That is 0.7 meters