Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class polinom {
- float *p;
- public:
- polinom(float a=0,float b=0,float c=0)
- {
- p=new float[3];
- p[0]=a;
- p[1]=b;
- p[2]=c;
- }
- polinom(const polinom& pol)
- {
- p=new float[3];
- p[0]=pol.p[0];
- p[1]=pol.p[1];
- p[2]=pol.p[2];
- }
- ~polinom(){delete []p;}
- polinom& operator=(const polinom& pol)
- {
- if(this==&pol)
- return *this;
- delete []p;
- p=new float[3];
- p[0]=pol.p[0];
- p[1]=pol.p[1];
- p[2]=pol.p[2];
- return *this;
- }
- friend ostream& operator<<(ostream& out,const polinom& pol)
- {
- for(int i=0;i<3;i++)
- {
- out<<pol.p[i]<<"X^"<<3-i-1;
- out<<" ";
- }
- out<<"\n";
- return out;
- }
- friend istream& operator>>(istream& in,const polinom& pol)
- {
- for(int i=0;i<3;i++)
- {
- cout<<"Vnesi go koeficientot pred X^"<<3-i-1<<endl;
- in>>pol.p[i];
- }
- return in;
- }
- polinom operator+(const polinom& pol)
- {
- for(int i=0;i<3;i++)
- {
- p[i]+=pol.p[i];
- }
- return *this;
- }
- polinom operator-(const polinom& pol)
- {
- for(int i=0;i<3;i++)
- {
- p[i]-=pol.p[i];
- }
- return *this;
- }
- polinom operator*(const polinom& pol)
- {
- for(int i=0;i<3;i++)
- {
- p[i]*=pol.p[i];
- }
- return *this;
- }
- };
- int main(){
- polinom m(3),n(4,2.7,3.0),k;
- cin>>m;
- cout<<"M = "<<m<<endl;
- cin>>n;
- cout<<"N = "<<n<<endl;
- polinom o=m;
- cout<< "O = "<<o<<endl;
- k=o;
- cout<<"K = "<<k<<endl;
- o=m + n;
- cout<<"M + N = "<<o<<endl;
- o=m - n;
- cout<<"M - N = "<<o<<endl;
- o=m * n;
- cout<<"M * N = "<<o<<endl;
- cout<<m;
- return 0;
- }
Add Comment
Please, Sign In to add comment