Valid user entries are:
- 'C' for Cotton
- 'L' for Liner
- 'P' for Polyester
Prompt:
Enter the fabric code found on your pants:
Possible Output:
Your pants contain cotton. Air dry to avoid shrinking!
Your pants contain linen. They are cool but wrinkle easily!
Your pants contain polyester. They are stain resistant!
Invalid fabric code. Please run the program again.
Notes and Hints:
1) You must accept the upper or lowercase version of the letters. Use whatever method you want of handling this.
Your textbook mentions that relational operators can be used to compare letters and words, thanks to ASCII. This simple program will ask the user to enter two letters and then two words to see if we can really "sort" these entries alphabetically with relational operators.
Prompts:
This is a Letter and Word sorting program
Enter two different letters separated by a space: [assume user inputs: b a]
Enter two different words separated by a space: [assume user inputs: bob alex]
Output:
a goes before b
alex goes before bob
Notes and Hints:
1) Do NOT convert the user's entry to uppercase. Some of the test cases will be comparing lowercase to uppercase letters (the results are interesting!)
2) Don't worry about the possibility of the user entering the same letters/words or entering something else. Keep this program simple.
ABC Delivery promises to deliver any package from one location in Miami Dade County to another in 2 to 24 hours. They can handle packages from 0.1 to 100 pounds. Their rate table is below:
Write a program that asks the user for the package weight. If the range is acceptable, ask for the delivery speed. If the range is acceptable, proceed with calculating the delivery cost.
Prompt:
Enter a shipping weight (in pounds) up to 100 lbs:
How soon do you need this delivered? Enter a number of hours between 2 and 24:
Possible Outputs (the numbers do not output, they are for clarification only)
1) Invalid weight
2) Invalid number of hours
3) We can make that delivery!
The total price of your 100-pound package delivered within 5 hours is $150
Notes and Hints:
1) Nothing weighs zero pounds. Reject that type of entry.
2) Hours must be a whole number entry from user. Weight can include decimal.
3) There are many ways to solve this. You only need what you learned in class today (nothing from future lessons). The best solutions are those that minimize CPU time by reducing how many conditions it has to check. Be creative and think this through before you start coding!
Ask the user to enter the name of one primary color (red, blue, yellow) and a second primary color that is different from the first. Based on the user's entries, figure out what new color will be made when mixing those two colors. Use the following guide:
If the user enters anything that is outside one of the above combinations, return an error message.
Prompts:
Enter a primary color (red, blue, yellow):
Enter a different primary color (red, blue, yellow):
Possible Outputs:
red and blue make purple
blue and yellow make green
yellow and red make orange
You entered invalid colors
Notes and Hints:
1) The program should work regardless of the color order. In other words, it shouldn't matter if the user enters red or blue first...the two colors make purple.
2) Regarding #1, this means that the first three outputs shown above may appear with the colors in a different order. Hint: Use variables in your output to make this easy!
3) If the user has any uppercase letters, it will not work. This is normal, as C++ is case sensitive. We will solve this problem in a future in-class lesson.
Most people know that the average human body temperature is 98.6 Fahrenheit (F). However, body temperatures can reach extreme levels, at which point the person will likely become unconscious (or worse). Those extremes are below 86 F and above 106 F.
Write a program that asks the user for a body temperature in Fahrenheit (decimals are ok). Check if that temperature is in the danger zone (for unconsciousness) or not and produce the relevant output shown below. Also check if the user entered a number greater than zero. If they didn't, display an error message and don't process the rest of this program.
If the entry was valid, convert the temperature from Fahrenheit to Celsius. and output it to the user.
F to C formula: (temp - 32) * 5 / 9
Prompts:
Enter a body temperature in Fahrenheit:
Possible Outputs:
This person is likely unconscious and in danger
Temperature in Celsius is: 41.6667
This person is likely conscious
Temperature in Celsius is: 37
Invalid entry
Notes and Hints:
1) This exercise is testing your knowledge of Flags and Logical Operators. Use both!
2) Do not use constants for the numbers in the F to C formula. Write it as-is.
3) Hint: The order in which you do your decision/conditional statements makes all the difference
4) Remember: Do not let this program do any math if the user's entry is invalid!
Ask the user to enter their weight (in pounds) and their height in inches. Calculate their Body Mass Index (BMI) and tell them whether they are underweight, overweight, or at optimal weight.
BMI formula: weight * 703 / (height * height)
Optimal weight is a BMI from 19 to 26. Lower is underweight, higher is overweight.
Prompts:
Enter your weight (in pounds):
Enter your height (in inches):
Possible Outputs:
Your BMI is 18.9964, which means you are underweight.
Your BMI is 29.2612, which means you are overweight.
Your BMI is 25.8704, which means you are at optimal weight.
Notes and Hints:
1) For simplicity, assume user entries will be in whole numbers. However, BMI must be calculated with decimals.
2) You must use an if/else if structure for this
3) NOTE: The three exercises in this HW are going to make you think a bit. If you want really basic practice with if/else and related concepts, read your author's examples in section 4.5 - 4.9. He has plenty of easy code (with explanationa) in the main text.
A company changes the commission rate for sales reps depending on their total sales for the month. Their regular commission is 5% (.05). However, if they sell at least $100,000, they get 7% (.07). Ask the user for the sales amount this month and then calculate how much to pay the sales rep this month.
Output 1:
Enter the sales amount for the month as a whole number, no commas or $: [assume user types: 125000]
You met the $100,000 sales goal for the month. Your commission is 7%
Your total commission on $125000 is: $8750
Output 2:
Enter the sales amount for the month as a whole number, no commas or $: [assume user types: 60000]
You did not meet the $100,000 sales goal for the month. Your commission is 5%
Your total commission on $60000 is: $3000
Hints and Notes:
1) Use an If/Else for this
2) The "100,000" portion of the output is a literal. I did not use the constant for this part of the output because I wanted to format the message nicely for the user.
Write a program that asks an employee how many hours were worked this week. The base pay rate is $12.50 / hr. For overtime hours (over 40), the employee should be paid 1.5 times the base rate (or 0.5 times base rate as a bonus...however you want to see it).
Output 1:
Enter the hours worked for the week as a whole number: [assume user types: 42]
You worked 2 overtime hours
Your total pay this week is $537.5
Output 2:
Enter the hours worked for the week as a whole number: [assume user types: 36]
Your total pay this week is $450
Hints and Notes:
1) There are many ways to do the math here. Use whatever method you are comfortable with, as I assume you’ve calculated this for your own job before.
2) Do NOT use an ELSE for this question. IF only.
Write a program that asks the user for their age and lets them know if they are eligible to vote. If they are not eligible, let them know how many years they have left.
Output 1:
Enter your age as a whole number: [assume user types: 20]
You are eligible to vote!
Output 2:
Enter your age as a whole number: [assume user types: 15]
You will be eligible to vote in 3 years
Hints and Notes:
1) Use an If/Else for this
The If statement can be used to change the value of a string, which in turn can affect the output that the user sees. In this program, you will set your favorite letter to ‘m’. You will also set a string to initially store the word “was”.
Ask the user to guess your letter. If it is guessed incorrectly, modify the string to store the words “was not”. If guessed correctly, don’t change the string.
Output 1:
Guess my favorite lowercase letter: [assume user types: m]
My favorite letter was guessed
Output 2:
Guess my favorite lowercase letter: [assume user types: a]
My favorite letter was not guessed
Hints and Notes:
1) Do NOT use an ELSE for this question. You only need one IF statement and one output statement for the was / was not guessed part.
2) As you probably noticed, the only words that change in the output are “was” and “was not”. The rest of the output is always the same.