In: Computer Science
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
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);
}
}