Homework #3

Due Wednesday Oct. 21, 1998 11:59pm

1) [30 points] You have just been hired by E*Trade, the leading provider of on-line trading on the Internet. Your first assignment is to write a stock analysis program which will enable customers to determine the current stock price of any company. For our purposes, however, you only have to worry about four publicly traded companies: Apple, IBM, Intel and Microsoft (see table below). Your program must provide the following functionality:

  • The user is prompted to enter a company ID number (1-4). Using the table below, display the current stock price of that company.

  • If the user enters a Company ID other than 1-4, you must display a Warning message, such as "Invalid Company ID. Please try again."

  • Each customer can check as many stocks as he/she wants. But, the user can always exit the program at any time by entering -1 for the company ID.

  • The first three stock quotes are free. But, after that, each additional stock quote costs $.25 (Note: If the user enters an Invalid Company ID, this does not cost anything. Make sure your program allows for this.) Keep a running tab of how many quotes the user has checked. If the user checks 3 or fewer, simply display the following line: "Thanks for using E-trade." Otherwise, display the final bill. The final bill should display the amount due in dollars and cents, for example, $1.50.

  • For this problem, one of the control structures you use should be a switch statement.

    Company IDCompanyStock Price


2) [30 points] Given r, the radius of a circle, the formula for the circumference of the circle is 2*PI*r. Write a function "circum", which takes a radius parameter, and returns the circumference. Once you have created your function, call the function within you main () function. For example:

printf ("Circumference:  %.2f", circum (2.5));
To help get you started, here is the function prototype for circum:
float circum (float);
Hint: To use PI, you must use the #define preprocessor instruction.

3) [20 points] Do problem 4.16, parts (a) and (b) on page 141 of the book. You must use for loops here.

4) [20 points] Do problem 4.24 on page 142 of the book. Recall that a TRUE condition results in a value of 1, and a FALSE condition results in a value of 0. So the output for each printf() will be either 1 (if the condition is true) or 0 (if the condition is false).

Note: in part d, there is a typo: where you see "< =", there should be no space; it should read "<=".