Em Andamento

Linked Lists

Overview

For this assignment, you will be implementing a singly linked list to store polynomials. For instance, the polynomial 5*X^4 + 3*X^3 + 7*X + 10 will be stored as a linked list made up of 4 nodes. The first node will contain the coefficient of 5 and exponent of 4. It will be followed by a node with coefficient and exponent of 3, a node with coefficient of 7 and exponent 1, and finally a node with coefficient 10 and exponent 0. Notice that the nodes are stored in descending order based on the exponent.

class Term

This class will store information about one term in the polynomial, therefore this is the class that is used as the nodes in the linked list.

The definition for this class should be contained in a file called ***Term.h***, while the implementation should be contained in a file called ***[url removed, login to view]***. The Poly class (described below) is eventually going to need access to the private members of the Term class.

Data members

This class should have three data members that are not available to the outside world. The first is an integer that is used to hold the coefficient for a term in the polynomial. The second is an integer that is used to hold the exponent for a term in the polynomial. The third is pointer to a Term object, which will hold the address of the next Term in the linked list.

Constructor

This class should have one constructor. It takes three arguments: the first is an integer value that will be used to set the coefficient, the second is an integer that will be used to set the exponent, and the third is a pointer to a Term object that will be used to set the link field for the Term.

All three of the arguments should have default values of 0.

### Methods

Input (or extraction) operator: istream >> Term

Overload the input operator to read in two integers, a coefficient and an exponent, from one line. The two integers should be stored in the appropriate fields of the Term.

#### Output (or insertion) operator: ostream << Term

Overload the output operator to print a Term in the following format:

coefficient*X^exponent

There are a couple of special cases that need to be handled:

1. If the exponent is 1, print only coefficient*X

2. If the exponent is 0, print only the coefficient.

## Deliverables

continued.....

Multiplication Operator: Term * Term

Overload the multiplication operator to multiply two Term objects. This is a constant method that takes one argument, a reference to a constant Term, and returns a Term object.

The new Term that is created should have an exponent equal to the sum of the exponents for the two Terms, a coefficient equal to the product of the coefficients for the two Terms, and a pointer field that is 0. For instance:

class Poly

This class will store the polynomial, therefore this is the class that is used as the linked list.

The definition for this class should be contained in a file called Poly.h, while the implementation should be contained in a file called Poly.cc. The Poly class is going to use the Term class so Term.h should be one of the #included files.

For this class, you should have at least the following data member and methods:

Data member

This class should have one data member that is not available to the outside world. It is a pointer to a Term object, which will hold the address of the first Term in the linked list.

Constructors

Default Constructor

The default constructor should initialize the pointer to 0 to indicate that the linked list is empty.

Copy Constructor

The copy constructor for this class should create a new Poly object that has Term's that are identical to those in an existing Poly object. It takes as its argument a reference to a constant Poly object.

Think about calling the Copy() method described below.

Destructor

The destructor for this class should release all of the Terms in a Poly object. Think about calling the Dismantle() method described below.

Methods

Copy

This is a private helper method that creates a copy of an existing Poly object. It takes two arguments and returns nothing. The first argument is a pointer to a Term object, while the second is a reference to a pointer to a Term object (ie. Term *&).

This method is going to create a copy of the existing Poly object one Term at a time. It can be implemented recursively.

The initial call to Copy will have sourcePtr pointing at the first Term of an existing Poly object, and destinationPtr referencing the first Term of the copy of the Poly object that is being created.

Dismantle

This is a private helper method that deletes all of the Terms in an existing Poly object. It takes one argument and returns nothing. The argument to this method is a reference to a pointer to a Term object.

This method will delete the Terms one at a time. It can be implemented recursively.

Equality Operator: Poly == Poly

Overload the equality operator to determine if two Poly objects are equal. Two polynomials are equal if the corresponding coefficients and exponents of every Term are equal.

Output (or insertion) Operator: ostream << Poly

Overload the output operator for the purpose of printing out an instance of the Poly class. The function should print out the polynomial one Term at a time.

