UMBC CS 201, Fall 07
UMBC CMSC 201
Fall '07

CSEE | 201 | 201 F'07 | lectures | news | help


CMSC201
Programming Project One

Exponents

Out: Wednesday 9/26/07
Due: Wednesday 10/3/07, Before Midnight

The Objective

The objective of this assignment is to get you started writing programs in C in the UNIX environment. Its main emphasis is design, so we will be designing the project together in class. This project will also give you practice writing functions, loops, switch statements and using separate compilation.

The Background

Although the square and cube of a number are very easy to calculate, finding the square root of a number, or actually the approximation of the squareroot, can be quite time consuming, especially if done by hand. Using a computer, we can calculate square roots by using a successive approximation algorithm. There are many such algorithms, but the one you will be using for this project is shown below:

The square root of a number n can be approximated by repeated calculation using the formula

nextGuess = 0.5 * (lastGuess + n / lastGuess)

where an initial guess of 1.0 will be the starting value of lastGuess. A value for nextGuess should then be computed using the formula given above. The difference between nextGuess and lastGuess should then be checked to see if those two values are almost identical. If they are, nextGuess is accepted as the square root of the number; otherwise, the value of nextGuess becomes the new value of lastGuess and the process is repeated (another value is computed for nextGuess, the difference checked, and so on). The loop should be repeated until the difference is less than 0.005

The Task

You are to write a program that calculates the square of a number, its cube, and also its square root. Each of these tasks should be performed in separate functions. The square root function that you write will return an approximation of the square root of the number. You will also get the precise square root of the number by using the sqrt() function found in the math library. When finding the difference, you should report the absolute value of the difference between your approximate square root and the square root found by the function in the math library. When displaying the difference, you MUST print it using exponential notation. Often the difference is so small that using %f would just display 0.000000, but the two roots are not really the same.

After printing the program explanation and getting a positive real number from the user, you will display a menu that will allow the user to choose which operations to do. The choices include :

You will be expected to write eight functions, other than main, for this project.

Here are the function prototypes :

You MUST use these function prototypes, as shown, without modification.

Function Descriptions:

Sample Run

Since the output is long, here is a link to a separate webpage containing the sample run.

More Details

Compiling the Pieces & Linking

Submitting the Program

To submit the files you should use the command:

submit cs201 Proj1 proj1.c exponents.c exponents.h

You can check your submission by using the command:

submitls cs201 Proj1


CSEE | 201 | 201 F'07 | lectures | news | help

Wednesday, 26-Sep-2007 08:31:00 EDT