Docsity

Assignment 13 in CGS 3460: Creating a Polynomial Program using Linked Lists, Assignments of Computer Science

Toggle sidebar
bg1
CGS 3460 - Programming Using C
Fall 2008
Assignment #13
Assigned: Monday, Dec 1st, 2008
Due: Monday, Dec 10th, 2008 at 11:59 PM
Please Note: Any compilation error will be subjected to at least 50% penalty of the assignment
grade.
1. (100 pts) in this assignment you’ll be creating a program that manages
polynomials using linked lists. If you are not familiar with polynomials you can
read http://en.wikipedia.org/wiki/Polynomial. You must perform all operations by
utilizing linked lists instead of arrays. We strongly encourage you to avoid square
brackets in your code. Any array usage associated with polynomials will result a
0 grade from this assignment.
Your program will perform the following operations on polynomials:
Create a polynomial
Add a polynomial
Multiply with a polynomial
Delete a specific term of the base (monomial) (see example).
The program will first read a polynomial from user, and keep it as its base
polynomial. While reading polynomials, you’ll force user to enter higher degree
terms first. If user provides an exponent of -1, you should finalize the reading
sequence. During reading you can assume exponent is a non-negative integer
and coefficient is a rational number (double or float).
After each operation, the resulting polynomial will be the base and will be printed.
While printing a polynomial:
; will be represented as
an * x^n +… + a1 * x + a0 (see example below).
Please follow the format in the example session below closely. You need to use
exact menu items (same letters while matching case). Note that you can assume
user never enters -1 at the beginning (so at least one valid term is provided).
Hint: You can define a structure to hold each term of the polynomial. Consider the
following structure:
pf3
pf4

Partial preview of the text

Download Assignment 13 in CGS 3460: Creating a Polynomial Program using Linked Lists and more Assignments Computer Science in PDF only on Docsity!

CGS 3460 - Programming Using C

Fall 2008

Assignment

Assigned: Monday, Dec 1st, 2008

Due : Monday, Dec 10

th

, 2008 at 11:59 PM

Please Note: Any compilation error will be subjected to at least 50% penalty of the assignment grade.

1. (100 pts) in this assignment you’ll be creating a program that manages

polynomials using linked lists. If you are not familiar with polynomials you can

read http://en.wikipedia.org/wiki/Polynomial. You must perform all operations by

utilizing linked lists instead of arrays. We strongly encourage you to avoid square

brackets in your code. Any array usage associated with polynomials will result a

0 grade from this assignment.

Your program will perform the following operations on polynomials:

 Create a polynomial

 Add a polynomial

 Multiply with a polynomial

 Delete a specific term of the base (monomial) (see example).

The program will first read a polynomial from user, and keep it as its base

polynomial. While reading polynomials, you’ll force user to enter higher degree

terms first. If user provides an exponent of -1, you should finalize the reading

sequence. During reading you can assume exponent is a non-negative integer

and coefficient is a rational number (double or float).

After each operation, the resulting polynomial will be the base and will be printed.

While printing a polynomial:

; will be represented as

an * x^n +… + a 1 * x + a 0 (see example below).

Please follow the format in the example session below closely. You need to use

exact menu items (same letters while matching case). Note that you can assume

user never enters -1 at the beginning (so at least one valid term is provided).

Hint: You can define a structure to hold each term of the polynomial. Consider the

following structure:

struct term{ float coef; int exp; term *next; }

Example:


Please enter your base polynomial:

Please enter exponent of the term (-1 if you are done): > 123000 Please enter coefficient of the term > 0.

Please enter exponent of the term (-1 if you are done): > 1 Please enter coefficient of the term > 2

Please enter exponent of the term (-1 if you are done): > 3 Error, you have already entered a term with degree 1, you should enter a strictly smaller exponent!

Please enter exponent of the term (-1 if you are done): > -

You are done entering base polynomial! The provided polynomial is:

0.5 * x^123000 + 2 * x

Please enter an option: ‘A’: Add a polynomial to base ‘M’: Multiply a polynomial with base ‘D’: Delete a specific term ‘Q’: Quit


> A

Please enter exponent of the term (-1 if you are done): > 1000 Please enter coefficient of the term > 3

Please enter exponent of the term (-1 if you are done): > 0

Deletion is done. Resulting base polynomial is:

0.5 * x^123002 + 2 * x^3 + 9 * x^

Please enter an option: ‘A’: Add a polynomial to base ‘M’: Multiply a polynomial with base ‘D’: Delete a specific term ‘Q’: Quit


> Q

You have chosen to quit. Final base polynomial is:

0.5 * x^123002 + 2 * x^3 + 9 * x^

Instructions for submitting Assignment 13

  1. First compress your program files into a tar file. For this, change to the directory where you have stored both the files. At the terminal command prompt (putty, Linux console, MAC terminal, etc.) type (Note that if you are using .h files see submission instructions for assignment 12): tar cvf assign13.tar p1.c Let’s say you have stored your files in assign13 directory your “rain” machine. > cd assign > ls p1.c .. >tar cvf assign13.tar p1. >ls p1.c assign13.tar ….
  2. If you are working from Windows platform using Putty and WinSCP, you can create a directory assign13 in your home directory on rain machine using putty. Create the directory using this command on putty > cd //to change to the home directory >mkdir assign13 //to create the directory under home directory
  3. Then transfer p1.c & p1.h to assign13 directory on rain using WinSCP.
  4. Go to step 1 to tar the file using putty.
  5. Use WinSCP to copy assign13.tar from rain machine back to your local computer, say desktop.
  6. Upload the assign13.tar to WebCT.
  7. Please check the discussion page for assignment 13 on WebCT for common questions and their answers.