Sei sulla pagina 1di 15

Programming Fundamentals

1
Chapter 3 - Problems
Problems
1. Roman Numerals
2. State Abbreviations
3. Areas of Rectangles
4. Test Scores and Grade
5. Mass and Weight
6. Time Calculator
7. Sorted Names
8. Software Sales
9. Shipping Charges
10. Fat Gram Calculator
11. Running the Race
12. The Speed of Sound
13. Internet Service Provider
1. Roman Numerals
 A number converter contains an integer within
the range of 1 through 10
 Convert the integer into the corresponding roman
numeral
 For example:
Integer Number Roman Numeral
1 I
2 II
3 III
… …
10 X
2. State Abbreviations
 A state translator includes a state abbreviation
 Translate the state abbreviation into its full name
as below:
Abbreviation Full Name
NC North Carolina
SC South Carolina
GA Georgia
FL Florida
AL Alabama

• Accept abbreviations in uppercase, lowercase or mixing


of them
• Return an error value if an abbreviation is not in the
above list
3. Areas of Rectangles
 A rectangle holds the following information:
• Length
• Width
 Calculate the area of rectangle:
Area = Length * Width
 Check if this rectangle’s area is greater than or
equal to another or not
• Return 1 for the greater case
• Return 0 for the equal case
• Otherwise, return -1
4. Test Scores and Grade
 A student’s transcript consist of three scores,
each score is for a subject that the student
achieved
 Calculate the average of test scores:
Average = (Score 1 + Score 2 + Score 3) / 3
 Determine the grade based on the average:
Test Score Grade
Average
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F
5. Mass and Weight
 The problem aims to convert an object’s mass
into its weight in Newtons.
 There is a converter which holds an object’s mass
 Convert the mass into the corresponding weight:
Weight = Mass * 9.8
 Determine the object’ status based on its weight:
• “Two heavy” if the weight is greater than 1000 Newtons
• “Two light” if the weight is less than 10 Newtons
• Otherwise, the status is “Normal”
6. Time Calculator
 A time calculator holds a mount of time in
seconds
 Calculate the number of minutes in that many
seconds
1 minute = 60 seconds
 Calculate the number of hours in that many
seconds
1 hours = 3600 seconds
 Calculate the number of days in that many
seconds
1 day = 86400 seconds
7. Sorted Names
 A name sorter holds three names
For example, “Charlie”, “Leslie”, and “Andy”
 Determine a name after the names sorted in
ascending order:
• The first name in the order (“Andy” for this case)
• The second name in the order (“Charlie” for this case)
• The third name in the order (“Leslie” for this case)
8. Software Sales
 A sold package item holds the following information:
• The stable price for each package: $99
• The number of packages purchased
 Determine the amount of the discount based on the
below table:
Quantity of packages Discount
10-19 20%
20-49 30%
55-99 40%
100 or more 50%

 Calculate the total amount of the purchase after the


discount
9. Shipping Charges
 A package shipping holds the following
information:
• Weight of package (pounds)
• Distance that the package is travelled on (miles)
 Calculate the shipping charges for a package
basedWeight
on the rate table:
of Package Rate per 500 Miles Shipped
2 pounds or less $1.10
Over 2 pounds but not more than 6 $2.20
pounds
Over 6 pounds but not more than 10 $3.70
pounds
Over 10 pounds $3.80

For example:
• The shipping charges of a 1-pound package with 500 miles is $1.10
10. Fat Gram Calculator
 A fat gram calculator for a food item holds the
following information:
• Total calories in the item
• The number of fat grams in the item. Each fat gram has
9 calories
 Calculate the percentage of calories from fat:
Percentage = Calories from fat / total calories
 Check if the item is low in fat or not. A food item
is in this status if and only if its calories from fat
are less than 30 percent of the total calories
11. Running the Race
 The problem is about determining achievement in
a three-competitor race
 The race records runners’ accomplishment as
soon as they finish
 Recording for each runner consists the following
information:
• The runner’s name
• An amount of time which it takes the runner to finish the
race
 Determine the first runner that reaches the goal
 Determine the second runner that reaches the
goal
 Determine the third runner that reaches the goal
12. The Speed Of Sound
 A sound meter is used for holding information
that a sound wave travels in a specific medium. It
consists of the following information:
• Medium that the wave travels in, can be air, water or
steel
• Distance that the wave travels
 Calculate the mount of time it takes the wave to
travel in the medium:
Time = Distance / Approximate speed for the medium
Medium Approximate speed
Air (feet/second) 1100

Water 4900
Steel 16400
13. Internet Service Provider
 The ISP provides three different packages for its
customers:
• Package A: For $9.95 per month 10 hours of access are
provided. Additional hours are $2.00 per hour
• Package B: For $13.95 per month 20 hours of access are
provided. Additional hours are $1.00 per hour
• Package C: For $19.95 per month unlimited access is
provided
 A customer’s monthly bill includes the following
information:
• Package’s name (A, B or C) that the customer has been
using
• The number of hours that were used
 Calculate the monthly total charge that a

Potrebbero piacerti anche