Separate Compilation Activity Notes

This document contains summary of the steps necessary to convert your single file quadratic equation solving program

into required separate compilation format for submission:

1. You should have a single file that contains the prototypes for the 4 subprograms, main program, and definitions

for the 4 subprograms. I would recommend creating a directory and placing a copy of this original program into

that directory so that all files will be grouped together:

a. Create a new directory: mkdir my_new_directory

This command will create a new directory called my_new_directory. You may name it anything you

want but remember to avoid spaces and it is case sensitive.

b. Copy current single file solution to the new directory: cp my_program.c my_new_directory

c. Change directories so you are in the directory you created with the copy of the original program where

you will do the remainder of the modifications: cd my_new_directory

Note: If you log off and return later, you will need to use this single command to move back into that

directory to continue working.

2. Use cut and paste to remove the prototypes from the original file and place into 4 separate header files

indicated below:

a. linear.h - prototype for solve_linear subprogram

b. quad.h - prototype for solve_quad subprogram

c. real.h – prototype for solve_real subprogram

d. complex.h - prototype for solve_complex subprogram

3. Use cut and paste to remove the definitions for the 4 subprograms from the original file and place into 4

separate files as indicated below:

a. linear.c - definition for solve_linear subprogram

b. quad.c - definition for solve_quad subprogram

c. real.c - definition for solve_real subprogram

d. complex.c - definition for solve_complex subprogram

4. Use Save As to save the remainder of the original program as a new file called main.c

Now we need to make a few modifications to these files to make them work together as a single program:

1. In each of the .c files, you will need to include the appropriate header files.

Note: Basic rule is you need to include header file that contains prototype for anything you call or define within

the current .c file

o main.c

 needs #include <stdio.h> since it uses printf/scanf statements

 needs #include “linear.h” and #include “quad.h” because it calls those two subprograms when

appropriate

 does not need math.h or either of the other two local .h files you created because it neither

defines nor calls them within this file

o quad.c

 needs to include both real.h and complex.h because it calls the subprograms for which those

contain the prototypes

 also needs to include quad.h because this file contains the definition of the solve_quad

subprogram and it’s prototype is located in quad.h

Note: If you call it or define It within the current file, you need to include the header file for it.

Repeat this process for the remaining .c files

2. In each of the header files (those that end with .h) you will need to add the following to surround the contents

of the header file:

#ifndef FILENAME_H

#define FILENAME_H

*** PROTOTYPE(S) AND/OR OTHER CONTENTS OF THIS FILE GOES HERE ***

#endif

Note: FILENAME_H can be any valid variable name but must be unique for each header file and is case-sensitive

and must match exactly on both lines. Good programming practice uses the actual file name in all capital letters

with an underscore where the “dot” is since only letters, digits and underscores are allowed and filenames are

unique. For example, LINEAR_H would be used for the file linear.h

3. Finally, we need to either copy the Makefile provided by the instructor or create our own in the same directory

that all of these program files are located. These instructions show how to copy and use the one provided:

a. Copy the Makefile from Ms. Tarver’s account: cp /home/faculty/mkt/Makefile .

Note: There is a PERIOD at the end of that command that indicates you want the file copied to the

current location in which you are working.

b. To compile your program, simply type the following command: make

Note: You will see commands that are compiling each file individually creating the object files and then a

command linking them together to create the executable… These are NOT error messages. An error

message regarding your program will appear as normal including the file name and line number in which

the error was found.

Computer Programming II Quadratic Equation Assignment

The purposes of this assignment include: passing of parameters, and command line parameters. You are to write a program to solve quadratic equations in all their possibilities (real or complex roots, or even degenerate equations). Your program should be invoked by the command:

solvequad a b c

where a, b, and c are coefficients. The solution should print on stdout. If the solution is complex, the output should consist of a pair of expressions such as “2 + 3i” and “2 – 3i”. Other cases will result in either two real numbers being printed, a single real number, or perhaps just a message. You must use separate compilation.

Get help from top-rated tutors in any subject.

Efficiently complete your homework and academic assignments by getting help from the experts at homeworkarchive.com