# CSE-40049 Homework 2

\$30.00

## Description

5/5 - (1 vote)

In this assignment you will be using linked lists to represent, display, and evaluate polynomials.

The following article provides a good overview of polynomials:
http://en.wikipedia.org/wiki/Polynomial.

The following rules should be observed throughout the assignment:
• Each polynomial should be represented as a singly-linked list (see files “list.h” and “list.c”
from the book).

• Each element in the linked list should represent one of the terms in the polynomial.
• The data held by each element should be type double representing the constant for that
term.

• For example, the polynomial 6.0×3 – 5.3x + 3.1 would be represented by the linked list
6.0  0.0  -5.3  3.1.

a) (1 point) Implement a function called appendTerm:
void appendTerm(List *pPolynomial, double constant);

This function should append (insert at the end) the value constant to pPolynomial. For
example, appending 3.1 to pPolynomial already containing 6.0  0.0  -5.3 should
result in the value 3.1 being added at the end: 6.0  0.0  -5.3  3.1. If the append
fails the program should exit.

b) (2 points) Implement a function called display:
void display(List *pPolynomial);
This function should output the polynomial to stdout in proper polynomial format. For
example, displaying polynomial 6.0  0.0  -5.3  3.1 should result in 6.0x^3 –
5.3x + 3.1 being output.

c) (2 points) Implement a function called evaluate:
double evaluate(List *pPolynomial, double x);

This function should evaluate the polynomial for the given value of x and return the result.
For example, given polynomial 6.0  0.0  -5.3  3.1 and x having value 7.0 the
function should return 2024.0 (the result of evaluating 6.0*7.03 – 5.3*7.0 + 3.1).

d) (4 points) Write a program to test the functions from parts a – c. Your test program should
demonstrate creating, displaying, and evaluating the following polynomials with the given
values for x:
• x + 1.0 with x = 1.0
• x
2 – 1.0 with x = 2.03

• -3.0×3 + 0.5×2 – 2.0x with x = 05.0
• -0.3125×4 – 9.915×2 – 7.75x – 40.0 with x = 123.45

e) (1 point) Make sure your source code is well-commented, consistently formatted, uses no
magic numbers/values, follows programming best-practices, and is ANSI-compliant.

Turn in all source code, program output, diagrams, and answers to questions in a single
Word or PDF document.