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.)


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.


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!