Question

In: Computer Science

The class Polynomials is a collection of polynomials of either implementation stored in an instance of...

The class Polynomials is a collection of polynomials of either implementation stored in an instance of the
generic library class List.
class Polynomials
{
private List L;
// Creates an empty list L of polynomials
public Polynomials ( )
{ … } (1 mark)
// Retrieves the polynomial stored at position i in L
public Polynomial Retrieve (int i) (1 mark)
{ … }
// Inserts polynomial p into L
public void Insert (Polynomial p) (1 mark)
{ … }
// Deletes the polynomial at index i
public void Delete (int i) (1 mark)
{ … }
// Returns the number of polynomials in L
public int Size ( )
{ … } (1 mark)
// Prints out the list of polynomials
public void Print ( )
{ … }

Please use C# to answer

Solutions

Expert Solution

1.

Creates an empty list L of polynomials

public polynomials()

{

//creation of empty list of Polynomials

List<Polynomial> list=new List<Polynomial>();

(Or) the provided List l

//we can use Any() to check wheather the list is empty or not

bool check=!l.Any();

if(check)

{

Console.WriteLine("the provided list l is empty");

} else

{

Console.WriteLine("The provided list is not empty");

}

2.

Retrieves the polynomial stored at position i in L

//Can be Done by using Item property

public Polynomial Retrieve (int i) (1 mark)
{

l.Item[i];

}

i.e l.item[2] (it will display polynomial which is storred at 2 location)

3.

// Inserts polynomial p into L
public void Insert (Polynomial p) (1 mark)
{

l.Add(p);

}

4.

// Deletes the polynomial at index i
public void Delete (int i) (1 mark)
{

l.RemoveAt(i)0;//which will remove at index i

}

5.

// Returns the number of polynomials in L
public int Size ( )
{

int count=l.Count; // It will provide number of polynomials of the list

return count;

}

6.

// Prints out the list of polynomials
public void Print ( )
{

foreach(Polynomial polynomial in l)

{

Console.Write(polynomial);

}

}


Related Solutions

Task 4 The class Polynomials is a collection of polynomials of either implementation stored in an...
Task 4 The class Polynomials is a collection of polynomials of either implementation stored in an instance of the generic library class List. class Polynomials { private List<Polynomial> L; // Creates an empty list L of polynomials public Polynomials ( ) { … } (1 mark) // Retrieves the polynomial stored at position i in L public Polynomial Retrieve (int i) (1 mark) { … } // Inserts polynomial p into L public void Insert (Polynomial p) (1 mark) {...
Task : (Please Answer in C#) Class Polynomials The class Polynomials is a collection of polynomials...
Task : (Please Answer in C#) Class Polynomials The class Polynomials is a collection of polynomials of either implementation stored in an instance of the generic library class List. class Polynomials { private List L; // Creates an empty list L of polynomials public Polynomials ( ) { … } // Retrieves the polynomial stored at position i in L public Polynomial Retrieve (int i) { … } // Inserts polynomial p into L public void Insert (Polynomial p) {...
Question 1 price is an instance variable of a class. Inside that class there is a...
Question 1 price is an instance variable of a class. Inside that class there is a method public void change(int price). From inside the method " change" how do we refer to the instance variable price and not the parameter price? Answer: Question 2 A method of a class can access which of the following: 1 global variables in the same scope 2. local variables defined within the method 3. the instance variables of its class 4. its parameters Question...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either fiction or nonfiction. Forty percent of the books are fiction and 65% are paperbacks, Also, 25% of the fiction books are hardcover. Now, a book is selected at random. a. What is the probability that it is a paperback?
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either fiction or nonfiction. Forty percent of the books are fiction and 65% are paperbacks, Also, 25% of the fiction books are hardcover. Now, a book is selected at random. a. What is the probability that it is a paperback? b. What is the probability that it is a paperback, given that it is a fiction? c. What is the probability it is a nonfiction,...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either...
Amazen has a collection of books for sale. They are either paperbacks or hardcovers and either fiction or nonfiction. Forty percent of the books are fiction and 65% are paperbacks, Also, 25% of the fiction books are hardcover. Now, a book is selected at random. a. What is the probability that it is a paperback? b. What is the probability that it is a paperback, given that it is a fiction? c. What is the probability it is a nonfiction,...
What is meant by the following statement: “The software implementation process is a conforming instance of...
What is meant by the following statement: “The software implementation process is a conforming instance of the system implementation process, specialized to the particular needs of implementing a software product or service”? What is meant by the following statement: “Detailed design of the interfaces shall permit coding without the need for further information”?
The Hole Class Description: For the Hole class, there are three instance variables: the par for...
The Hole Class Description: For the Hole class, there are three instance variables: the par for the hole, the length of the hole in yards, and a Boolean valued indicator of whether the hole is one in which the players’ full drives will be measured for distance. John clarifies: The length of the hole in yards determines par for the hole. The current standard is: No more than 250 yards Par 3 251 to 470 yards Par 4 471 to...
A negative Rational could either be represented by a negative value stored in __numerator or a...
A negative Rational could either be represented by a negative value stored in __numerator or a negative value stored in __denominator. If negative values are stored in both, the reduce() method that is provided for you will make them both positive. If a Rational happens to reduce to a whole number, it will still be saved in Rational form. In other words, if the result of an add() call creates a fraction 6/2, it should reduce to 3/1 but will...
Excess food is stored in our body either in the form of carbohydrates (in the muscles...
Excess food is stored in our body either in the form of carbohydrates (in the muscles and liver) or as fat (adipose tissue). When our body needs additional energy it uses the carbohydrate source first as a source of “quick” energy, then the fat. Why do you think carbohydrates are used as a source of quick energy rather than fat?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT