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).
- Plot the function for amplitude = 1.0 and
frequency = 1.0.
- Allow the user to specify the value of amplitude.
- Allow the user to specify the value of frequency.
- 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.
- Allow the user to specify the range of x values to
plot, instead of 0 to 2 pi.
Implementation Notes:
- Please include your name in the comments at the top of the program
and specify which features you have implemented.
- To use the sin function, you have to add the following directive
to the beginning of your program:
#include <math.h>
- To determine the number of asterisks to plot, you should round
floating point numbers to the closest integer.
(So, -2.3 becomes -2 and 2.3 becomes 2.) To do this, you find the
absolute value of the number, add 0.5 and truncate the number.
For example, the absolute value of -2.3 is 2.3. Add 0.5 to 2.3,
it becomes 2.8, which becomes 2 after truncation. Note that if
you add 0.5 to -2.3, it becomes -1.8, which becomes -1 after truncation.
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
|
|****
|*********
|*************
|****************
|*******************
|*********************
|**********************
|**********************
|**********************
|*********************
|*******************
|****************
|*************
|*********
|****
|
****|
*********|
*************|
****************|
*******************|
*********************|
**********************|
**********************|
**********************|
*********************|
*******************|
****************|
*************|
*********|
****|
|
|****
|*********
|*************
|****************
|*******************
|*********************
|**********************
|**********************
|**********************
|*********************
|*******************
|****************
|*************
|*********
|****
|
****|
*********|
*************|
****************|
*******************|
*********************|
**********************|
**********************|
**********************|
*********************|
*******************|
****************|
*************|
*********|
****|
|