This can be implemented by starting a pointer at the first Term in the Poly object and stepping through the Terms as long as the pointer is not 0. At each step, the Term is printed using the output operator for Term.

If the Poly object is empty (i.e. there are no Terms to print), the function should print a message saying so.

This function is going to need access to private data from BOTH the Poly and Term classes. Therefore, this function should be made a friend of BOTH the Poly and Term class.

Input (or extraction) Operator: istream >> Poly

Overload the input operator to read in the data to form a Poly object. The function is first going to read in an integer that is equal to the number of Terms that will make up the polynomial (lets call this numTerm). Now implement a loop that will execute numTerm times. Inside of the loop:

## Platform

Tera Term Pro 2.3

continued...

Add. Operator: Poly += Term

Overload += operator to add Term to an existing Poly object. This takes 1 argument, a reference to a constant Term, and returns reference to a Poly object.

Assignment Operator: Poly = Poly

Overload assign. operator so that it assigns contents of the Poly on the right of the operator to the Poly on left. Takes 1 argument, reference to a constant Poly, and returns reference to a Poly.

Add. Operator: Poly + Poly

Overload add. operator so that two instances of Poly can be added together. Takes 1 argument, reference to a constant

Poly object, and returns a Poly object.

Sub. Operator: Poly - Poly

Overload subtraction operator so one instance of Poly can be subtracted from another. Takes 1 argument, reference to a constant Poly object, and returns Poly object.

Habilidades: Programação C, Engenharia, Linux, MySQL, PHP, Arquitetura de software, Teste de Software, UNIX

Ver mais: world programming, while loop c programming, think recursively, recursively, purpose of use cases, programming operator, programming loop, programming definition, programming class definition, pointer programming, object based programming, node programming, node based programming, loop programming, linked on, linked n, linked it, linked i, integers form 1, definition of programming, data input operator, c programming while loop, c programming pointer, c programming operator, c programming linked list

Acerca do Empregador:
( 2 comentários ) United States

ID do Projeto: #2998777

Premiar a:

claudiuvw

See private message.

$42.5 USD em 4 dias
(1 Comentário)
2.3

28 freelancers estão ofertando em média $27 para este trabalho

mziconsultinginc

See private message.

$46.75 USD in 4 dias
(84 Comentários)
6.3
mihaiscortaru

See private message.

$42.08 USD in 4 dias
(160 Comentários)
6.0
idleswell

See private message.

$36.55 USD in 4 dias
(174 Comentários)
5.9
jamix2

See private message.

$33.15 USD in 4 dias
(57 Comentários)
5.9
jonminter

See private message.

$42.5 USD in 4 dias
(33 Comentários)
5.0
senzaciosnegyes

See private message.

$15.3 USD in 4 dias
(104 Comentários)
4.9
dcrs

See private message.

$11.9 USD in 4 dias
(11 Comentários)
4.6
hajjs

See private message.

$42.5 USD in 4 dias
(17 Comentários)
4.3
RitchieM

See private message.

$33.15 USD in 4 dias
(17 Comentários)
4.2
shashikhanvw

See private message.

$93.5 USD in 4 dias
(15 Comentários)
3.8
andrewlazarev

See private message.

$17 USD in 4 dias
(12 Comentários)
3.6
rebuildingteam

See private message.

$17 USD in 4 dias
(20 Comentários)
3.5
vladimirlagutin

See private message.

$12.75 USD in 4 dias
(20 Comentários)
3.3
michaelpryhodko

See private message.

$25.5 USD in 4 dias
(1 Comentário)
3.3
carefulwith

See private message.

$15.3 USD in 4 dias
(13 Comentários)
3.1
sonersen

See private message.

$17 USD in 4 dias
(11 Comentários)
2.8
homeworktutor

See private message.

$16.15 USD in 4 dias
(12 Comentários)
2.4
sireeshvw

See private message.

$3.4 USD in 4 dias
(3 Comentários)
1.7
blacksmithstd

See private message.

$85 USD in 4 dias
(1 Comentário)
0.6
striker69

See private message.

$11.05 USD in 4 dias
(4 Comentários)
0.3