Solutii5 - Capitolul 5 - Clase derivate. Moteniri E5.1,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Capitolul 5 - Clase derivate. Moşteniri E5.1, E5.2, E5.3 #include <iostream.h> class polinom { protected: int n; // grad void *coef; int err; public: polinom(){err=1;coef=0;} virtual ~polinom(){ if (coef){ delete coef; coef = 0; } //cout << "Destructor polinom" << endl; } int GetDegree() const{return n;} void SetDegree(int v) {n=v;} int GetErr()const {return err;} void SetErr() {err=1;} void* GetCoef() const {return coef;} void SetCoef(void* c) {coef=c;} virtual void print(){ //cout <<"Print from baza" << endl; } virtual polinom& sum(const polinom &pol)=0; //virtual polinom& prod(const polinom &pol)=0; //virtual polinom& powr(int k)=0; }; class lpolinom:public polinom { public: lpolinom() {err = 1; coef = 0;} lpolinom(int d, long *c) { err=0; n = d; long *lcoef= new long[d+1]; coef = (void*)lcoef; for (int i=0;i<=d;i++) lcoef[i] = c[i]; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
{ err = pol.err; if (!err){ n = pol.n; coef = (void*)new long[n+1]; long *pc= (long*)coef; long *pr= (long*)pol.coef; for (int i=0;i<=n;i++) pc[i]=pr[i]; } } ~lpolinom(){ if (coef){ delete [](long*)coef; coef = 0; } //cout << "Destructor lpolinom" << endl; } polinom& sum(const polinom& pol);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Solutii5 - Capitolul 5 - Clase derivate. Moteniri E5.1,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online