0% found this document useful (0 votes)
62 views3 pages

4 - Chapter 4 - Making Decisions

1. The document contains 10 programming assignments involving calculations related to geometry, finance, health, and conversions. 2. The assignments include writing programs to determine the larger of two numbers, convert numbers to Roman numerals, calculate rectangle areas, calculate body mass index, apply quantity discounts to software sales, calculate bank fees, compare race times, calculate fat content of foods, and build a geometry calculator. 3. Input validation is required for many assignments to prevent negative or out-of-range values.

Uploaded by

Def Abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views3 pages

4 - Chapter 4 - Making Decisions

1. The document contains 10 programming assignments involving calculations related to geometry, finance, health, and conversions. 2. The assignments include writing programs to determine the larger of two numbers, convert numbers to Roman numerals, calculate rectangle areas, calculate body mass index, apply quantity discounts to software sales, calculate bank fees, compare race times, calculate fat content of foods, and build a geometry calculator. 3. Input validation is required for many assignments to prevent negative or out-of-range values.

Uploaded by

Def Abc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment 4

1. Minimum/Maximum
Write a program that asks the user to enter two numbers. The program should use the conditional
operator to determine which number is the smaller and which is the larger.

2. Roman Numeral Converter


Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch
statement to display the Roman numeral version of that number.

Input Validation: Do not accept a number less than 1 or greater than 10.

3. Areas of Rectangles
The area of a rectangle is the rectangle’s length times its width. Write a program that asks for the length
and width of two rectangles. The program should tell the user which rectangle has the greater area, or if
the areas are the same.

4. Body Mass Index


Write a program that calculates and displays a person’s body mass index (BMI). The BMI is often used to
determine whether a person with a sedentary lifestyle is overweight or underweight for his or her height.
A person’s BMI is calculated with the following formula:

𝐵𝑀𝐼 = 𝑤𝑒𝑖𝑔ℎ𝑡 × 703 / ℎ𝑒𝑖𝑔ℎ𝑡 1


where weight is measured in pounds and height is measured in inches. The program should display a
message indicating whether the person has optimal weight, is underweight, or is overweight. A sedentary
person’s weight is considered to be optimal if his or her BMI is between 18.5 and 25. If the BMI is less than
18.5, the person is considered to be underweight. If the BMI value is greater than 25, the person is
considered to be overweight.

5. Software Sales
A software company sells a package that retails for $99. Quantity discounts are given according to the
following table.

Quantity Discount
10-19 20%
20-49 30%
50-99 40%
100 or more 50%

Write a program that asks for the number of units sold and computes the total cost of the purchase.

Input Validation: Make sure the number of units is greater than 0.


6. Bank Charges
A bank charges $10 per month plus the following check fees for a commercial checking account:

$.10 each for fewer than 20 checks


$.08 each for 20–39 checks
$.06 each for 40–59 checks
$.04 each for 60 or more checks

The bank also charges an extra $15 if the balance of the account falls below $400 (before any check fees
are applied). Write a program that asks for the beginning balance and the number of checks written.
Compute and display the bank’s service fees for the month.

Input Validation: Do not accept a negative value for the number of checks written. If a negative value is
given for the beginning balance, display an urgent message indicating the account is overdrawn.

7. Running the Race


Write a program that asks for the names of three runners and the time it took each of them to finish a
race. The program should display who came in first, second, and third place.

Input Validation: Only accept positive numbers for the times.

8. Fat Gram Calculator


Write a program that asks for the number of calories and fat grams in a food. The program should display
the percentage of calories that come from fat. If the calories from fat are less than 30% of the total calories
of the food, it should also display a message indicating that the food is low in fat.

One gram of fat has 9 calories, so


Calories from fat = fat grams * 9
The percentage of calories from fat can be calculated as
Calories from fat ÷ total calories

Input Validation: Make sure the number of calories and fat grams are not less than 0. Also, the number of
calories from fat cannot be greater than the total number of calories. If that happens, display an error
message indicating that either the calories or fat grams were incorrectly entered.

9. Freezing and Boiling Points


The following table lists the freezing and boiling points of several substances. Write a program that asks
the user to enter a temperature and then shows all the substances that will freeze at that temperature
and all that will boil at that temperature. For example, if the user enters −20 the program should report
that water will freeze and oxygen will boil at that temperature.

Substance Freezing Point (oF) Boiling Point (oF)


Ethyl alcohol -173 172
Mercury -38 676
Oxygen -362 -306
Water 32 212
10. Geometry Calculator
Write a program that displays the following menu:

Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter your choice (1-4):

If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the
following formula:

𝑎𝑟𝑒𝑎 = 𝜋𝑟 1
Use 3.14159 for 𝜋 and the radius of the circle for r. If the user enters 2, the program should ask for the
length and width of the rectangle and then display the rectangle’s area. Use the following formula:

𝑎𝑟𝑒𝑎 = 𝑙𝑒𝑛𝑔𝑡ℎ ∗ 𝑤𝑖𝑑𝑡ℎ


If the user enters 3 the program should ask for the length of the triangle’s base and its height, and then
display its area. Use the following formula:

𝑎𝑟𝑒𝑎 = 𝑏𝑎𝑠𝑒𝑧 ∗ ℎ𝑒𝑖𝑔ℎ𝑡 ∗ .5


If the user enters 4, the program should end. Input Validation: Display an error message if the user enters
a number outside the range of 1 through 4 when selecting an item from the menu. Do not accept negative
values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy