Project 1. A Unary Sparse Polynomial Calculator
[Problem Description]
Implement a simple calculator to operate unary sparse polynomials.
[Requirement]
The basic functions of the calculator should be as follows.
(1) Input and establish the polynomial.
(2) Output the polynomial as a sequence of integers:
1 1 2 2
, , , , , , , ,
n n
n c e c e c e
where n is the number
of items,
i
c
and
i
e
respectively refers to the coefficient and exponent of the item. The exponents of
the polynomial should be sorted in a descending order.
(3) Polynomial addition: establish the polynomial
a b
.
(4) Polynomial subtraction: establish the polynomial
a b
.
(5) Compute the value of polynomial when the
x
is given.
(6) Compute the derivative
a
of polynomial
a
.
(7) Polynomial multiplication: establish the polynomial
ab
.
(8) Design a simulation UI for the calculator.
[Test Cases]
(1)
8 11 8 9 11 9
(2 5 3.1 ) (7 5 11 ) ( 3.1 11 2 7)
x x x x x x x x
(2)
3 2 9 3 2 2 15 15 9 3
(6 4.4 1.2 ) ( 6 5.4 7.8 ) ( 7.8 1.2 12 )
x x x x x x x x x x x x
(3)
2 3 4 5 6 3 4 2 5
(1 ) ( ) (1 )
x x x x x x x x x x x
(4)
3 3
( ) ( ) 0
x x x x
(5)
100 100 200 100 200
( ) ( ) ( 2 )
x x x x x x x
(6)
2 3 2 3
( ) 0
x x x x x x
[Hints]
(1) Use the singly linked list with head node to store the polynomial.
(2) Define the representations of input and output yourself.
[Grading]
Implementation: 50% Interface: 30% Coding Style: 20%
Notice: This project will be checked on the experimental lesson in the 5th week (2016.09.27).