UMBC CMSC201, Computer Science I, Spring 1994 Sections 0101, 0102 and Honors

Project 2

Due: March 10, 1994

Click here for the latest news and hints.

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 standard normal distribution function, also known as the bell curve. The mathematical formula for this curve is:

In C syntax, the right hand side of the equation is:

  0.39894228 * exp(-0.5 * x * x)
For the purposes of this program, the x-axis will run down the page and the y-axis will run across. For the basic assignment, write a program which plots an asterisk * for each point between the x-axis and the bell curve. Each line down the page of the plot should represent a distance of 0.1 along x-axis; and each space across the page of the plot should represent a distance of 0.01 along the y-axis. Plot the bell curve for x = -2.5 to x = 2.5. You may assume that the bell curve does not exceed 0.4 in this range. You should also print out the tick marks and labels for the x and y axes. (See the example below.) The basic assignment is worth 85% of the project grade. For the full assignment, your program should ask the user for several values relating to the plot. You should ask the user for the region of the graph to be plotted as well as the scale of the x and y axes. For example, in the second example below, the user asked for the graph to be plotted between x = 0.0 and x = 2.0. The x axis is scaled so that each line represents 0.1 and the y axis is scaled so that each space represents 0.008. Because of space limitations, you should plot only 50 spaces along the y-axis. For the full assignment, print out labels for every 10 spaces along the y-axis and every 5 lines along the x-axis.

Optional Embellishments:

Modify your program so that it prints out a warning symbol, >, in the right margin of each line where the 50 space limit truncates the bell curve. Then, if you are really ambitious, plot your graph so that it displays the curve in the customary orientation --- the x-axis horizontally and the y-axis vertically.

Warning:


Example 1:

Output from the basic assignment with the x and y-axes labelled.
          0  0.100000  0.200000  0.300000  0.400000  0.500000
          |_________|_________|_________|_________|_________|
      -2.5|*
          |**
          |**
          |***
          |****
        -2|*****
          |******
          |*******
          |*********
          |***********
      -1.5|************
          |**************
          |*****************
          |*******************
          |*********************
        -1|************************
          |**************************
          |****************************
          |*******************************
          |*********************************
      -0.5|***********************************
          |************************************
          |**************************************
          |***************************************
          |***************************************
 1.082e-15|***************************************
          |***************************************
          |***************************************
          |**************************************
          |************************************
       0.5|***********************************
          |*********************************
          |*******************************
          |****************************
          |**************************
         1|************************
          |*********************
          |*******************
          |*****************
          |**************
       1.5|************
          |***********
          |*********
          |*******
          |******
         2|*****
          |****
          |***
          |**
          |**
       2.5|*

Example 2:

Output from a sample run of the full assignment.
Low x value: 0.0
High x value: 2.0
x increment size: 0.1
y increment size: 0.008


          0  0.080000  0.160000  0.240000  0.320000  0.400000
          |_________|_________|_________|_________|_________|
         0|*************************************************
          |*************************************************
          |************************************************
          |***********************************************
          |**********************************************
       0.5|********************************************
          |*****************************************
          |***************************************
          |************************************
          |*********************************
         1|******************************
          |***************************
          |************************
          |*********************
          |******************
       1.5|****************
          |*************
          |***********
          |*********
          |********
         2|******

What to turn in:

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. Your session will be recorded in a file called typescript. Please use cat typescript to check that the file actually contains your output before you turn it in. If you completed only the basic assignment, then turn in your program and the output. If you completed the full assignment, then turn in your program and the output from the sample run which prints the bell curve from x = 1.0 to x = 3.0 with the x-axis scaled at 0.03 per line and the y-axis scaled at 0.004 per space. When you have made certain that the file typescript contains your output, send your project and output using the UNIX command:
% cat proj2.c typescript | mail chang@gl.umbc.edu
Please turn in only one copy of your project. If you finish early, check your answer and turn in the final copy.
Last Modified: June 10, 1994

Richard Chang, chang@gl.umbc.edu