Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class wielomian3
- {
- protected:
- float a[4];
- public:
- wielomian3(float t[4])
- {
- for(int i=0;i<4;i++)
- {
- a[i]=t[i];
- }
- }
- wielomian3()
- {
- for(int i=0;i<4;i++)
- {
- a[i]=0;
- }
- }
- wielomian3 operator+(wielomian3 b)
- {
- for(int i=0;i<4;i++)
- {
- b.a[i]+=a[i];
- }
- return b;
- }
- void operator+(int x)
- {
- for(int i=0;i<4;i++)
- {
- a[i]+=x;
- }
- }
- friend void operator+(int x, wielomian3 &w)
- {
- for(int i=0;i<4;i++)
- {
- w.a[i]+=x;
- }
- }
- void wyswietl()
- {
- cout << a[0] << " + " << a[1] << "x + " << a[2] << "x^2 + " << a[3] << "x^3" << endl;
- }
- };
- int main()
- {
- float x[4]={2,3,4,5};
- float y[4]={1,3,2,2};
- wielomian3 w(x);
- wielomian3 w1(y);
- (w+w1).wyswietl();
- w+2;
- w.wyswietl();
- 2+w;
- w.wyswietl();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement