DANVILLE
AREA
COMMUNITY COLLEGE
INTRODUCTION TO COMPUTER SCIENCE
MATH 110, Fall
2008
Homework 2 (Due
Sept. 4
in class)
Read: Section 2.3,
2.4, 2.5,
2.6, 2.7, 2.8, 2.9, 2.10, 2.11, 2.12, 2.13, 2.14, 2.15, 2.16, 2.17,
2.18,
2.19, 2.20, 2.21;
Pay special attention on 2.5, 2.6, 2.7, 2.11, 2.12, 2.13, 2.14, 2.15,
2.16,
2.17, 2.18, 2.19;
Understand the 12 examples in Chapter 2 by compiling and running them.
Solve the following Problems:
Problem
(2-45):
(p. 153);
Problem
(2-46):
(p. 153);
Problem
(2-54):
(p. 155). (will be continued on HW-3)
Hint: (you don't have to follow this
hint if you can solve these problems)
Exercise 2.45:
(1) Read Section 2.14 and 2.15.
(2) Run fig02_20.cpp on page 96. and try to
understand
this example completely.
(3) Modify fig02_20.cpp, and let it print
out the sum
of 1, 2, 3, 4, and 5. and then save this new version on disk.
(4) Study Problem 2.42 on page 153, and
then use a nested
for structure on your new version, let it print out:
table as
follows:
x,
sum,
5
sum of 1, 2, 3, 4, and 5.
4
sum of 1, 2, 3, 4.
3
sum of 1, 2, 3.
2
sum of 1, 2.
1
sum of 1.
(5) After you finish this, simply
change your sum
to production.
(6) The following is a
suggestion to calculat
the factorial of 10, (10*9*8*7*6*5*4*3*2*1):
for ( int j = 1; j <= 10; ++j )
factorial *= j;
cout << factorial;
Exercise 2.46:
(1) Read Section 2.14 and 2.15.
(2) Run fig02_21.cpp on page 98. and try to
understand
this example completely.
(3) Modify fig02_21.cpp, change rate from
0.05 to a integer
5,
(in
order to get the correct results, line 31 should change to "rate/100.0"
accordingly.
(4) Study Problem 2.42 on page 153, and
then use a nested
for structure on your new version, Your outer loop is
rate = 5;
rate <= 10; rate++ .
Exercise 2.54:
To learn a general procedure how to solve a
relatively
complicated problem,
here are some suggestions (you do NOT have to
follow).
(1) Write a simple program to calculate the
Pi (use for
structure), print the first 5 terms.
Then use a
calculator to check your results.
(2) Write a simple program to calculate the
Pi (use for
structure), print the first 10 terms.
Then use a
calculator to check your results.
(3) After you got a dependent program, then
try a few
large i. We will continue working on 2.54
in
HW-3 to
answer all the questions of 2.54.
(4) To get a positive and negative terms you
may try
this (there are many methods):
for(float
a=1; a<=999999;a+=2)
{p+=x*(4/a);
x*=-1; }
SAVE YOUR WORK ONTO TWO DIFFERENT DISKS.
The computer unit of DACC will "clean up"
all the
PC's in MMC-206 every week.
If you don't save your work to the disk, you
will lose
everything you did.
Exam-1 on Sept. 11 (covers Chapter 1 and
2).
Prepare your Exam-1 by doing:
(a) review problem input 4 different integers from the key board,
then, print out the largest one on the screen.
(b) review the problems on page 50 to 55.