0% found this document useful (0 votes)
2 views4 pages

Assignment 2

The document outlines ten programming exercises for beginners, covering various topics such as calculating the day of the week, areas of rectangles, age classification, Roman numerals, mass and weight, time calculations, color mixing, book club points, software sales, and shipping charges. Each exercise includes specific requirements and conditions for user input and expected output. The exercises aim to enhance programming skills through practical applications.

Uploaded by

muusenimco911
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)
2 views4 pages

Assignment 2

The document outlines ten programming exercises for beginners, covering various topics such as calculating the day of the week, areas of rectangles, age classification, Roman numerals, mass and weight, time calculations, color mixing, book club points, software sales, and shipping charges. Each exercise includes specific requirements and conditions for user input and expected output. The exercises aim to enhance programming skills through practical applications.

Uploaded by

muusenimco911
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/ 4

Programming Exercises

1. Day of the Week


Write a program that asks the user for a number in the range of 1 through 7. The
program should display the corresponding day of the week, where 1 = Monday, 2 =
Tuesday,3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday.
The program should display an error message if the user enters a number that is
outside the range of 1 through 7.
2. 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.
3. Age Classifier
Write a program that asks the user to enter a person’s age. The program should
display
a message indicating whether the person is an infant, a child, a teenager, or an
adult.
Following are the guidelines:
• If the person is 1 year old or less, he or she is an infant.
• If the person is older than 1 year, but younger than 13 years, he or she is a child.
• If the person is at least 13 years old, but less than 20 years old, he or she is a
teenager.
• If the person is at least 20 years old, he or she is an adult.
4. Roman Numerals
Write a program that prompts the user to enter a number within the range of 1
through 10.
The program should display the Roman numeral version of that number. If the
number is outside the range of 1 through 10, the program should display an error
message. The following table shows the Roman numerals for the numbers 1
through 10:
Number Roman Numeral
1I
2 II
3 III
4 IV
5V
6 VI
7 VII
8 VIII
9 IX
10 X
5. Mass and Weight
Scientists measure an object’s mass in kilograms and its weight in newtons. If you
know the amount of mass of an object in kilograms, you can calculate its weight in
Newtons with the following formula:
weight 5 mass 3 9.8
Write a program that asks the user to enter an object’s mass, and then calculates its
weight.
If the object weighs more than 500 newtons, display a message indicating that it is
too heavy. If the object weighs less than 100 newtons, display a message indicating
that it is too light.
6. Time Calculator
Write a program that asks the user to enter a number of seconds and works as
follows:
• There are 60 seconds in a minute. If the number of seconds entered by the user is
greater than or equal to 60, the program should display the number of minutes in
that many seconds.
• There are 3,600 seconds in an hour. If the number of seconds entered by the user
is greater than or equal to 3,600, the program should display the number of hours
in that many seconds.
• There are 86,400 seconds in a day. If the number of seconds entered by the user is
greater than or equal to 86,400, the program should display the number of days in
that many seconds.
7. Color Mixer
The colors red, blue, and yellow are known as the primary colors because they
cannot
be made by mixing other colors. When you mix two primary colors, you get a
secondary
color, as shown here:
When you mix red and blue, you get purple.
When you mix red and yellow, you get orange.
When you mix blue and yellow, you get green.
Design a program that prompts the user to enter the names of two primary colors to
mix. If the user enters anything other than “red,” “blue,” or “yellow,” the program
should display an error message. Otherwise, the program should display the name
of the secondary color that results.
8. Book Club Points
Serendipity Booksellers has a book club that awards points to its customers based
on the
number of books purchased each month. The points are awarded as follows:
• If a customer purchases 0 books, he or she earns 0 points.
• If a customer purchases 2 books, he or she earns 5 points.
• If a customer purchases 4 books, he or she earns 15 points.
• If a customer purchases 6 books, he or she earns 30 points.
• If a customer purchases 8 or more books, he or she earns 60 points.
Write a program that asks the user to enter the number of books that he or she has
purchased
this month and displays the number of points awarded.
9. 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 10%
20–49 20%
50–99 30%
100 or more 40%
Write a program that asks the user to enter the number of packages purchased. The
program should then display the amount of the discount (if any) and the total
amount of the purchase after the discount.
10. Shipping Charges
The Fast Freight Shipping Company charges the following rates:
Weight of Package Rate per Pound
2 pounds or less $1.50
Over 2 pounds but not more than 6 pounds $3.00
Over 6 pounds but not more than 10 pounds $4.00
Over 10 pounds $4.75
Write a program that asks the user to enter the weight of a package and then
displays the shipping charges.

END

You might also like