

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Introduction to Computer Programming; Subject: Computational Science; University: Syracuse University; Term: Fall 2007;
Typology: Assignments
1 / 3
This page cannot be seen from the preview
Don't miss anything!


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:
Part II:
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
? ??? ?????