Programming Projects for cs 230

Please construct, code, and debug the programs for the following projects. On each output for each run handed in, state NAME, DATE, and Program number. Your program should have comments documenting the code adequately (about one comment every three to five lines, except where more may be required.) Programs should operate with the prescribed algorithm or method described in the problem set below. Only hardcopy outputs from the computer will be accepted. Print BOTH source code and execution-screen (run-time image). Each project should be done individually- no joint projects.

Project 1: (Do both parts)

a)Determine and print the volume of a can of height 5 and radius 2. Use 3.1416 for Π.

b) Read 4 grades, compute and print their average and the difference between each of numbers and the average. For example if the input was 1,2,3,4 you would print “ the average is 2.5 and the differences are

-1.5 -.5 .5 1.5”. Try this with 66 90 88 79.

Project 2: Your ATM machines dispenses $50, $20, $10, $5 and $1 bills but jams if there are too many bills. To decrease the probability that bills get stuck you have been asked to write a C++ program which given any whole dollar amount(read in through CIN) prints the number of bills of each denomination which would yields the least total number of bills. Run your program with $198 as input. Hint: recall a similar problem in our first homework.

Project 3:

In high school you probably solved systems of equations of the form

Ax + By = E

Cx + Dy = F

by trying to find the easiest arithmetic. Computers don’t care about that but users are interested in accuracy and whether there is a solution or many solutions. Use the following pseudo code to determine the solution:

x = (ED-FB)/(AD-BC) and y =(AF-CE)/(AD-BC)

Use as sample data 1: 1x + 1y = 6

-0.5x - 1y = 1

Use as sample data 2: -.5x - 1y = 1

2x + 4y = 20

Use as sample data 3: 2x + 4y = 4

-0.5x - 1y = -1

Use as sample data 4: 1x10-20 x + 4y = 4

-0.5x - 1y = -1

You must read in A, B, C, D, E, F using cin.

Compute and print x and y using assignment statements & IFs.

Your IFs should catch any error cases ( 0/0 and number/0 ).

Print the source code and then print the run. Print an error message when division by zero is attempted (ie. 1/0 and 0/0 cases, which stand for parallel lines and the same line.)

______

Project 4: Choose either a or b:

(a)  Write a C++ program that reads in 20 SAT scores and prints all the scores, indicates the highest score, the second highest score and number of scores in each of the following categories:

1) scores>= 700

2) 600<=scores<700

3) 500<= scores<600

4) 400<=scores<500

5) 300<=scores<400

6) 200<=scores<300

Make up your own data.

(b)  for x =9,19,29,39,49,59,69, compute the square root of x without calling pow using the following bisection scheme:

Set y to x and z to 0.

Set u to 1.e-9

Until ||y –z|| <u*||y| do the following steps.

Set m to the average of y and z

if m*m-x <0 set z to m

else set y to m

For each x print out y, z, and the number of times you have gone through the loop.

______

Project 5:

Choose a or b

a. (1) make the algorithm in 4b into a function that returns the number of times you have gone through the loop and y and z.

(2)Also make the following algorithm into a function and compare the results:

Set y to x and z to 0.

Set u to 1.e-9

Until ||y –z|| >u*||y| do the following steps.

Set z to y

Set y to (y+x/y)/2

For the second method return only y and the number of times you have gone through the loop. In the main program call the two functions for x=9,19,29,39,49,59,69. Which algorithm is the most efficient?

b. Make a picture using Allegro and the Dev C++ compiler. See moving face on blackboard.

______

Project 6: Write a C++ program which computes all the prime numbers under 1000 and greater than 2 using the following sieve algorithm:

Set an array p to 0

For i=3 and running through all the odd numbers until 999

If p[i] is 0

Print that i is a prime

Set to 1 all elements of P whose index

is a multiple of i.

Hint: You will need a nested loop. The first time you will set p(3),p(6), p(9),,,p(999) to 1. Next times you will set p(5), p(10),p(15), p(20)..p(995) to 1. Cleverness counts. Extra Credit for eliminating unnecessary operations.