CSCI-14 Assignment #5, simple looping (40 points) due 3/8/16

advertisement
CSCI-14 Assignment #5, simple looping (40 points) due 3/8/16
These are adapted from the text, pages 293-294.
1. (Adapted from number 2, pg. 293). Write a C++ program that prints a table of the
characters for the ASCII codes from ' ' (space) to '~' (tilde). Print the characters
16 to a line separated by spaces. The problem in the book says to loop from 32 to
127. Do not do this. Instead, use the ASCII characters not the numeric codes (e.g.,
space ' ' is 32, '~' is 126) to control the loop. Do not print a trailing space on any
line (except perhaps a space after '~' if you can't figure out how to not print it).
This is ONLY ONE loop! You will need to track how many symbols you have
printed on a line to determine if you need to print a space or a newline after each
ASCII character you print. This illustrates the “fence-post” problem. (20 points)
The table should look something like this:
0
@
P
`
p
!
1
A
Q
a
q
"
2
B
R
b
r
#
3
C
S
c
s
$
4
D
T
d
t
%
5
E
U
e
u
&
6
F
V
f
v
'
7
G
W
g
w
(
8
H
X
h
x
)
9
I
Y
i
y
*
:
J
Z
j
z
+
;
K
[
k
{
,
<
L
\
l
|
=
M
]
m
}
.
>
N
^
n
~
/
?
O
_
o
2. Do number 7, Pennies for Pay, from pg. 294. Test with several numbers of days.
Work out at how many days the program stops working correctly with an int for the
number of pennies, and include tests for that value and for a larger value. Your
variable to hold the daily pennies must be an int. The only floating-point variable
for this is for the total pay. (20 points)
A test run would look something like this for 8 days:
How many days? 8
Pay for day 1 = 1
Pay for day 2 = 2
Pay for day 3 = 4
Pay for day 4 = 8
Pay for day 5 = 16
Pay for day 6 = 32
Pay for day 7 = 64
Pay for day 8 = 128
Total pay is $2.55
Download