CMPT 102   Lab 3

This lab is designed primarily to give you practice using format statements and if statements.  Instructions on how to complete the lab problem are followed by the statement of the lab problem to be solved.  An additional practice problem is also provided.

1.     Consider the lab problem below and develop an algorithm to solve it based on the information provided. Be sure to follow the first three steps in the software development process as you develop your algorithm.

THE SOFTWARE DEVELOPMENT PROCESS

a)     Specify the problem requirements

b)     Analyze the problem

c)     Design an algorithm to solve the problem and tests to demonstrate the algorithm is working correctly

d)     Implement the algorithm in a programming language

e)     Test and verify that the implemented algorithm (program) is working correctly

f)      Maintain and update the program

Write a summary of your algorithm development, showing each step in the process and making sure to include all of the items listed below. You algorithm development should be typed in a text or word processor file. You may add hand drawn diagrams or hand written equations to your printed solution. Your discussion of algorithm development should include each of the following:

a)     Statement of the problem

b)     A list of inputs, and a list of outputs along with a list of any mathematical  relations demonstrating the relations between the inputs and the outputs

c)     A series of hand examples, one for the common case and one for each of the special cases you identify

d)     An algorithm based on the hand example for the common case

e)     A refined algorithm to include your first special case

f)      A final refined algorithm containing all your special cases

g)     A test plan for testing the algorithm or the implemented program

2.     Make a directory to hold all your files for this lab

a)     Log in to a Linux machine (or a Cygwin window if you are working at home)

b)     Open a terminal window

c)     Make a directory for this weeks lab

d)     Move into that directory

3.     Write  the program to implement your algorithm.  You have two choices,

EITHER

a)     Start kate by typing   kate   followed by <enter>

b)     Enter some code

c)     Select ‘save as’ from the file menu and save your new code to file in ;your directory for this lab with filename integreSums.c

d)     Continue developing your code using kate, until you can save the final version of quadraticSolver.c and submit your solution.

OR

a)     Make. a copy of an existing program in your new directory (expansion c might be a good choice ). Rename the copy so it is  called  quadraticSolver.c

b)     Load the copy of the existing program into kate    (  kate quadraticSolver.c )

c)     Update the existing code so it is applicable to this problem.

d)     Debug your code and submit the resulting quadraticSolver.c file as your implemented solution.

e)     Remember that each time you make changes to your file you will need to save them (by selecting ‘save’ in the file menu) and reload the file before trying to compile or run the program.

f)      Remember the commands to compile and link your program

gcc      –Wall  –c       –o quadraticSolver.o quadraticSolver.c

gcc      ntegerSums.o             -lm      -o quadraticSolver.o

OR

gcc      -Wall               -lm      -o quadraticSolver     quadraticSolver.c

g)     Remember that the command to run your code is

./quadraticSolver.c

4.     When you have a completed executable file submit it to the submission server.  Remember you need to submit a zipped tar file.  To use tar and zip visit the instructions for using tar and zip.

5.     Print a copy of the C text file containing your program (quadraticSolver.c), a copy of the algorithm development for your program containing all the information requested above. and a copy of the lab exercise cover sheet from the class website.  Fill out and sign the cover sheet.  Be sure that all members in the group must sign the cover sheet.  Hand in the hard copy of your lab to the CMPT 102 drop box.  The hard copy of this lab problem includes a listing of your C text file, your algorithm development,  and a signed cover sheet.

 

LAB  PROBLEM:  Write a C program to find the real roots of the quadratic equation    coeffA*x*x + coeffB*x + coeffC  = 0.     A root of the equation is a value of the variable x that makes the equation true.  A quadratic equation can have up to two roots.  The roots will depend on the values of the three coefficients of the equitation (coeffA, coeffB, and coeffC). The C code to solve this problem should be stored in a file called quadraticSolver.c.

To refresh your memory one would use the quadratic equation, given below, to find the value of x, given the values of the coefficients.

.      

The following standard math library functions will be useful to you as you implement your algorithm        

double sqrt(double x);       This function takes the square root of a positive number. You cannot take the square root of a negative number, so you must structure your program to take a square root of a number only after you have checked that it is a positive number. 

     double fabs(double x);   This function calculates the absolute value of its argument.   

·      Your implemented program should comply with the following requirements:

Be sure to test your program extensively using the test plan you developed earlier

 

 

 

PRACTICE PROBLEM:

Enter your program into the source window, Your program should

a)      Prompt the user for, and read in a percentage grade between 0.0 and 100.0

b)      Calculate the corresponding letter grade according to the following scale

A  79.5<grade <=100.0

B   64.5<grade<=79.5

C   55.5<grade<=64.5

D   49.5<grade<=55.5

F   grade <=49.5

c)      When you run your program the output should look like

Enter the student’s percentage grade:

66.5

 

This student has a numerical grade of 66.5%

This student has earned a B

 

 

 

If you want more practice try some of the end of chapter problems in your textbook.