Project 3: CISC181h, Spring 2004

Required Reading/Concepts:

Reminders:

Assignment Description

This assignment involves developing a class to work with Polynomials, and demonstrating that the class works. You will develop the class in seven steps. In each case, the main program and the Polynomial.h file are provided for you. You are also provided with an outline of the Polynomial.cpp file; it is your job to fill in the missing code.

At each step, you will compile by typing "make". A Makefile is given for you in steps 1-4. In steps 5 and 6, you are given only an outline of the Makefile, and you have to extend it yourself (based on observing the differences in the Makefiles in steps 1 through 4, and the instructions inside the Makefile at steps 5 and 6.)

Steps 1-6 should be done in order. However, step 7 can be done anytime after you do step 1, as explained further below.

The files for this project are located in:

~pconrad/public_html/cisc181h/04S/proj/proj3 which can be found on the following web link:

http://copland.udel.edu/~pconrad/cisc181h/04S/proj/proj3

This directory contains a separate subdirectory for steps 1-6 of the project. step 7 can be done any time after step 1, and does not depend on steps 2 through 6.

At each stage, you should have a working complete project that you could script and turn in for partial credit. However, in the end you should only turn in one set of files: your Polynomial.cpp file, your Makefile, and a script file where you cat your Polynomial.cpp file and your Makefile, and then demonstrate compiling and running your main programs.

Some important differences between this and previous projects:

The following table shows an overview of the steps in this project. Each step is described in further detail below.

Step
Purpose
Partial Credit you get for completing up through this step

Your script should show runs of these main programs

Step 1 simple constructors, print functions 35% main1
Step 2 overloaded << operator 40% main1, main2
Step 3 additional constructor that takes an integer parameter (degree) and the setDegree member function 45% main1, main2, main3
Step 4 copy constructor and overloaded = operator 50% main1 through main4
Step 5 addToCoeff member function, and overloaded + operator 60%

main1 through main5

Step 6 overloaded * and - operators 75% main1 through main6
Step 7

enhancements to the print function (print function is included in step 1, so these enhancements can be made anytime after step 1 is complete)

add 25% to total from last step completed (included in other steps)

If you complete, for example, steps 1 through 5, and then do step 7, you can receive a maximum grade of 85%. Of that 85%, 70% of that 85% will be for correctness, and the other 30% of the 85% will be for style. Some sample deductions:

5 - 10% off for lack of comments (other than ones that were in the original source files)
5 - 10% off for bad indentation and formatting of code
5 - 10% off for other miscellaneous style issues
5 - 40% off if the code doesn't work properly
5 - 30% off if instructions for submission are not followed
(e.g. Makefile not used to compile is 20% off,
Makefile not submitted on WebCT is 10% off,
Polynomial.cpp not submitted 10% off)

Steps 1 through 6: Implementing member functions

In steps 1 thorugh 6, you are implementing member functions of the Polynomial class. At each step, you will start with the code in the directory for that step. I recommend that you make a separate proj3 subdirectory, and under that subdirectory, make separate subdirectories step 1, step2, step3, etc.

You will use the Makefile given (except in steps 5 and 6, where you must build your own Makefile based on the one from the previous step.)

In step 1, you start with the Polynomial.cpp and Polynomial.h files given, then add some code to the Polynomial.cpp in the places indicated in the file by @@@. Then, compile with "make", and test by running the program "main1". Your output should look like the following; this is what will be in your script file (in addition to doing a "cat" of your Polynomial.cpp file and your Makefile):

> make clean
/bin/rm -f main1
/bin/rm -f *.o
/bin/rm -f core 
> make
g++ -c main1.cpp 
g++ -c Polynomial.cpp
g++ main1.o Polynomial.o -o main1
> ./main1
p1= 0
p2= 1
p3= 2x + -3
p4= 1x^2 + -5x + 6
> 

When you are finished with step 1, you can proceed to Step 2. You will copy the files from my step2 subdirectory in your step2 directory. Then, use vi or emacs to edit the file Polynomial.cpp from the step2 subdirectory. You will see, early in the file, the comment:

// @@@ COPY IN YOUR CODE FROM Polynomial.cpp for step 1 here
 

This indicates that you should use an editor feature that copies a file into your current buffer. For example, to insert the contents of the file "../step1/Polynomial.cpp" into the current buffer at the place where the cursor is located,

Once you have pulled the Polynomial.cpp from the previous step into your buffer, you can proceed with adding the code for the additional functions. Look for @@@ for places where you need to add something to the code. You should remove all the @@@ comments before submitting your work, and replace them with comments in your own words.

When you are done with step 2, you should be able to script it as follows. Note that at step 2, you should run both main1 and main2. This applies to each successive step; you should run all of the main programs at each step.

> make clean
/bin/rm -f main1 main2
/bin/rm -f *.o
/bin/rm -f core 
> make
g++ -c main1.cpp 
g++ -c Polynomial.cpp
g++ main1.o Polynomial.o -o main1
g++ -c main2.cpp 
g++ main2.o Polynomial.o -o main2
> ./main1
p1= 0
p2= 1
p3= 2x + -3
p4= 1x^2 + -5x + 6
> ./main2
p1= 0
p2= 1
p3= 2x + -3
p4= 1x^2 + -5x + 6
> 
 

Any time after you complete step 1, you can skip ahead to step 7, and do that step out of order if you like. step 7 involves some enhancements to the print() member function of the Polynomial class. Since you have a basic version of that member function completed in step 1, you can do this step at anytime after step 1. Or, you can save it for last: your choice.

step 7 simply involves rewriting the code for the print() member function (I provide a basic version of print for you, but it does not produce very "nice" output.) In the section of this assignment web page labelled "step 7: Nicer Output", I have listed some rules for you to explain how you are to modify the print() member function. Suppose, for example, you complete step 7 after steps 1 and 2. In that case, the output would look like the following:

> make clean
/bin/rm -f main1 main2
/bin/rm -f *.o
/bin/rm -f core 
> make
g++ -c main1.cpp 
g++ -c Polynomial.cpp
g++ main1.o Polynomial.o -o main1
g++ -c main2.cpp 
g++ main2.o Polynomial.o -o main2
> ./main1
p1= 0
p2= 1
p3= 2x - 3
p4= x^2 - 5x + 6
> ./main2
p1= 0
p2= 1
p3= 2x - 3
p4= x^2 - 5x + 6
> 
 Notice that the output looks a little nicer: instead of 2x + -3, we have 2x - 3, and instead of 1x^2, we simply have x^2.

In any case, whether you do step 7 now, or later, proceed through steps 1 through 6 in the same fashion described above;adding code in the places indicated. In some steps, there is less to do; for example, at step 4, most of the work is already done for you. At other steps, you have more work to do.

step 7: Nicer output

In this step, you modify the print() member function to produce nicer output. Here are the rules

Rule What we want What we don't want
(1) Don't print terms with zero as the coefficient 2x^2 + 7 2x^2 + 0x + 7
(2) Don't print 1 as a coefficient, except for the [0] term 2x^2 + x + 1 2x^2 + 1x + 1

(3) Make sure that only one sign appears between terms

 

2x^2 - 7x - 3, 2x^2 + -7x + -3

(4) If the first non-zero term is negative, make sure a negative sign appears immediately in front of it

-2x^2 + 3x + 7 - 2x^2 + 3x + 7
2x^2 + 3x + 7 +2x^2 + 2x + 7

(5) Make sure that if the value of all coefficients is zero, that you print 0.

0 (nothing prints when all coefficients are zero)

What to turn in

If you finish all steps

If you only finish some steps

(end of project 3)