assignement_1_tcp1231
TRANSCRIPT
TCP1231 Computer Programming I
Trisemester II, 2011/2012
Assignment Questions
7th
November 2011
=====================================================================
This assignment is to be done individually. STRICTLY NO COPYING from other students
or from any other sources (Internet, books, etc.). Plagiarism and cheating is an offence! If you
fail to prove that you have done the assignment on your own, you will be given a mark of
ZERO.
There are 15 questions available in this list. You are required to select only one question and
follow the Submission Guidelines for assignment completion.
Due date: The assignment must be submitted to your respective tutor in Week 7, on 29th
November 2011, by 5pm. 5% of the full marks shall be deducted for every 24 hours (1 day)
delay.
Assignment demonstration will be conducted in Week 7 during lab session, by 2nd
December 2011.
Assignment 1 Registration
Go to http://ipms.site90.com/tcp1231 and login using the following credential to register
your question number.
Login ID: tcp1231_2011a1
Password: mmu_fist1992
Enter your student ID and select the question number. The assignment questions are available
based on first come first serve manner. One question cannot be selected by more than 3
students.
If your student ID does not exist in the database, then please inform me immediately. You
must select and register online by 14 November 2011.
The objective of this project is to test the skill of the students in problem solving and modular
design using algorithms, pseudo-code, and flowcharts. The students are expected to
implement the program in C++ language.
=====================================================================
Submission Guidelines:
Category Marks Your
Marks
Report
1 Cover Page -
2 Assignment Assessment Sheet -
3 Introduction and Problem Definition (IN YOUR OWN WORDS!!!) 2
4 Program design 4.1 Input, Process and Output (other Conditions / Assumptions /
Constraints)
4.2 Algorithms or Pseudocode
4.4 Flowcharts
4.5 Error-Handling
(20)
5
6
6
3
5 Coding 5.1 Code Efficiency
5.2 Code Strategy
5.3 Error Checking Features
5.4 Style – Self Documentation
5.5 Style – Indentation
(35)
12
12
6
3
2
6 Program Documentation 6.1 User Manual with Sample Screen Shots
6.2 Program Source Code with Comments (printed version)
6.3 A virus-free floppy disk/CD containing the softcopy of your
report and source code.
(13)
8
3
2
7 Demonstration - Program demonstration session by each student
(presenting your work to your tutor)
8 Program Execution
If the program cannot run (even if it can compile), 0 mark will be given for this section 6.1 General Appearance of Program (display)
6.2 Accuracy (program works and runs correctly)
6.3 Usability (interaction with user, user-friendliness)
6.4 Performs All Required Features
6.5 Error-free During Runtime
(30)
5
10
5
5
5
TOTAL 100
9 Bonus
Code Modularity (usage of functions)
Additional special features OR any other significant contributions
5
5
Error-handling: The program should handle special cases such as an accidental invalid input
from the user. In case of wrong inputs, how the program will proceed with
error detection?
Code Modularity: Break down the problem into smaller functions; the functions should
NEVER be too long.
Accuracy: Ensure the accuracy in terms of correct computations and usage of decimal
points.
Code Efficiency: Ensure the usage of control flow (e.g. unnecessary loops), logics,
computations, and code repetition.
Code Strategy: Ensure the proper flow of the program, usage of variables, and variable
naming convention.
Question 1
Negotiating a consumer loan is not always straightforward. One form of the loan is the discount
installment loan, which works as follows.
Suppose a loan has a face value $1,000.00, the interest rate is 15%, and the duration is 18 months. The interest rate is computed by multiplying the face value of $1,000.00 by 0.15 to yield $150.00.
This figure is then multiplied by the loan period of 1.5 years to yield $225.00 as the total interest
owned. The amount is immediately deducted from the face value, leaving the consumer with only $775.00.
Repayment is made in equal monthly installment based on the face value. Hence, the monthly loan payment will be $1,000.00 divide by 18, which is $55.56. This method of calculation may
not be too bad if the consumer needs $775.00 dollars, but the calculation is a bit more
complicated if the customer needs $1000.00.
Write a program that will take three inputs:
- the amount the consumer needs to receive
- the interest rate - the duration of the loan in months
The program should then calculate the face value required in order for the consumer to receive
the amount needed. It should also calculate the monthly payment. Your program should allow the calculations to be repeated as often as the user wishes.
=====================================================================
Question 2
An employee is paid at a rate of $16.78 per hour for the first 40 hours worked in a week. Any
hours over that are paid at the overtime rate of one and half times that. From the worker’s gross
pay, 6% is withheld for social security tax, 14% is withheld for federal income tax, 5% is withheld for state income tax, and $10.00 per week is withheld for union dues. If the worker has
three or more dependents, then an additional $35.00 is withheld to cover the extra cost of health
insurance beyond what the employer pays.
Write a program that will read in the number of hours worked in a week and the number of
dependents as input. The program will then output the worker’s gross pay, each withholding
amount, and the net take-home pay for the week. Your program should allow the calculation to be repeated as often as the user wishes.
=====================================================================
Question 3
You have purchased a stereo system that cost $1000.00 on the following credit card plan:
- no down payment
- an interest rate of 18% per year (and hence 1.5% per month)
- monthly payment of $50.00
The monthly payment of $50.00 is used to pay the interest and whatever is left is used to pay the
part of the remaining debt. Hence, the first month you pay 1.5% of $1000.00 in interest (that is $15.00 in interest). The remaining $35.00 is deducted from your debt, which leaves you with a
debt of $965.00. The next month you pay interest of 1.5% of $965.00 (that is $14.48). Hence, you
can deduct $35.52 (which is $50.00-$14.48) form the amount you owe.
Write a program that will tell you how many months it will take you to pay off the loan as well as
the total amount of interest paid over the life of the loan. Use loops to calculate the amount of
interest and the size of the dept after each month. Use a variable to count the number of loop iterations and hence the number of months until the dept is zero. You may want to use other
variables as well.
The last payment may be less than $50.00. Do not forget the interest on the last payment. If you
owe $50.00, then your monthly payment of $50.00 will not pay off your debt, although it will
come close. One month’s interest on $50.00 is only 75 cents. Your program should allow the calculation to be repeated as often as the user wishes.
=====================================================================
Question 4
Write a program that computes the cost of a long-distance call. The cost of the call is determined
according to the following rate schedule:
a. Any call started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at a rate of $0.40 per minute.
b. Any call starting before 8:00 A.M. or after 6:00 P.M., Monday through Friday, is charged
at a rate of $0.25 per minute.
c. Any call started on Saturday or Sunday is charged at a rate of $0.15 per minute.
The input will consist of
- the day of the week - the time the call started
- the length of the call in minutes
The output will be the cost of the call. The time is to be input in 24-hour notation (e.g. the time
1:30 P.M. is input as 13:30). The day of the week will be read as one of the following pairs of character values, which are stored in two variables of type char:
Mo Tu We Th Fr Sa Su
Be sure to allow the user to use either uppercase or lowercase letters or a combination of the two.
The number of minutes will be input as a value of type int. Your program should include a loop that lets the user repeat this calculation until the user says she or he is done.
=====================================================================
Question 5
Develop a simple Paper-Scissors-Rock program (http://en.wikipedia.org/wiki/Rock-paper-
scissors). Make it a single player game where the player plays with the computer. The party that
accumulatively wins 3 times first will win the game.
Option: Your program may include a loop that lets the user repeat the game until the user says she
or he is done.
=====================================================================
Question 6
Develop a simple Tic-Tac-Toe program. You can choose to develop a single player (player plays
with computer) or two players game.
Option: Your program may include a loop that lets the user repeat the game until the user says she
or he is done.
=====================================================================
Question 7
Write a program that asks for user’s height, weight, and age. It then should compute clothing
sizes acoording to the formulas: - Hat size = weight in pounds divided by heigh in inches and all that multiplied by 2.9.
- Jacket size (chest in inches) = height times weight divided by 288 and then adjusted by
adding 1/8 of an inch for each 10 years over age 30. (Note that the adjustment only takes
place after a full 10 years. Hence, there is no adjustment for ages 30 through 39, but 1/8 of an inch is added for age 40.)
- Waist in inches = weight divided by 5.7 and then adjusted by adding 1/10 of an inch for
each 2 years over age 28. (Note that the adjustment only takes place after a full 2 years. Hence, there is no adjustment for age 29, but 1/10 of an inch is added for age 30.)
Your prgram should allow the user to repeat this calculation as often as the user wishes.
=====================================================================
Question 8
Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following:
86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies)
Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use
nickel abd half-dollar coins. Include the loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program.
=====================================================================
Question 9
To maintain one’s body weight, an adult human needs to consume enough calories daily to:
1. Meet the basal metabolic rate (energy required to breath, maintain body temperature, etc).
2. Account for physical activity such as exercise.
3. Account for the energy required to digest the food that is being eaten.
For an adult that weights P pounds, we can estimate these caloric requirements using the
following formulas: 1. Basal metabolic rate: Calories required = 70*(P/2.2)0.756
2. Physical activity: Calories required = 0.0385*Intensity*P*Minutes
Minutes: Number of minutes spent during the physical activity Intensity: A number that estimates the intensity of the activity
Here are some sample numbers for the range of values:
Activity Intensity
Running 10 mph: 17 Running 6 mph: 10
Basketball: 8
Walking 1 mph: 1 3. Energy to digest food: calories required = TotalCaloriesConsumed*0.1
In other words, 10% pf the calories we consume goes towards digestion.
Develop a program that inputs a person’s weight, an estimate of the intensity of physical activity,
minutes spent execersing, and the number of calories in one serving of your favorite food. The
program should then clculate and output how many servings of that food should be eaten per day
to maintain the person’s current weight at the specified activity level. The computation should include the energy that is required to digest food.
You can find estimates of the caloric content of many foods on the web. For example, a double cheeseburger has approximately 1000 calories. Include the loop that lets the user repeat this
computation for new input values until the user says he or she wants to end the program
=====================================================================
Question 10
The sequence of triangle numbers is generated by adding the natural numbers. Hence, the 7th
triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
Let us list the factors of the first seven triangle numbers:
1: 1 3: 1,3
6: 1,2,3,6
10: 1,2,5,10 15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28 We can see that 28 is the first triangle number to have over five divisors. What is the value of the
first triangle number to have over one hundred divisors?
Question 11
The constant percentage method of computing depreciation of an asset is based on the assumption
that the depreciation charge at the end of each year is a fixed percentage of the book value of the
asset at the beginning of the year. This assumption leads to the following relationship:
S = C(1 ─ d)
n
where C = original cost of assed
d = depreciation rate per year n = number of years
S = book value of the end of n years.
Write a program to compute the number of years of useful life of an asset given the original cost,
depreciation rate, and book value at the end of its useful life (called scrap value). The program
should also display the book value at the end of each year until the end of its useful life. Your
program should allow the user to repeat this calculation as often as the user wishes.
Question 12
A bicycle accelerates at a constant rate from a stationary position. The gear in which the bicycle
is in depends on the velocity in the following manner.
Velocity (km/hour) Gear
0─3 1 3─5 2
5─7 3
7─10 4
10─12 5 12─15 6
15─17 7
17─21 8 21─24 9
24─28 10
28─35 11 35─40 12
40─48 13
48─55 14
55─100 15
Write a program to ask user to input an acceleration (km/hour) and the riding time (hh:mm:ss)
and determine which gear the bicycle is in at that time. Print the velocity and the gear number to
the screen. Limit the maximum velocity to 100km/hr. For any velocities that are on the border of a gear change, use the lower gear. Your program should allow the user to repeat this calculation
as often as the user wishes.
Question 13
A popular form of fitness aerobics makes use of an adjustable-height bench that increases the
intensity of aerobics workout without making it high impact. One of the important safety factors
in bench exercises is the bench height. The bench should not be too high for you; otherwise, there
is a danger of developing “chondromalacia patellae,” a degenerative knee condition caused by the grinding of the cartilage between the patella and the femur. The safe bench height depends on
your femur length and is determined by the knee angle formed when you stand in front of the
bench with one foot on the bench. The formula for knee angle in terms of bench_height and femur_length is
where = 3.1415936, angle is in degrees, and arccos is the “arc_cosine” function. Values for bench_height can be 2, 4, 6, 8, 10 and 12 inches. Values for femur_length can be integers in the range of 10 to 21 inches. Safe, risky and dangerous zones are defined as follows:
Safe zone : angle >= 140
Risky zone : 124 < angle < 140
Dangerous zone : angle <= 124 The program should prompt the user to input a femur length in inches and then computes and
prints the safe bench heights, as well as the maximum allowable bench height that is not
considered dangerous. Your program should allow the calculation to be repeated as often as the user wishes.
Question 14
Develop a program that accepts for each faculty member of a small college two data values:
faculty salary and a character value for faculty performance level. The performance-level data
item can have the values S, G, and A for superior, good, and average, respectively. We want the program to compute and display on the terminal screen the cost of a proposed pay increase
scheme. The pay increase scheme assumes a 3.5 percent across-the-board increase for all faculty
members, plus a merit raise. Merit raise percentages depend on the performance level; for
superior performance it is 2.5 percent, for good performance it is 1.5 percent, and for average performance no merit raise is given. The program should be able to accept data for any number of
faculty members.
Question 15
A rectangle in x─y space can be defined with the (x,y) coordinates of the lower left and upper
right corners. Write a program to determine whether three given rectangles overlap. Have a user input the corners of three rectangles (a total of six x-y) pairs. Print out whether or not the
rectangles overlap. If there is overlap, print out the pairs of overlapping rectangles and the
coordinates of the corners of their overlapping region. Your program should allow the calculation
to be repeated as often as the user wishes.
Hint: Try out the case with two rectangles first and analyze all possible overlap cases between
two rectangles. It may be possible for two rectangles to overlap at more than one corner.