Programming Assignment #3

 

CS 202: Programming Systems

 

 

 

Program Statement:

Design and implement a C++ program using data abstraction and operator overloading to create a polynomial data type. This is not a proof of concept program – but rather a program where you are to develop a complete data type. You should build a simple application that thoroughly tests the data type.

 

Definition:

Develop a new data type: polynomial. Each polynomial is to be represented as a doubly linked list. The first node in the list represents the first term in the polynomial, the second node represents the second term, and so on. Each node contains a minimum of three fields: the first field is the term’s coefficient, the second field is the term’s power, and the third field is a pointer to the next term. So, 5x4+8x3-7x2+3x+7 would have 5 nodes. Allow the individual terms to be accessed (using []), polynomials to be copied (using the = operator), polynomials to be added and subtracted, and compared (using the relational and equality operators).

 

Design your solution such that you can naturally work with polynomials and perform operations on them as naturally as you might work with equations of integers. Chaining should be supported whenever possible.

 

Operators you must Overload (minimum set)

1.     Provide operations for accessing each term (i.e., []), assigning polynomials, displaying the polynomials with the << operator, inputting a polynomial with the >> operator, comparing two polynomials (==, !=, <, <=, >, >=), and performing addition and subtractions (+=, +, -=, and -). For addition and subtraction – allow for the operands to be polynomials or a combination of polynomials and integer constants.

2.     Provide for iterator operators that allow the client to step sequentially through the terms of a polynomial. Have both forward and backward (++, --) iterators.

3.     Consider what operator would make sense to allow clients to evaluate a polynomial.

 

When using operator overloading, remember to ask yourself the following questions:

      a) What should be the residual value (and what data type is this)?

      b) Should it be a modifiable lvalue or an rvalue?

      c) What are the data types of the operator’s operands?

      d) Is the first operand always an object of class?

      e) Can this be used with constant operands?

 

Take into account all of the special functions that are needed in C++ to ensure that objects can be passed by reference or by value by the client. Make sure the client is able to create constant objects of these types.

 

Implementation Requirements:

a)     Whenever possible return a reference

b)    Use pointer arithmetic; no subscripts allowed in your class implementation!

c)     Your grade will be based on efficient implementation of operators and member functions; for example, minimize the need for the copy constructor to be invoked!

d)    Make sure to pick symbols to be overloaded which follows their predefined intent as much as possible

e)     Make sure to use dynamic memory for your linked list. This means you will need a constructor, destructor, copy constructor and assignment operator to start with.

f)      Support complete data hiding (all data members must be private)

g)    Separate the class definition from the implementation (separate .h and .cpp files)

h)    Use Operator Overloading

i)      Use only the <iostream.h> I/O facilities...and not <stdio.h>

j)       Make sure to show:

- assignment (copying one set to another)

- addition and subtraction of two polynomials, as well as a polynomial and a constant

- show both interactive input & output of polynomials

 

Also, test out each of the symbols you overload, such as assignment, equality, and any arithmetic operators, etc.

 

 

What to Turn in:

• On the due date, email your source code  to: karlafgr@cs.pdx.edu as attached files.

The subject of your email should state:

                  cs202 prog2 submission <your last name>

 

• Remember that 20% of each program's grade is based on a written discussion of the UNIX debugger used, and major design considerations encountered when solving the problem.