Guest User

Untitled

a guest
Jan 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. / Input Poly
  2. cout << "Input p1: " << endl;
  3. Polynomial P1;
  4. cin >> P1;
  5.  
  6. // Output Poly
  7. cout << "p1(x) = " << P1 << 'n' << endl;
  8.  
  9. //Insertion
  10. ostream& operator<<(ostream& os, Polynomial Poly){
  11.  
  12. for (int i=0; i < Poly.polyNum; i++) {
  13. os << Poly.poly[i] << " x^" << i;
  14.  
  15. if(i != Poly.polyNum - 1){
  16. os << " + ";
  17. }
  18. }
  19.  
  20. return os;
  21. }
  22.  
  23. //Extraction
  24. istream& operator>>(istream& is, Polynomial Poly){
  25.  
  26. int numP = 0;
  27. int * tempP;
  28.  
  29. is >> numP;
  30.  
  31. tempP = new int [numP+1];
  32.  
  33. for (int i=0; i < numP; i++) {
  34. is >> tempP[i];
  35. }
  36.  
  37. Poly.polyNum = numP;
  38.  
  39. Poly.poly = new int[Poly.polyNum +1];
  40.  
  41. for (int i=0; i < Poly.polyNum; i++) {
  42. Poly.poly[i] = tempP[i];
  43. }
  44.  
  45. return is;
  46. }
  47.  
  48. istream& operator>>(istream& is, Polynomial Poly)
  49.  
  50. istream& operator>>(istream& is, Polynomial& Poly)
  51.  
  52. Polynomial P1;
  53. cin >> P1;
Add Comment
Please, Sign In to add comment