-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathExercise 1.7 (Completed)
115 lines (115 loc) · 5.91 KB
/
Exercise 1.7 (Completed)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
1. (Practice) A C++ program is required that calculates the amount, in dollars, contained in a
piggybank. The bank contains half dollars, quarters, dimes, nickels, and pennies.
a. For this programming problem, how many outputs are required?
one output is required (amount)
b. How many inputs does this problem have?
10 inputs are required (half dollars, quarters, dimes, nickels, and pennies, number of each(5))
c. Write an algorithm for converting the input items into output items.
(half * halfNum)+(quart * quartNum)+(dim * dimNum)+(nick *nickNum)+(pen * penNum) = amount
d. Test the algorithm written for Exercise 1c using the following sample data: half dollars 0
quarters 17, dimes 24, nickels 16, and pennies 12.
(.50 * 0 )+(.25 * 17)+(.10 * 24)+(.05 * 16)+(.01* 12) = 7.57
2. (Practice) A C++ program is required to calculate the value of distance, in miles, given this
relationship:
distance = average - speed × time
a. For this programming problem, how many outputs are required?
one out is reqired (distance)
b. How many inputs does this problem have?
three inputs are required (average, speed and time)
c. Write an algorithm for converting the input items into output items.
rate x time = distance
d. Test the algorithm written for Exercise 2c using the following sample data: speed is 55 miles
sper hour and time is 2.5 hours.
(55 x 2.5) = distance
e. How must the algorithm you wrote in Exercise 2c be modified if the elapsed time is given
in minutes instead of hours?
average - speed x time(60) = distance
3. (Practice) A C++ program is required to determine the value of Ergies, given this relationship:
Ergies = Fergies × Lergies
a. For this programming problem, how many outputs are required?
one output is required.
b. How many inputs does this problem have?
itwo inputs are used.
c. Determine an algorithm for converting the input items into output items.
Fergies x Lergies = Ergies
d. Test the algorithm written for Exercise 3c using the following sample data: Fergies = 14.65
and Lergies = 4.
14.65 x 4 = 58.6
4. (Practice) A C++ program is required to display the following name and address:
Mr. S. Hazlet
63 Seminole Way
Dumont, NJ 07030
ha. For this programming problem, how many lines of output are required?
three lines of output are required
b. How many inputs does this problem have?
none
c. Write an algorithm for converting the input items into output items.
use the cout function.
5. (Practice) A C++ program is required to determine how far a car has traveled after 10 seconds,
assuming the car is initially traveling at 60 mph and the driver applies the brakes to decelerate
at a uniform rate of 12 miles/sec2. Use the following formula:
distance = st - (1/2)dt2
ts is the initial speed of the car.
d is the deceleration.
t is the elapsed time.
a. For this programming problem, how many outputs are required?
One output is required.
b. How many inputs does this problem have?
Three inputs are required.
c. Write an algorithm for converting the input items into output items.
(s)(t) - (1/2)(d)(t)2 = distance
d. Test the algorithm written for Exercise 5c by using the data given in the problem.
(60)(10) - (1/2)(12)(10)2 = 480
6. (Practice) In 1627, Manhattan Island was sold to Dutch settlers for approximately $24. If the
proceeds of that sale had been deposited in a Dutch bank paying 5% interest, compounded
annually, what would the principal balance be at the end of 2012? The following display is
required; xxxxxx is the amount calculated by the program:
Balance as of December 31,2012 is:xxxxxx
a. For this programming problem, how many outputs are required?
One output is required.
b. How many inputs does this problem have?
three inputs are required.
c. Is the algorithm for converting the input items into output items provided?
No, the algorithm would be C = P[(1+r)^n - 1]
7. (Practice) A C++ program is required that calculates and displays the weekly gross pay and
net pay of two employees. The first employee is paid an hourly rate of $16.43, and the second
is paid an hourly rate of $12.67. Both employees have 20% of their gross pay withheld for
income tax, and both pay 2% of their gross pay, before taxes, for medical benefits.
a. For this programming problem, how many outputs are required?
two ouputs are required
b. How many inputs does this problem have?
four inputs are required
c. Write an algorithm for converting the input items into output items.
gross pay = hours woked x rate
((hours worked x rate ) *.20)+((hours worked x rate) *.02) + gross pay = net pay
d. Test the algorithm written for Exercise 7c, using the following sample data: The first
employee works 40 hours during the week, and the second employee works 35 hours.
((40 * 16.43 )*.20)+(( 40 * 16.43)*.02)+(40*16.43) = 801.78
Second employee = 541.01
8. (Program) This is the formula for the standard normal deviate, z, used in statistical
applications:
z = (X - μ)/σ
X is a single value.
μ refers to a mean value.
σ refers to a standard deviation.
Using this formula, write a program that calculates and displays the value of the standard
normal deviate when X = 85.3, μ = 80, and σ = 4.
a. For this programming problem, how many outputs are required?
There is only one output that is required
b. How many inputs does this problem have?
There are three inputs to this problem
c. Write an algorithm for converting the input items into output items.
z = (single value - mean value)/ standard deviation
d. Test the algorithm written for Exercise 8c, using the data given in the problem.
(85.3-80)/4 = 1.325
9. (Practice) The equation describing exponential growth is as follows:
y = e^x
Using this equation, a C++ program is required to calculate the value of y.
a. For this programming problem, how many outputs are required?
One output is required
b. How many inputs does this problem have?
Two input is required
c. Write an algorithm for converting the input items into output items.
status = (exponential)^growth
d. Test the algorithm written for Exercise 9c, assuming e is 2.718 and x is 10.
2.718^10 = 22003.6396