Forum Index > Coș cu teme șterse > Soft > Polimorfism

#0 by tuyi (Power User) (0 mesaje) at 2014-11-15 21:59:45 (559 săptămâni în urmă) - [Link]Top
Creaţi clasa abstractă de bază Container cu funcţiile virtuale de inserare şi extragere. Creaţi clasele derivate Stack şi Queue, în care funcţiile date sunt predefinite. În funcţia main determinaţi masivul de pointeri la clasa abstractă, cărora li se atribuie adresele obiectelor claselor derivate.
In C++.


Mesaj util ?   Da   0 puncte

1
<< Precedenta      Următoarea >>

#1 by dumitru19811 Club de sah si dame (Power User) (0 mesaje) at 2014-11-15 23:24:31 (559 săptămâni în urmă) - [Link]Top
Vad si eu acum in ce consta.

Am dat la niste ciuvasi pe skype sa o faca. Drept ca lipseste class Queue.

#include<iostream>

using namespace std;

class Container{
    public:
    int *array;
    int position;

    virtual void push(int i)=0;
    virtual int pop()=0;
};

class Stack : public Container{

    public:
    Stack(int size){
        array = new int[size];
        position = 0;
    }

    void push(int item){
        array[position++]=item;
    }

    int pop(){
        return array[--position];
    }
};

int main(){
    int *a= new int[10];
    a=new int[3];
    a[1]=2;

    Stack p(100);
    Container *c=&p;

    c->push(3);
    c->push(5);

    cout<<c->pop()<<endl;
    cout<<c->pop()<<endl;

    return 1;

}


/*The two operations applicable to all stacks are:

a push operation, in which a data item is placed at the location pointed to by the stack pointer, and the address in the stack pointer is adjusted by the size of the data item;
a pop or pull operation: a data item at the current location pointed to by the stack pointer is removed, and the stack pointer is adjusted by the size of the data item.*/


Mesaj util ?   Da   0 puncte

1
<< Precedenta      Următoarea >>

Forum Index > Coș cu teme șterse > Soft > Polimorfism

Această temă este închisă. Nu puteţi posta mesaje noi.


Navigare rapidă:


Comunitatea digitală din Moldova. Să adunăm și să organizăm conținutul autohton de pe întreg internet pe un singur site web.