Computer Programming - Assignment 3 Sample Questions | CPS 196, Assignments of Computer Science

Material Type: Assignment; Class: Introduction to Computer Programming; Subject: Computational Science; University: Syracuse University; Term: Fall 2007;

Typology: Assignments

Pre 2010

Uploaded on 08/09/2009

koofers-user-e0p-1
koofers-user-e0p-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPS 196
Homework Assignment 3 Due Thursday, November 1, 2007, at 10pm. (avoiding late
nights on Halloween).
While you may discuss this assignment with others, all work you submit must be your
own. That means, after discussing it, you must go back and write it up yourself.
Software Development Process:
Part I:
1. Specify the problem requirements:
State the problem.
2. Analyze the problem:
List the inputs, determine their data types and pick variable names for them.
List the outputs, determine their data types and pick variable names for them.
Work out one example in detail. Show the step by step calculations. If you need
any additional variables, identify their type and name them.
3. Design the algorithm to solve the problem.
List the steps for each function and for main in plain English. These steps should
also be given as comments in the program.
Part II:
4. Write a C program, using the analysis above:
Write a comment block that has the program name, your name and date.
The program should be well documented and have good variable names.
Include the function prototypes as listed in the problem statement and use them
for the function definitions.
Use proper programming style with reasonable indentation.
Test your program thoroughly using the test values from part 3 and check your
results.
Follow the above steps to write C programs for two problems:
Program 1
For this problem, you will write a function to find the length of a vector, assumed to go
from the origin to a point value with x and y components.
double findlength(double x, double y)
The findlength function takes in the x and y components of a vector from main and
computes the length (the square root of the sum of x-squared and y-squared) and returns
the answer to main. It does not take any input from the keyboard nor produce any output
to the screen. To write findlength, you may use the sqrt function that is included in the
library math.h.
pf3

Partial preview of the text

Download Computer Programming - Assignment 3 Sample Questions | CPS 196 and more Assignments Computer Science in PDF only on Docsity!

CPS 196

Homework Assignment 3 Due Thursday, November 1, 2007, at 10pm. (avoiding late nights on Halloween).

While you may discuss this assignment with others, all work you submit must be your own. That means, after discussing it, you must go back and write it up yourself.

Software Development Process:

Part I:

  1. Specify the problem requirements: State the problem.
  2. Analyze the problem: List the inputs, determine their data types and pick variable names for them. List the outputs, determine their data types and pick variable names for them. Work out one example in detail. Show the step by step calculations. If you need any additional variables, identify their type and name them.
  3. Design the algorithm to solve the problem. List the steps for each function and for main in plain English. These steps should also be given as comments in the program.

Part II:

  1. Write a C program, using the analysis above: Write a comment block that has the program name, your name and date. The program should be well documented and have good variable names. Include the function prototypes as listed in the problem statement and use them for the function definitions. Use proper programming style with reasonable indentation. Test your program thoroughly using the test values from part 3 and check your results.

Follow the above steps to write C programs for two problems:

Program 1

For this problem, you will write a function to find the length of a vector, assumed to go from the origin to a point value with x and y components.

double findlength(double x, double y)

The findlength function takes in the x and y components of a vector from main and computes the length (the square root of the sum of x-squared and y-squared) and returns the answer to main. It does not take any input from the keyboard nor produce any output to the screen. To write findlength, you may use the sqrt function that is included in the library math.h.

The main should ask for the components of the vector. It should then call the appropriate functions and finally print the length and direction, both to two decimal places.

Sample screen:

Please enter the x and y components of the vector, separated by a space: 3.0 3. The vector ( 3.00, 3.00 ) has length 4.

Program 2

You are going to write a program with two functions.

The function

char getsymbol(void)

asks the user what symbol they would like to use for drawing a triangle. The function reads the user's answer and passes back the character to main.

The function

void drawtriangle(char symbol)

draws a triangle using the character obtained by getsymbol.

Your main should first draw three triangles with three different symbols (using drawtriangle ), then call getsymbol to ask the user for their choice of symbol, and finally, draw a triangle with that symbol.

Sample screen:

Welcome to triangle maker. I can draw triangles! x xxx xxxxx

7 777 77777

? ??? ?????