Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A {
- int x;
- public:
- A(int _x) : x(_x) {}
- virtual int f(int) =0;
- };
- class E {
- float coeff;
- public:
- E(double c) {coeff = (float) c;}
- double getCoeff() {return (double) coeff;}
- int somma(int[], int);
- };
- int E::somma(int v[], int n) {
- int somma = 0;
- for(int i=0; i < n; i++)
- somma += v[i];
- return somma;
- }
- //IL COSTRUTTORE CREA UN'ISTANZA DI E, E PASSA IL PARAMETRO d
- // ALL'ATTRIBUTO COEFF;
- class B : public A{
- E e;
- public:
- B(int x, double d) : A(x), e(d) {}
- float getCoeff() { return (float) e.getCoeff();}
- E getE() {return e;}
- };
- //attrib: - z int[*]
- //metodi
- // + C(x: int, d: double, q: int)
- // + f(x: int) : int
- // + ultimo() : int
- // il costruttore crea un array di lunghezza x e poi
- // inizializza la locazione di indice i con il valore (2*q+i+1)
- // f restituisce il metodo somma con parametro z
- // ultimo restituisce l'ultimo elemento di z
- class C : public B{
- int* z;
- int n;
- public:
- C(int x, double d, int q) :B(x,d) {
- //B(x, d);
- n = x;
- z = new int[x];
- for(int i=0; i < x; i++) {
- z[i] = 2*q+i+1;
- }
- }
- int f(int x) { return getE().somma(z, x);}
- int ultimo() {return z[n-1];}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement