Assign7

advertisement
CSIS 10A
Assignment 7
Read: Hennefeld, Chapter 8
Select 10 Points from below
Name____________________________
Item
Exercises (for help check solns to blue exercises in Appendix J)
Ch 8 Exercises 2, 3a, 4a, 5a , 12b
Labs
L8- 2, 3
( 1 point each)
Ch 8 Programming Problems
Problem 16
over1000.cpp (see p177)
Problem 17
asterisk.cpp (see p190/191)
Problem 21
ulam.cpp (see p181)
Challenges
Problem 25
strontium90.cpp
Problem 30 – 33 (pick one)
Total Possible
10 points + 1 point extra credit
Points
4
2
2
2
2
4
11
11 max
PROGRAM TEST PLANS
Problem 16
over1000.cpp (see p177)
Test Case
Input Data
Problem 17
asterisk.cpp (see p190/191)
Test Case
Input Data
1
Problem 21
ulam.cpp (see p181)
Test Case
Input Data
1
Expected Result
See p199 and p177
Expected Result
See p190/191
Expected Result
See test plan on p200
HINTS
Problem 16
over1000.cpp (see p177)
set n = -1, sum=0
while the sum is less than or equal to 1000
add 2 to n
add n2 to sum
display "sum goes over 1000 when" n "is added, sum is" sum
Problem 17
asterisk.cpp (see p190/191)
YOU MUST USE A FUNCTION!
use a void function line( ) that displays char c, n times on one line, for example:
line('*', 5); // will draw a line of five *, *****
cout<<endl;
// goto new line
line('x', 7); // draws xxxxxxx
cout<<endl;
line(' ', 3);
// draws three spaces (used to indent)
line('^', 5); // draws 5 ^, ^^^^^
taken together, the above statements would produce the following drawing
*****
xxxxxxx
^^^^^
your line function will look like this:
void
line(char c, int n)
{// display (cout) char c in a for loop set to repeat n times,
}
then use this function in the main program, to display a line of spaces, then a line of stars:
Pseudocode for main function:
ask How many rows?
input num_rows
for loop where r goes from 1 to num_rows
draw a line of spaces ' ', length (num_rows-r) long …using your line function
draw a line of '*', length r long…using your line function
go to a new line
Download