UMBC CMSC201, Computer Science I, Fall 1994 Section 0101, 0102 and Honors

Project 2

Due: Wednesday, October 19, 1994


Objective:

The main objective of this assignment is to practice using control structures in C.

Assignment:

Write a program which plots the graph of the sine curve with two parameters, amplitude and frequency. Use the formula:
   y = amplitude * sin (frequency * x)
You will plot the graph so the x-axis runs down the page and the y-axis runs across the page (see example below). Plot the graph for x = 0 to x = 2 pi. Each line down the page will represent an increase of pi / 32 in the x-axis. Also, each space across the page will represent an increas of 1/30 in the y-axis. You will only be required to plot the graph for values of y from -1 to +1. Finally, print a vertical bar, |, (the pipe symbol) for the x-axis. Implement as many of the following features as you can (in order of increasing difficulty).
  1. Plot the function for amplitude = 1.0 and frequency = 1.0.
  2. Allow the user to specify the value of amplitude.
  3. Allow the user to specify the value of frequency.
  4. If the value of y exceeds 1 or falls below -1, make sure these points are not plotted and the | symbols for the x-axis line up.
  5. Allow the user to specify the range of x values to plot, instead of 0 to 2 pi.

Implementation Notes:


What to turn in:

Choose values for the amplitude and frequency that will demonstrate the features you have implemented. Then, use the script command to save a copy of your output. To do this, type script, run your program, and then type exit at the prompt. Repeat: you have to type exit when you are done running your program. Your session will be recorded in a file called typescript. Use an editor (e.g., emacs) to check that the file actually contains your output before you turn it in. Also, between trial runs of your program, you should remove the typescript file. When you have successfully created the typescript file, submit your program using the submit201 command that you copied for Project 1. To submit both your project and the typescript, use the following command (assuming your project is called project2.c):
      % submit201 project2.c typescript
Then, you can read your own mail to check that you have submitted the correct files.

Example:

Here's a sample run with features 1, 2 and 3 implemented.
Amplitude = 0.75
Frequency = 2.0
                              |
                              |****
                              |*********
                              |*************
                              |****************
                              |*******************
                              |*********************
                              |**********************
                              |**********************
                              |**********************
                              |*********************
                              |*******************
                              |****************
                              |*************
                              |*********
                              |****
                              |
                          ****|
                     *********|
                 *************|
              ****************|
           *******************|
         *********************|
        **********************|
        **********************|
        **********************|
         *********************|
           *******************|
              ****************|
                 *************|
                     *********|
                          ****|
                              |
                              |****
                              |*********
                              |*************
                              |****************
                              |*******************
                              |*********************
                              |**********************
                              |**********************
                              |**********************
                              |*********************
                              |*******************
                              |****************
                              |*************
                              |*********
                              |****
                              |
                          ****|
                     *********|
                 *************|
              ****************|
           *******************|
         *********************|
        **********************|
        **********************|
        **********************|
         *********************|
           *******************|
              ****************|
                 *************|
                     *********|
                          ****|
                              |