Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *******LISTAPACCHETTI.h*******
- #include <iostream>
- #include "Pacchetto.h"
- #include "OorExc.h"
- using namespace std;
- typedef PacchettoRegalo A;
- class ListaPacchetti {
- friend ostream & operator<<(ostream&, const ListaPacchetti &);
- friend istream & operator>>(istream&, ListaPacchetti &);
- private:
- static int count;
- A * V;
- int Nelem;
- public:
- explicit ListaPacchetti(const int = 10);
- ListaPacchetti (const int, const A &);
- ListaPacchetti (const ListaPacchetti &);
- int get_Nelem() const {return Nelem;}
- static int get_count() {return count;}
- A & operator[](int);
- const A & operator[](int) const;
- ~ListaPacchetti() {count--; delete [] V;}
- };
- #endif
- *******LISTAPACCHETTI.cpp*******
- #include "ListaPacchetti.h"
- int ListaPacchetti::count=0; //inizializzazione della variabile membro statica
- ListaPacchetti::ListaPacchetti(const int n) {
- count++;
- Nelem=n;
- V=new A[Nelem];
- }
- ListaPacchetti::ListaPacchetti(const int n, const A & e) {
- count++;
- Nelem=n;
- V=new A[Nelem];
- for(int i=0; i<Nelem; i++)
- V[i]=e;
- }
- ListaPacchetti::ListaPacchetti(const ListaPacchetti & L) : Nelem(L.Nelem){
- count++;
- V=new A[Nelem];
- for(int i=0; i<Nelem; i++)
- V[i]=L.V[i];
- }
- A & ListaPacchetti::operator[](int index){
- return V[index];
- }
- const A & ListaPacchetti::operator[](int index) const {
- return V[index];
- }
- ostream & operator<<(ostream& os, const ListaPacchetti & L)
- {
- for(int i=0; i<L.Nelem; i++)
- os << L.V[i] << endl;
- return os;
- }
- istream & operator>>(istream& in, ListaPacchetti & L){
- cout << "\n Inserire la dimensione della lista di pacchetti: ";
- in >> L.Nelem;
- if(L.V) delete [] L.V;
- L.V=new A[L.Nelem];
- cout << "\n Inserire la lista di pacchetti: " << endl;
- for(int i=0; i<L.Nelem; i++)
- in >> L.V[i];
- return in;
- }
Advertisement
Add Comment
Please, Sign In to add comment