CS
2500 Spring 2011
Lab 1
Getting Started
* Make sure you have a computer account on the CS
Department network.
* Check out the Department's e-mail program: https://cs.csustan.edu/WebMail/src/login.php.
Use your CS network login name and
password.
* If you want your CS2500-related e-mail forwarded
to another system, follow directions here
for creating a .forward file.
Programming Exercises
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
program
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
the
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:
sum_odd.cpp
script_sum_odd
pi.cpp
script_pi
perfect.cpp
script_perfect
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.
Testing guidelines:
Test values that are in range and
out-of-range.
For choice: test at least one value in each branch.
For loops: test values at the beginning, middle, and end. Then test
outside values.
Try to break your program and if you can document and fix.