Guest User

Untitled

a guest
Jul 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class polinom {
  4. float *p;
  5. public:
  6. polinom(float a=0,float b=0,float c=0)
  7. {
  8. p=new float[3];
  9. p[0]=a;
  10. p[1]=b;
  11. p[2]=c;
  12. }
  13. polinom(const polinom& pol)
  14. {
  15. p=new float[3];
  16. p[0]=pol.p[0];
  17. p[1]=pol.p[1];
  18. p[2]=pol.p[2];
  19.  
  20. }
  21. ~polinom(){delete []p;}
  22.  
  23. polinom& operator=(const polinom& pol)
  24. {
  25. if(this==&pol)
  26. return *this;
  27. delete []p;
  28. p=new float[3];
  29. p[0]=pol.p[0];
  30. p[1]=pol.p[1];
  31. p[2]=pol.p[2];
  32. return *this;
  33. }
  34.  
  35. friend ostream& operator<<(ostream& out,const polinom& pol)
  36. {
  37. for(int i=0;i<3;i++)
  38. {
  39. out<<pol.p[i]<<"X^"<<3-i-1;
  40. out<<" ";
  41. }
  42. out<<"\n";
  43. return out;
  44. }
  45. friend istream& operator>>(istream& in,const polinom& pol)
  46. {
  47. for(int i=0;i<3;i++)
  48. {
  49. cout<<"Vnesi go koeficientot pred X^"<<3-i-1<<endl;
  50. in>>pol.p[i];
  51. }
  52. return in;
  53. }
  54.  
  55. polinom operator+(const polinom& pol)
  56. {
  57. for(int i=0;i<3;i++)
  58. {
  59. p[i]+=pol.p[i];
  60. }
  61. return *this;
  62. }
  63. polinom operator-(const polinom& pol)
  64. {
  65. for(int i=0;i<3;i++)
  66. {
  67. p[i]-=pol.p[i];
  68. }
  69. return *this;
  70. }
  71. polinom operator*(const polinom& pol)
  72. {
  73. for(int i=0;i<3;i++)
  74. {
  75. p[i]*=pol.p[i];
  76. }
  77. return *this;
  78. }
  79.  
  80. };
  81. int main(){
  82. polinom m(3),n(4,2.7,3.0),k;
  83. cin>>m;
  84. cout<<"M = "<<m<<endl;
  85. cin>>n;
  86. cout<<"N = "<<n<<endl;
  87. polinom o=m;
  88. cout<< "O = "<<o<<endl;
  89. k=o;
  90. cout<<"K = "<<k<<endl;
  91. o=m + n;
  92. cout<<"M + N = "<<o<<endl;
  93. o=m - n;
  94. cout<<"M - N = "<<o<<endl;
  95. o=m * n;
  96. cout<<"M * N = "<<o<<endl;
  97. cout<<m;
  98. return 0;
  99. }
Add Comment
Please, Sign In to add comment