2500 Spring 2011
* Make sure you have a computer account on the CS
* Check out the Department's e-mail program: https://cs.csustan.edu/WebMail/src/login.php.
Use your CS network login name and
* If you want your CS2500-related e-mail forwarded
to another system, follow directions here
for creating a .forward file.
Solve the following exercises using C++:
1. Write a program which reads a positive integer N and calculates the
sum of the first N odd integers. For example, if N is 4 then the
should produce the number 16 (1+3+5+7).
2. The German mathematician Leibniz discovered that the constant pi can
be computed using the following relationship:
pi/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 -
1/11 + .....
Write a program which computes an approximation of pi by summing
first N terms of the series (where N is a number read from the
keyboard). Thus if the input number N is 4, the program should
compute 1 - 1/3 + 1/5 - 1/7 (the first four terms of the series).
3. Greek mathematicians defined the concept of perfect numbers. A
number N is perfect if N is equal to the sum of all its proper divisors
(i.e. all divisors of N, except N itself). For example, 6 is a perfect
number since its proper divisors and 1, 2, and 3 and 1+2+3 = 6. On the
other hand, 8 is not a perfect number, since its proper divisors are
1, 2, and 4, but 1+2+4 = 7.
Write a function which takes a positive
integer and returns whether the
number is perfect. Then write a program
which will compute all perfect
numbers between 1 and 10,000, making use of the function.
4. Turn in your programs
and scripts to the CS Homework Submission System at https://hopper.csustan.edu/cshomework/
Choose instructor: cs2500mm
Choose course: CS2500
Choose assignment: Lab1
You will be
able to upload all six required files:
Turn in the source code for each of the three
programs. The names of the programs must be the ones given above. For
each program run a script showing that you were able to compile it and
showing your testing of the program. Instructions
on how to create a script.
Test values that are in range and
For choice: test at least one value in each branch.
For loops: test values at the beginning, middle, and end. Then test
Try to break your program and if you can document and fix.