CS 631 - Computing Fundamentals II - Spring 2005
Programming Assignments
Loyola College >
Department of Computer Science >
CS 631 >
Programming Assignments >
Programming Assignment 2
Polynomial Representation with Linked Lists
Due
Tuesday, March 15th at the beginning of class.
Email an electronic copy by attaching each .cpp and .h to the email. In addition, turn in a printout of the code. Be sure to include the Honor Code Statement:
"I hereby declare that I have abided by the Honor Code during this assignment."
Introduction
The objective of this assignment is a representation of a polynomial using a linked list. This class will support the operations degree, coeffiecient, change coeffiecient, and add as described in the text on pages 160 and 161. In addition, your program should support an evaluate operation which displays the value of the polynomial for some x value entered by the user.
You should provide a menu that allows the user to interact with the program. The user should be able to
- create a new polynomial entered in the format -3x^4 + 2x^2 - x + 4 (the spaces are not required but you should be able to copy with any number of spaces in the equation)
- find the degree of the polynomial
- find the coefficient for a specified term
- change the coefficient of a specified term
- add a polynomial entered in the same format shown above
- evaluate a polynomial at a specified value
The program should prompt the user to enter the necessary information and do error checking and handle incorrect information gracefully.
Assignment
- Complete Programming Problem 8 on page 239.
- Design your program using a modular approach, which may include classes and/or structs if you wish. You are not allowed to use global variables, although you may define global constants.
- Your program should first call a function announce to describe the purpose of your program.
- The program will then display the menu and execute the correct operation.
Grading
- 70% Execution - Partial credit will be granted depending on how much progress you made towards the correct result.
- 20% Design - The design score is based on how easy it is to follow the logic of your code, how well you avoided repetitive code, the types you choose for your variables, and how easy it would be to change your code if certain specifications changed.
- 10% Style - Style includes comments, indentation, and choice of variable and method names.
- Substantial progress must be made towards correct execution to earn the points for design and style.
Partial Solution
This program demonstrates parsing a polynomial. I read the whole line, and then treat the string as an array to find the coefficient and power of each term. This is different from the solution discussed in class which did not handle terms where the power is 0 or terms where the coefficent in 1.