
CS 1713, Assignment 2, Thu Jan 15 1998, Page 1 of 2
CS 1713, Introduction to Computer Science
Assignment 2, Spring 1998
Modify the Copy Program
Due Thursday, January 29, 1998
The assignment: In this assignment you will modify the quadratic equations program of
Assignment 1. You will also practice creating a directory, copying and modifying a file, and
using a makefile.
Details:
1. First create a new directory named "assign2"to hold the new assignment, and switch to
that directory.
runner% mkdir assign2 (create a new directory)
runner% cd assign2 (change to the new directory)
The next time you login and want to work inside this directory, you don’t need to create it
again, but you will need to execute the "cd assign2" command.
2. Copy the old "roots.c" source file into the new directory, using a new name
"roots2.c":
runner% cd .. (change back to your home directory)
runner% cp roots.c assign2/roots2.c (copy the source)
runner% cd assign2 (change to the new directory)
Now once again you are in the assign2 directory and can work on the new source file
roots2.c (still the same as the old one). (We could have used the same name roots.c
for the new file, since it is in a different directory from the old, but it is probably less
confusing to use a new name.)
3. Make four changes to the program, using the vi editor to change the file roots2.c:
(a) Add an fprintf statement so that the first thing the program prints will be:
Assignment 2: Program written by <Your full name>.
Here <Your full name> should be your actual name.
(b) Have the program handle the case of a degenerate quadratic equation (in case a2 is 0) by
having it print an appropriate message followed by the one root, and then exit. You may
assume that a1 is not zero in this case.
(c) Have the program handle the case of a quadratic with a single repeated root (in case
discriminant is 0) by having it print an appropriate message followed by the one
repeated root, and then exit.
(d) Have the program handle complex roots by having it print two lines in the form:
Root1. Real part: <xxx>, imaginary part: <yyy>.
Root2. Real part: <xxx>, imaginary part: -<yyy>.
(Here <xxx> and <yyy> should be the actual real and imaginary parts. Let d be the
discriminant: d = a12 - 4 a0 a2. In case d < 0, that is, a complex root, then the roots have
real and imaginary parts given by
real part = (-a1)/(2 a2) , imaginary parts = ±√(−d)/(2 a2) )