Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class wielomian3
  6. {
  7. protected:
  8. float a[4];
  9.  
  10. public:
  11.  
  12. wielomian3(float t[4])
  13. {
  14. for(int i=0;i<4;i++)
  15. {
  16. a[i]=t[i];
  17. }
  18. }
  19.  
  20. wielomian3()
  21. {
  22. for(int i=0;i<4;i++)
  23. {
  24. a[i]=0;
  25. }
  26. }
  27.  
  28. wielomian3 operator+(wielomian3 b)
  29. {
  30. for(int i=0;i<4;i++)
  31. {
  32. b.a[i]+=a[i];
  33. }
  34. return b;
  35. }
  36.  
  37. void operator+(int x)
  38. {
  39. for(int i=0;i<4;i++)
  40. {
  41. a[i]+=x;
  42. }
  43. }
  44.  
  45. friend void operator+(int x, wielomian3 &w)
  46. {
  47. for(int i=0;i<4;i++)
  48. {
  49. w.a[i]+=x;
  50. }
  51. }
  52.  
  53.  
  54.  
  55. void wyswietl()
  56. {
  57. cout << a[0] << " + " << a[1] << "x + " << a[2] << "x^2 + " << a[3] << "x^3" << endl;
  58. }
  59.  
  60. };
  61.  
  62. int main()
  63. {
  64. float x[4]={2,3,4,5};
  65. float y[4]={1,3,2,2};
  66.  
  67.  
  68. wielomian3 w(x);
  69. wielomian3 w1(y);
  70.  
  71. (w+w1).wyswietl();
  72.  
  73. w+2;
  74. w.wyswietl();
  75.  
  76. 2+w;
  77. w.wyswietl();
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement