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

Lab 1 - Making Decisions

The document describes 6 programming exercises: 1) A math tutor program that displays addition problems and solutions 2) A word game that inserts user-provided information into a story template 3) A program to calculate interest earned in a savings account 4) A program to calculate fat grams and percentages from calorie and fat gram inputs 5) A program to identify substances that freeze or boil at a given temperature 6) A geometry calculator menu program to compute areas of circles, rectangles, and triangles

Uploaded by

Nony Shin
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)
45 views3 pages

Lab 1 - Making Decisions

The document describes 6 programming exercises: 1) A math tutor program that displays addition problems and solutions 2) A word game that inserts user-provided information into a story template 3) A program to calculate interest earned in a savings account 4) A program to calculate fat grams and percentages from calorie and fat gram inputs 5) A program to identify substances that freeze or boil at a given temperature 6) A geometry calculator menu program to compute areas of circles, rectangles, and triangles

Uploaded by

Nony Shin
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

Lab 1

1. Math Tutor
Write a program that can be used as a math tutor for a young student. The program should display two
random numbers to be added, such as
247
+129
The program should then pause while the student works on the problem. When the student is ready to
check the answer, he or she can press a key and the program will display the correct solution:
247
+129
376
2. Word Game
Write a program that plays a word game with the user. The program should ask the user to enter the
following:

• His or her name


• His or her age
• The name of a city
• The name of a college
• A profession
• A type of animal
• A pet’s name

After the user has entered these items, the program should display the following story, inserting the user’s
input into the appropriate locations:
There once was a person named NAME who lived in CITY. At the age of AGE, NAME
went to college at COLLEGE. NAME graduated and went to work as a PROFESSION.
Then, NAME adopted a(n) ANIMAL named PETNAME. They both lived happily ever
after!

3. Interest Earned
Assuming there are no deposits other than the original investment, the balance in a savings account after
one year may be calculated as

𝑅𝑎𝑡𝑒 !
𝐴𝑚𝑜𝑢𝑛𝑡 = 𝑃𝑟𝑖𝑛𝑐𝑖𝑝𝑎𝑙 ∗ 91 + =
𝑇
Principal is the balance in the savings account, Rate is the interest rate, and T is the number of times
the interest is compounded during a year (T is 4 if the interest is compounded quarterly).

Write a program that asks for the principal, the interest rate, and the number of times the interest is
compounded. It should display a report similar to

Interest Rate: 4.25%


Times Compounded: 12
Principal: $ 1000.00
Interest: $ 43.34
Amount in Savings: $ 1043.34

4. 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.

5. 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
6. 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:

𝑎𝑟𝑒𝑎 = 𝜋𝑟 "
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