Question
THIS IS FOR C++ ONLY! Below are the test cases you should get once you are done doing the programming part. Test Case 1: What
THIS IS FOR C++ ONLY!
Below are the test cases you should get once you are done doing the programming part.
Test Case 1:
What is your name? Cletus
In what month were you born? 8
What was the date? 31
What was the year? (yyyyy)? 1961
What is your height (inches)? 70
What is your weight (lbs)? 190
What color are your eyes?
1. Black
2. Blue
3. Green
4. Brown
5. Gray
6. Hazel
7. Red
8. Pink
9. Violet
Select eye color: 4
How long is your index finger? 3.1
How long is your ring finger? 3.8
Cletus, your lucky number is 10. Thank you, that will be $25
Test Case 2:
What is your name? Wilma
In what month were you born? 9
What was the date? 15
What was the year? (yyyyy)? 1993
What is your height (inches)? 63
What is your weight (lbs)? 130
What color are your eyes?
1. Black
2. Blue
3. Green
4. Brown
5. Gray
6. Hazel
7. Red
8. Pink
9. Violet
Select eye color: 55
An invalid eye color was selected. The program is terminating.
Start of Actual Programming
//==================================================================================================
// INCLUDE DIRECTIVES
//==================================================================================================
??? // For abs() and exit()
??? // For pow() and sqrt()
??? // For cin, cout, endl
??? // For string class
using namespace std;
//==================================================================================================
// CONSTANT DEFINITIONS
//==================================================================================================
// Constants for converting inch to cm and lb to kg.
??? define double constant CM_PER_INCH to be 2.54
??? define double constant LB_PER_KG to be 2.20462262.
// Eye color menu constants. See Fig 1 in the lab project document.
??? define int constant MENU_BLACK to be 1
??? define int constant MENU_BLUE to be 2
??? define int constant MENU_GREEN to be 3
??? define int constant MENU_BROWN to be 4
??? define int constant MENU_GRAY to be 5
??? define int constant MENU_HAZEL to be 6
??? define int constant MENU_RED to be 7
??? define int constant MENU_PINK to be 8
??? define int constant MENU_VIOLET to be 9
//==================================================================================================
// FUNCTION PROTOTYPES
//==================================================================================================
// ??? Write a prototype for the validate_eye_color() function. This prototype is necessary because
// validate_eye_color() is defined below the point from where it is first called -- in
// get_eye_color().
???
// ??? Write a prototype for the get_int() function. This protoype is necessary because get_int()
// is defined below the point from where it is first callled -- in get_eye_color().
???
//==================================================================================================
// FUNCTION DEFINITIONS
//==================================================================================================
//--------------------------------------------------------------------------------------------------
// FUNCTION: calc_lucky()
//
// DESCRIPTION
// Calculates and returns the customer's lucky number using the Even Better Lucky Number Formula(tm).
//
// PARAMS:
// date int d in the formula
// height int h in the formula
// month int m in the formula
// weight int w in the formula
// year int y in the formula
// eye int e in the formula
// finger double f in the formula
//
// PSEUDOCODE
// function calc_lucky(date, height, month, weight, year, eye, finger)
// term1 = 2 x month^2.2 + 3 x date^3.3 + 5 x sqrt(y)
// term2 = (eye x height) / 3
// term3 = (11 x weight) / 5
// term4 = term1 + finger(term2 + term3)
// return ConvertToInt(|term4|) mod 10 + 1
// end function calc_lucky()
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: convert_inch_to_cm()
//
// DESCRIPTION
// Converts inches to centimeters.
//
// PSEUDOCODE
// function convert_inch_to_cm(inches)
// return inches x CM_PER_INCH
// end function convert_inch_to_cm
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: convert_lb_to_kg()
//
// DESCRIPTION
// Converts pounds to kilograms.
//
// PSEUDOCODE
// function convert_lb_to_kg(lbs)
// return lbs / LB_PER_KG
// end function convert_lb_to_kg
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: error_exit()
//
// DESCRIPTION
// Called when the program cannot continue due to user input error. Displays the message string
// 'msg' on the output window and calls exit(-1) to terminate the program.
//
// PSEUDOCODE
// function error_exit(msg)
// send msg, endl to cout
// call exit(-1)
// end function error_exit
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: get_double()
//
// DESCRIPTION
// Display a prompt and read a number (as a double) from the keyboard. Return the number.
//
// PSEUDOCODE
// See Get.cpp on the course website.
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: get_eye_color()
//
// DESCRIPTION
// Displays a menu of eye colors and asks the user to select one. Returns e based on the table in
// the lab project document.
//
// PSEUDOCODE
// function get_eye_color()
// display the eye color menu as shown in the lab project document
// choice = get_int("Select Eye Color: ")
// validate_eye_color(choice)
// define int variable e
// if choice is MENU_BLACK then
// e = 3
// else if choice == MENU_BLUE then
// e = -2
// ... and so on for the remaining eye colors
// return e
// end function get_eye_color
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: get_int()
//
// DESCRIPTION
// Display a prompt and read a number (as an int) from the keyboard. Return the number.
//
// PSEUDOCODE
// See Get.cpp on the course website.
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: get_string()
//
// DESCRIPTION
// Display a prompt and read a string from the keyboard. Return the string.
//
// PSEUDOCODE
// See Get.cpp on the course website.
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: my_round
//
// DESCRIPTION
// This function rounds 'value' up or down and returns the result as an int. For example, if value
// is 2.3, then we return ConvertToInt(2.3 + 0.5) = ConvertToInt(2.8) = 2 (which rounds 2.3 down).
// If value were 2.8 then we would return ConvertToInt(2.8 + 0.5) = ConvertToInt(3.3) = 3 (which
// rounds 2.8 up). Make sure you understand how rounding works for negative values as well.
//
// PSEUDOCODE
// function my_round(value)
// if value 0 then
// return ConvertToInt(value + 0.5)
// else
// return ConvertToInt(value - 0.5)
// end if
// end function my_round
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: validate_eye_color()
//
// DESCRIPTION
// Validates that the user selects an eye color menu item in the range 1-9. If so, this function
// simply returns. If not, we display an error message and terminate the program.
//
// PSEUDOCODE
// function validate_eye_color(choice)
// if choice < MENU_BLACK or choice > MENU_VIOLET then
// error_exit("An invalid eye color was selected. The program is terminating...")
// end if
// end function validate_eye_color
//--------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------
// FUNCTION: main()
//
// PSEUDOCODE
// function main()
// display "Zelda's Lucky Number Calculator" followed by endl, endl
// define int variables: date, e, height_cm, height_in, lucky, month, weight_kg, weight_lb, year
// define double variables: f, index, ring
// define string object: name
// name = get_string("What is your name? ")
// month = get_int("In what month were you born? ")
// date = get_int("What was the date? ")
// year = get_int("What was the year (yyyy)? ")
// height_in = get_int("What is your height (inches)? ");
// weight_lb = get_int("What is your weight (lbs)? ")
// height_cm = my_round(convert_inch_to_cm(height_in))
// weight_kg = my_round(convert_lb_to_kg(weight_lb))
// e = get_eye_color()
// index = get_double("How long is your index finger? ")
// ring = get_double("How long is your ring finger? ")
// f = 0
// if (index < ring) then
// f = -1;
// else if (index > ring) then
// f = 1;
// end if
// lucky = calc_lucky(date, height_cm, month, weight_kg, year, e, f)
// send name ", your lucky number is " lucky ". Thank you, that will be $25." endl to cout
// return 0
// end function main()
//--------------------------------------------------------------------------------------------------
???
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started