CSCE 2004 - Homework 8
Due Date - 11/20/2012 at 11:59 PM

1. Problem Statement:

The goal of this programming assignment is to give students practice defining and using classes. In particular, students are required to design, implement, and test a class for storing and manipulating quadratic polynomials of the form: Ax^2 + Bx + C.

In the class header file "quadratic.h" students must define the class and specify the constructor/destructor functions, the public methods and private variables. In the class implementation file "quadratic.cpp" students must implement the following operations:

  • constructor - to initialize the object.
  • copy constructor - to copy an object.
  • destructor - to delete the object.
  • set - allow the user to set the values of A,B,C.
  • get - allow the user to get the values of A,B,C.
  • print - print out the quadratic in the form: Ax^2 + Bx + C.
  • add - add one quadratic polynomial to another.
  • subtract - subtract one quadratic polynomial from another.
  • evaluate - calculate the value of the quadratic for given x value.
  • derivative - take derivative of a quadratic polynomial.
  • zeros - calculate the zeros (roots) of a quadratic polynomial.
  • The purpose of your main program "hw8.cpp" is to demonstrate that all of the methods above work properly. You should have at least one call to each of the methods, and print out the quadratic polynomial as needed to show that the operations are performing correctly. Keep your main program as simple as possible. A well designed sequence of method calls is all you need. You do NOT need a fancy interactive program.

    2. Design:

    The main design task for this project is to decide what private variables need to be stored to represent quadratic polynomials, and what parameters you want to use for each of the public methods. You also need to decide which parameters to your methods are value parameters (with const) and which are reference parameters (with &).

    There are also several design decisions you need to make about the implementation of the methods above. For example, how do you want to print a quadratic with A=0? Should it be "0x^2 + Bx + C" or simply "Bx + C"? Any choice you make is fine.

    For the "evaluate" method, you simply need to plug in an x value into the Ax^2 + Bx + C formula to calculate the value of the quadratic at that point. You can use any method you like to give this value back to the main program.

    For the "derivative" method, you need to remember the basic formula for the derivative of a quadratic and modify the A,B,C coefficients of the quadratic accordingly. Your method will not need any parameters or return values.

    For the "zeros" method, you will need to use the quadratic formula you learned years ago to find the two values of x where Ax^2 + Bx + C is equal to zero. As you know, the zeros will both be real if the discriminant (b^2 -4ac) is positive, and the roots will be imaginary if the descriminant is negative. You need to decide what your method will return in both of these cases.

    Finally, you need to design the sequence of method calls in your main program to demonstrate the correctness of all of your methods. Your goal should be to print out a sequence of messages that make it easy for the user (your GTA) to follow what the program is doing. For example, to demonstrate that set, get, print, and addition are working properly you could output something like this:

    Set q1:   A=2, B=3, C=4
    Print q1: 2x^2 + 3x + 4
    Set q2:   A=1, B=4, C=-2
    Print q2: 1x^2 + 4x - 2
    Add q2 to q1
    Print q1: 3x^2 + 7x + 2
    Get q1:   A=3, B=7, C=2

    3. Implementation:

    You can implement this program using either a bottom-up approach or a top-down approach. If you go for a bottom-up approach, start by creating basic methods and classes, and test theses methods using a simple main program that calls each method. When this is working, you can create the main program that uses these methods to solve the problem above.

    If you go for a top-down approach, start by creating your main program that reads user input, and calls empty methods to pretend to solve the problem. Then add in the code for these methods one at a time. This way, you will get an idea of how the whole program will work before you dive into the details of implementing each method and class.

    Regardless of which technique you choose to use, you should develop your code incrementally adding code, compiling, debugging, a little bit at a time. This way, you always have a program that "does something" even if it is not complete.

    4. Testing:

    Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. Try your program on 2-3 input documents, and save your testing output in text files for submission on the program due date.

    5. Documentation:

    When you have completed your C++ program, write a short report (less than one page long) describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems? Save this report in a separate text file to be submitted electronically.

    6. Project Submission:

    In this class, we will be using electronic project submission to make sure that all students hand their programming projects and labs on time, and to perform automatic analysis of all programs that are submitted. When you have completed the tasks above go to the class web site to "upload" your documentation and testing document (pdf, doc, or txt file), and your C++ program (cpp or txt file).

    The dates on your electronic submission will be used to verify that you met the due date above. All late projects will receive reduced credit:

    You will receive partial credit for all programs that compile even if they do not meet all program requirements, so handing projects in on time is highly recommended.