Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

CSBP112: Introduction to Programming

PROJECT

Proposal Project: Pick 1 from list Project Due Date: Wk 16

This a programming project to solve a problem from real life.


1. Make a team of 2 students, only max 2 students are allowed in a group.
2. Form a group and choose one of the projects listed in this document no later than the
above proposal date.
3. You can also propose your own project but you have to get my approval first. Submit
online in Blackboard.
4. For final project submission, each group should submit both soft and hard copy of your
code before the above project due date. NO LATE SUBMISSION WILL BE
ACCEPTED WITHOUT VALID REASONS.
5. Each project is considered as a single C++ program, even with multiple parts. So project
with multiple parts will be a multi-functions (selection) program.
6. Your code should be very well documented (with lot of // everywhere).

STUDENT CODE OF CONDUCT


The Student Code of Conduct establishes standards of expected behavior for students and
student organizations at the University, and puts in place fair and efficient procedures for
protecting student rights and handling student misconduct, for details, refer to:
http://www.uaeu.ac.ae/en/about/policies/student_affairs_deanship/pol_pro-sa_02_en.pdf

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:

Write a program that 1) calculates perimeter/circumference and area for specific


geometric plane figures and 2) calculates the volume and surface area of specific
geometric solids. The program should take input from the keyboard and keep track of the
units of measurement. It should also have a function for each figure. Answers should be to
nearest 100th of a unit (2 decimal places). The figures and shapes are listed below:

Triangular Shapes (OUTPUT Perimeter and Area or surface area and volume as
appropriate.)

1. Triangles (INPUT sides, not base and height):


o Scalene
o Isosceles
o Equilateral
o Right Triangle (know a, b)
o Right Triangle (know a, c)
2. Triangular Right Prism (INPUT sides of base and height of prism)
3. Triangular Pyramid (INPUT sides of base and height of pyramid)

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:

Select ArcSin(as), ArcCos(ac), or ArcTan(at): at


Enter a trigonometric ratio: 50
angle in degrees = 88.8542371618249

2. Combining Decibels:

Sound power level is expressed in decibels. A decibel is 10 x log10(picoWatts), where a picoWatt


is 10-12 Watts. To determine the acoustical power level produced by the combination of two sound
sources, we do the following:
1. Convert each decibel level into picoWatts, using the formula, picoWatts = 10(decibels / 10)
2. Add the picoWatt powers.
3. Convert the sum back into 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:

1. Net Present Value Calculation:


Implement a program that calculates the net present value.
Before undertaking an expensive project, it is common for business financial analysts to calculate
the net present value for the proposed project. The net present value tells the business financial
analyst whether it would be wise to go forward with the project or not. A positive net present value
says to go forward. A negative net present value says that the business would make more money by
not going forward, and, instead, investing the proposed project’s expenses in the financial markets.
To calculate a project’s net present value, you first need to obtain the project’s estimated net cash
flow values. Net cash flow is the project’s income or loss at a particular time t. Here is an example,
which shows 6 estimated net cash flow values for the life of a proposed project:

Year 2012 = -$100,000 initial investment (cash outflow)


Year 2013 = +$40,000 income (cash inflow)
Year 2014 = +$40,000 income (cash inflow)
Year 2015 = +$40,000 income (cash inflow)
Year 2016 = +$20,000 income (cash inflow)
Year 2017 = +$50,000 sale of remaining assets (cash inflow)

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.

Another sample session:


Enter present year: 2010
Enter discount rate as a fraction: .06
Enter year of net cash flow: 2012
Enter net cash flow: -100000
Any more cash flows (y/n)? y
Enter year of net cash flow: 2013
Enter net cash flow: 40000
Any more cash flows (y/n)? y
Enter year of net cash flow: 2014
Enter net cash flow: 40000
Any more cash flows (y/n)? y
Enter year of net cash flow: 2015
Enter net cash flow: 40000
Any more cash flows (y/n)? y
Enter year of net cash flow: 2016
Enter net cash flow: 20000
Any more cash flows (y/n)? y
Enter year of net cash flow: 2017
Enter net cash flow: 50000
Any more cash flows (y/n)? n
Net present value = +53,511.27

2. Write a program to mimic a simple calculator

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:

stoppingDistance = speed * (2.25 + speed / 21)

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:

Enter your speed (in mph): 60.0


Enter your tailgate distance (in feet): 240.0
Major wreck!

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:

Enter starting balance: 10000


It takes 4 years to reach $100,000.
It takes 7 years to reach $1,000,000.
Project 7:
Game of NIM:

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

Enter number of starting stones: 7


Would you like to go first? (y/n): yes
How many would you like to remove: 1 or 2? 1
The number of stones left is 6.
The computer removes 2 stones.
The number of stones left is 4.
How many would you like to remove: 1 or 2? 2
The number of stones left is 2.
The computer removes 1 stone.
The number of stones left is 1.
How many would you like to remove: 1 or 2? 1
The number of stones left is 0.
The computer wins!
Do you want to play again? (y/n): Y

Enter the number of starting stones: 4


Would you like to go first? (y/n): n
The computer removes 1 stone.
The number of stones left is 3.
How many would you like to remove: 1 or 2? 2
The number of stones left is 1.
The computer removes 1 stone.
The number of stones left is 0.
You win!
Do you want to play again? (y/n): n
b) Final improvement for submission:
Add input validation to your Nim program. More specifically, (1) ask the user to re-enter the
number of starting stones if he/she doesn’t enter a positive number, and (2) ask the user to
re-enter the number of stones to be removed if he/she doesn’t enter an appropriate
number.

Sample session:

T H E G A M E O F N I M

Enter the number of starting stones: 7


Would you like to go first? (y/n): Y
How many would you like to remove: 1 or 2? 1
The number of stones left is 6.
The computer removes 2 stones.
The number of stones left is 4.
How many would you like to remove:1 or 2? 2
The number of stones left is 2.
The computer removes 1 stone.
The number of stones left is 1.
How many would you like to remove: 1 or 2? 2
You cannot remove 2 stones.
How many would you like to remove: 1 or 2? 1
The number of stones left is 0.
The computer wins!
Do you want to play again? (y/n): Y

Enter the number of starting stones: 0


You cannot start with 0 stones.
Enter the number of starting stones: 4
Would you like to go first? (y/n): n
The computer removes 1 stone.
The number of stones left is 3.
How many would you like to remove: 1 or 2? 0
You cannot remove 0 stones.
How many would you like to remove: 1 or 2? 3
You cannot remove 3 stones.
How many would you like to remove: 1 or 2? 2
The number of stones left is 1.
The computer removes 1 stone.
The number of stones left is 0.
You win!
Do you want to play again? (y/n): n
Project 8:

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:

More than 2500 years ago, mathematicians got interested in numbers.

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

153 is an Armstrong number but it is not a perfect number.

6 is not an Armstrong number but it is a perfect number.

You might also like