Professional Documents
Culture Documents
CSBP112 Projects
CSBP112 Projects
PROJECT
ACADEMIC INTEGRITY
Academic integrity is of central importance to an education at UAEU. Students have the
responsibility to know and observe the requirements of the UAEU Code of Academic
Honesty available:
http://www.uaeu.ac.ae/en/catalog/plagiarism_and_academic_integrity.shtml and the penalties
resulting from violation of this code. This code forbids cheating, fabrication or falsification of
information, multiple submission of academic work, plagiarism, abuse of academic materials,
and complicity in academic dishonesty. Cheating in any form and on any academic work
results in serious penalties that include dismissal from the university.
Project 1:
Triangular Shapes (OUTPUT Perimeter and Area or surface area and volume as
appropriate.)
The program should permit the user to keep going or terminate after each calculation is made.
Project 2:
1. Trigonometric Functions:
Write a demonstration program that asks the user to select one of three possible inverse functions:
ArcSin, ArcCos, or ArcTan, and subsequently input a trigonometric ratio. If the magnitude of the
ratio is greater than unity, and the desired function was either ArcSin or ArcCos, the program should
output the statement, “Magnitude must not be greater than unity.” and terminate. If the input
function type is not “as,” “ac,” or “at,” the program should print “Not an allowed function” and
print the angle as “NaN.” Otherwise, it should perform the conversion, and output the resulting
angle in degrees.
Sample session:
2. Combining Decibels:
Using good style, create a class called Decibels. In the main method, declare two component decibel
values, dB1 and dB1, both double variables. Also declare a combined decibel value, combinedDB.
Prompt for and input the two component decibel values. Then use the above formulas and Math’s pow
method and Math’s log10 method to compute the combined sound power level.
Sample session:
Enter first decibel level: 63
Enter second decibel level: 65
Combination decibel level = 67.1244260279434 dB
The program should permit the user to keep going or terminate after each calculation is made.
Project 3:
After obtaining net cash flow values, the next step in finding a project’s net present value is to
calculate the present value for each of its net cash flow values. The present value is today's
equivalent value of an amount of money at a particular time in the future. You may have heard of
the effect of compound interest. Compound interest converts a present value to a greater future
value. Finding present value is just going the other way – converting future dollars back to
equivalent present dollars. If that doesn’t make sense, that’s OK. Just use this formula to calculate
the present value for a net cash flow at year y in the future:
𝐶𝑦
𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑣𝑎𝑙𝑢𝑒𝑦 = 𝑦−𝑝𝑟𝑒𝑠𝑒𝑛𝑡 𝑦𝑒𝑎𝑟
(1 + 𝑟)
Where:
• Cy is the net cash flow at year y
• r is the discount rate, which is the estimated rate of return that could be earned on an
investment in the financial markets
• y – present year is the cash flow’s year minus the current year
Note: The above formula refers to the present value and the net cash flow value at a particular year
y. Present values and the net cash flow values are sometimes specified at non-yearly intervals, but
it’s common to simplify matters by sticking to yearly intervals and that’s what we do.
The final step in finding a project’s net present value is to sum all of the project’s present values.
To see if you now understand how to calculate a net present value, use the six net cash flow values
shown in the above example, use a discount rate of .06 (meaning that you anticipate a 6% annual
return if you invest money in the financial markets), and use a present year of 2010. You should
come up with a net present value of +53,511.27.
The program should permit the user to keep going or terminate after each calculation is made.
Project 4:
1. Stopping Distance:
If you follow too close behind another car and that other car stops suddenly, you will not be able
to stop in time, and you will crash into the rear of that other car. The following formula gives the
distance between you and the car in front which allows you to stop safely:
a) Write a program which determines whether a vehicle’s tailgating distance is safe. The program
should read in the speed of the vehicle and the vehicle’s tailgating distance. The program
should then calculate the distance that would be required to stop the vehicle.
If the stopping distance is less than the tailgating distance, your program should print “No
problem.” If the stopping distance equals the tailgating distance, your program should print
“Minor wreck.” If the stopping distance is greater than the tailgating distance, your program
should print “Major wreck!”
Sample session:
b) Notice that one of the tests is a comparison for equality. Since the probability of two real
numbers being exactly equal is zero, if you use floating point numbers there will never be an
input that produces a minor wreck. Modify the program so that it allows a range of uncertainty
entered by the user, within which the result will be a minor wreck.
c) Allow the user to enter the speed in kmph or mph and the distance in the corresponding unit
(m or feet).
2. Write a program to mimic a unit converter or currency converter (at least 3 different types):
For example:
• meter <-> feet • USD <-> AED
• km <-> mile • GBP <-> EURO
• cm <-> inch • EURO <-> USD
• kg <-> lb • AUD <-> AED
The program should permit the user to keep going or terminate after each calculation is made.
Project 5:
Column Safety:
In designing a building, you must determine whether each of the building’s support
columns is thick enough to support the column’s expected load. Assume the column is
wooden and has a solid square cross section. To be safe, all three of these conditions must
be met:
• The column should be sufficiently thick, that is:
height / width ≤ 50, where 50 is a special value called the slenderness limit,
• To prevent the column from buckling, make sure this requirement is met:
expected load ≤ (0.3*E*area) / (height/width)2,
where E = 1,700,000 psi is a special value called the modulus of elasticity.
• To prevent the column from compressing, make sure this requirement is met:
expected load ≤ area * stress,
where stress = 1450 psi = maximum allowable stress parallel to the grain.
In the above formulas,
height is the height of the column in inches,
width is the width of the beam in inches, and
area = cross-sectional area = width * width.
a) Evaluation:
Write a program that determines whether a wooden column with a given height is thick
enough to support a given expected load. More specifically, read in height, width, and
expected load values and then print “The column is safe.” or “The column is unsafe.”
Use named constants for slenderness limit, modulus of elasticity, and maximum stress.
In the sample sessions, note that the user enters height in units of feet, whereas the
formulas require height in units of inches.
Sample session:
Enter column width in inches: 4.0
Enter column height in feet: 15.0
Enter expected load in pounds: 5000.0
The column is unsafe.
Another sample session:
Enter column width in inches: 5
Enter column height in feet: 15
Enter expected load in pounds: 5000
The column is safe.
b) Design:
Create a separate program that enhances your original program. Your enhanced
program should calculate the minimum safe column width for a given height and
expected load. After inputting the height and expected load, your program must use a
loop to test and increment column width values until a satisfactory width is reached.
Consider only standard American widths. The smallest standard width is .625”. The
next standard widths are 1.625", 3.625", 5.625", 7.625”, and so on, with larger widths
at 2” intervals.
Background information: You should use the widths shown above for your program.
Those widths are actual widths. They correspond to the “nominal” widths of 1”, 2”, 4”,
6”, 8”, and so on. Nominal widths are what you ask for in a lumber store, and actual
widths are what you get. Nominal width values refer to the width of the rough-cut
boards, whose size is reduced due to drying and planning.
Sample session:
Enter column height in feet: 15.0
Enter expected load in pounds: 5000.0
Square column width = 5.625 inches
Project 6:
1. Economic Policy:
The following rules illustrate traditional economic policy theory in terms of regulating a
government’s economy.
a) If the annual growth rate is less than 1%:
• If inflation is less than 3%, recommended economic policy is:
Increase welfare spending, reduce personal taxes, and decrease discount rate.
• Otherwise, recommended economic policy is:
Reduce business taxes.
b) If the annual growth rate is greater than 4%:
• If inflation is less than 1%, recommended economic policy is:
Increase personal and business taxes, and decrease discount rate.
• If inflation is greater than 3%, recommended economic policy is:
Increase discount rate.
Write a program that applies these economic policy practices. More specifically, read in
growthRate and inflation values and output the recommended economic policy for the
given economic situation. If there is no recommended economic policy for the given
economic situation, then output “No change in economic policy.”
2. Bank Balance:
The First National Bank of Parkville recently opened up a new “So You Want to Be a
Millionaire” savings account. The new account works as follows:
• The bank doubles the customer’s balance every year until the customer’s balance reaches
one million.
• The customer isn’t allowed to touch the money (no deposits or withdrawals) until the
customer’s balance reaches one million.
• If the customer dies before becoming a millionaire, the bank keeps the customer’s balance.
• Note: Customers close to $1,000,000 tend to get “accidentally” run over in the bank’s
parking lot.
Write a program that prompts the user for a starting balance and then prints the number of
years it takes to reach $100,000 and also the number of years it takes to reach $1,000,000.
Sample session:
Write a program that plays the ancient Chinese game of NIM. Actually, this is a simplified
version of the game. Each game starts with a user-specified number of stones in a pile. The
user and the computer take turns removing either one or two stones from the pile. The player
who takes the last stone loses. Your program should have the computer use the optimal playing
strategy. The optimal strategy is as follows:
Divide the remaining number of stones by three. If the remainder is zero, then two stones are
removed, or else one stone is removed. For example, if the remaining number of stones is nine
or fifteen, then two stones are removed; if the remaining number of stones is eight or ten, then
one stone is removed.
a) Your program should allow the user to play additional games of NIM as long as he/she
enters a “y” or “yes” (lowercase or uppercase) in response to a “Do you want to play
again?” prompt. See the sample session for required wording.
Sample session:
T H E G A M E O F N I M
Sample session:
T H E G A M E O F N I M
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value
is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those
digits are summed and the process is repeated. This is continued as long as necessary to obtain a single
digit. For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6
is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the
9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yields
3, a single digit and also the digital root of 39.
Input File:
The input file will contain a list of positive integers, one per line. The end of the input will be indicated
by an integer value of zero.
Output File:
For each integer in the input, output its digital root on a separate line of the output.
Example Input:
24
39
34527689425676154283672531207341
0
Example Output:
6
3
3
Project 9:
Armstrong Numbers: The number 153 has the odd property that 13+53 + 33 = 1 + 125 + 27 = 153.
Namely, 153 is equal to the sum of the cubes of its own digits.
Perfect Numbers: A number is said to be perfect if it is the sum of its own divisors (excluding itself).
For example, 6 is perfect since 1, 2, and 3 divide evenly into 6 and 1+ 2 + 3 = 6.
Input File
The input is taken from a file named number.in and which a sequence of numbers, one perline,
terminated by a line containing the number 0.
Output File
A file number.out which contains all the the number read from the input file. These numbers are
printed one perline followed by a sentence indicating whether the number is or is not armstrong
number and whether it is nor not a perfect number.
Sample Input
153
6
0
Sample Output