Computer Science 1621
Computer Science I

Programming Assignment 1
Creating a Program (15 points)
Due Tuesday, September 15, 1998

Introduction

In this assignment you will repeat the process from Lab 1 for the program shown at the end of this handout. You should create a project, a source file, compile the source file, debug your program and then run the program multiple times.

The Program

The program below prints the function f(x) = A * x * x + B * x + C where you enter values for A, B, and C. Once you have typed the program, compile it and then run it. Follow the instructions and type 3, 1, and 5 for the values of A, B, and C and then -3 and 3 as the starting and ending points for X. If your program runs correct you should see the following (what you type shown in italics


Enter coefficients A, B, and C: 3 1 5
What X value should I start at? -3
What X value should I end at?   3

 -------------------------------------------------------------
|                                                    X
|                                              X
|                                         X
|                                    X
|                                X
|                            X
|                        X
|                    X
|                 X
|              X
|           X
|        X
|      X
|    X
|   X
| X
|X
|X
|X
|X
|X
|X
|X
|  X
|   X
|     X
|       X
|         X
|           X
|              X
|                 X
|                     X
|                        X
|                             X
|                                 X
|                                      X
|                                          X
|                                                X
|                                                     X
|                                                           X



If the output from the program looks correct, try other values for A, B, and C and for the starting and ending X values. Try to find values that produce three significantly different shaped curves.

What To Hand In

Hand in the following items:

Program Soucre Code

/*
Your Name 
CS 1621  Section ?  
Today's date 
Program #1 
*/

#include <stdio.h>

#define numXpoints 40
#define numYpoints 60

void main(){
  float A;
  float B;
  float C;
  float startX;
  float endX;
  float minY;
  float maxY;
  float X;
  float Y;
  int i;
  int j;
  int indent;

  printf("Enter coefficients A, B, and C: ");
  scanf("%f %f %f",&A,&B,&C);

  printf("What X value should I start at? ");
  scanf("%f",&startX);
  printf("What X value should I end at?   ");
  scanf("%f",&endX);

  minY = startX * startX * A + startX * B + C;
  maxY = minY;
  for (i = 1; i < numXpoints; i++) {
    X = startX + (i * (endX - startX) / numXpoints);
    Y = X * X * A + X * B + C;
    if (Y < minY)
      minY = Y;
    if (Y > maxY)
      maxY = Y;
  }

  if (minY == maxY){ 
      minY--;
      maxY++;
  }

  printf(" ");
  for (i= 0; i<= numYpoints; i++)
    printf("-");
  printf("\n");

  for (i= 0; i < numXpoints;i++){
    X = startX + (i * (endX - startX) / numXpoints);
    Y = X * X * A + X * B + C;
    indent = (((Y - minY) / (maxY - minY)) * numYpoints - 0.5);

    printf("|");
    for (j=1; j <= indent; j++)
      printf(" ");
    printf("X\n");
  }
}