public static void EvaluatePolynomial(DatastructuresPolynomials.Polynomials S) { int index; double x; double result; Console.Clear(); Console.WriteLine("Delete the polynomial from S at a given index"); Console.WriteLine("-----------------------------------------------------------------------------"); if (S.Size() == 0) { Console.WriteLine("Please populate the polynomials list S before evaluating!"); } else { Console.WriteLine("Polynomials in List S:\n"); Console.WriteLine("{0,8}{1,30}", "Key", "Polynomial"); Console.WriteLine("-----------------------------------------------------------------------------"); for (int i = 0; i < S.Size(); i++) { Console.Write("{0,8}{1,20}", i, ""); S.Retrieve(i).Print(); Console.WriteLine(); } Console.WriteLine("-----------------------------------------------------------------------------"); try { Console.Write("Enter index corresponding to the polynomial to be evaluated:\t"); index = Convert.ToInt32(Console.ReadLine()); Console.Write("\nEnter the value of x:\t"); x = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("\n\nEvaluating polynomial from list S:"); Console.WriteLine("-----------------------------------------------------------------------------"); Console.Write("\nPolynomial to be evaluated:\t"); S.Retrieve(index).Print(); Console.WriteLine($"\nx = {x}"); result = S.Retrieve(index).Evaluate(x); Console.WriteLine($"Result: {result}"); } catch (FormatException f) { Console.WriteLine("\n" + f.Message); Console.WriteLine("Invalid value of x"); Console.WriteLine("----------------------------------------------"); } catch (Exception e) { Console.WriteLine("\n" + e.Message); Console.WriteLine("Index entered does not exist"); Console.WriteLine("----------------------------------------------"); } } Console.WriteLine("\nPress any key to continue!"); Console.ReadKey(); Console.Clear(); }
public static void MultiplyPolynomial(DatastructuresPolynomials.Polynomials S) { int indexP; int indexQ; Console.Clear(); Console.WriteLine("Multiply two polynomials from S and insert the resultant polynomial into S"); Console.WriteLine("-----------------------------------------------------------------------------"); if (S.Size() == 0) { Console.WriteLine("Please populate the polynomials list S before multiplying!"); } else { Console.WriteLine("Polynomials in List S:\n"); Console.WriteLine("{0,8}{1,30}", "Index", "Polynomial"); Console.WriteLine("-----------------------------------------------------------------------------"); for (int i = 0; i < S.Size(); i++) { Console.Write("{0,8}{1,20}", i, ""); S.Retrieve(i).Print(); Console.WriteLine(); } Console.WriteLine("-----------------------------------------------------------------------------"); Console.Write("Enter index corresponding to p:\t"); indexP = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter index corresponding to q:\t"); indexQ = Convert.ToInt32(Console.ReadLine()); try { Console.WriteLine($"\nMultiplying terms p and q:"); Console.Write("p:\t"); S.Retrieve(indexP).Print(); Console.Write("\nq:\t"); S.Retrieve(indexQ).Print(); DatastructuresLinkedList.Polynomial product = new DatastructuresLinkedList.Polynomial(); product = S.Retrieve(indexP) * S.Retrieve(indexQ); Console.Write("\np * q: \t"); product.Print(); Console.WriteLine("\n\nInserting p * q into list S"); S.Insert(S.Retrieve(indexP) * S.Retrieve(indexQ)); Console.WriteLine("List S:"); S.Print(); } catch (Exception e) { Console.WriteLine("\n" + e.Message); Console.WriteLine("Index entered does not exist"); Console.WriteLine("----------------------------------------------"); } } Console.WriteLine("\nPress any key to continue!"); Console.ReadKey(); Console.Clear(); }
public static void DeletePolynomial(DatastructuresPolynomials.Polynomials S) { int index; Console.Clear(); Console.WriteLine("Delete the polynomial from S at a given index"); Console.WriteLine("-----------------------------------------------------------------------------"); if (S.Size() == 0) { Console.WriteLine("Please populate the polynomials list S before deleting!"); } else { Console.WriteLine("Polynomials in List S:\n"); Console.WriteLine("{0,8}{1,30}", "Key", "Polynomial"); Console.WriteLine("-----------------------------------------------------------------------------"); for (int i = 0; i < S.Size(); i++) { Console.Write("{0,8}{1,20}", i, ""); S.Retrieve(i).Print(); Console.WriteLine(); } Console.WriteLine("-----------------------------------------------------------------------------"); Console.Write("Enter index corresponding to the polynomial to be deleted:\t"); index = Convert.ToInt32(Console.ReadLine()); try { Console.WriteLine("\n\nDeleting polynomial from list S"); Console.Write("\nPolynomial to be deleted:\t"); S.Retrieve(index).Print(); S.Delete(index); Console.WriteLine("\n\nList S:"); S.Print(); } catch (Exception e) { Console.WriteLine("\n" + e.Message); Console.WriteLine("Index entered does not exist"); Console.WriteLine("----------------------------------------------"); } } Console.WriteLine("\nPress any key to continue!"); Console.ReadKey(); Console.Clear(); }