Question 1  Edit and execute a simple C program
This question will help you get acquainted with the computing resources for this course.
- Login to one of the machines in the lab either locally or remotely over the internet.
- Create a directory called a1 for the files for this assignment.
- cd a1 to move into that directory.
- 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).
- Compile this program with the command gcc -o distance -lm distance.c. The "-lm" part tells the compiler to use the math library.
- Run this program by typing the command ./distance.
- If it works correctly, execute the following commands:
script q1.out pwd ls cat distance.c ./distance exit
- 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  Compute the volume of a sphere
Write a program to compute the volume of a sphere. (Recall that V = (4/3)pr3.)
- Your program will ask the user to input the radius.
- 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  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 submissionYou 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):
Then submit the file a1.tar.gztar cvf a1.tar q1.out volume.c q2.out intersection.c q3.out gzip a1.tar