# CMPT 102 - Assignment 1

Out: Friday, Sept. 16, 2005
Due: Friday, Sept. 30, 2005 at 5:00pm
Weight: 10%
Total: 100 marks

## Question 1 [15] Edit and execute a simple C program

This question will help you get acquainted with the computing resources for this course.

1. Login to one of the machines in the lab either locally or remotely over the internet.
2. Create a directory called a1 for the files for this assignment.
3. cd a1 to move into that directory.
4. Create a file called distance.c which modifies the program on Page 21 of the textbook to compute the distance between the two points (-4.2, 1.3) and (7.5, 6.4).
5. Compile this program with the command gcc -o distance -lm distance.c. The "-lm" part tells the compiler to use the math library.
6. Run this program by typing the command ./distance.
7. If it works correctly, execute the following commands:
```script q1.out
pwd
ls
cat distance.c
./distance
exit
```
(The script command copies all of the output that you see into a file that can be submitted. Don't forget to exit.)
8. Have a look at your q1.out file to make sure that you actually have the right information in it. Type the command more q1.out. You should see a transcript of the commands you just typed.

## Question 2 [25] Compute the volume of a sphere

Write a program to compute the volume of a sphere. (Recall that V = (4/3)pr3.)

• Your program should define a symbolic constant as follows:
#define PI 3.141593
• Save your program in a file called volume.c.
• Test your program with three different values for the radius and save the transcript of your tests in a file called q2.out. You should use the script command
• from Question 1.

## Question 3 [60] Compute the intersection of two lines

Consider the problem of computing the intersection of two lines on a plane, where each line is given by a pair of distinct points on the plane. Solve this problem by following the engineering problem-solving methodology in the textbook.

• Your program will ask the user to input the two lines.
• You program should consider all possible cases. For example, the two lines might be identical, or they might be parallel.
• You can choose to draw an input/output diagram or describe the input/output information in words.
• You can work out as many hand examples as you want, but you only need to submit one hand example such that the two lines intersect at a unique point and neither of the two lines is perpendicular to the x axis.
• Describe your algorithm in the form of decomposition outline as shown on Page 21 of the textbook.
• Save your program in a file called intersection.c
• You should develop a test plan which covers all possible cases. For each case, you should describe it with a sentence and present a sample set of data.
• Test your program with these sets of data and save the transcript of the tests in a file called q3.out.

## How to submit

### Electronic submission

You should submit the files q1.out, volume.c, q2.out, intersection.c, and q3.out. The submission server allows you to submit one zipped file per assignment. You need to combine the files into one file, zip the resulting file, then submit it. You can do this by typing these commands (cd a1 if you haven't already):
```tar cvf a1.tar q1.out volume.c q2.out intersection.c q3.out
gzip a1.tar
```
Then submit the file a1.tar.gz

### Hard-copy submission

First, you should submit the printout of the files you submit electronically. Second, you should submit your solution to Question 3. You can either hand-write it or type it using a text editor or word processor. Finally, don't forget the cover page!