Guest User

ListaPacchetti.cpp

a guest
Feb 6th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include "ListaPacchetti.h"
  2.  
  3. int ListaPacchetti::count=0; //inizializzazione della variabile membro statica
  4.  
  5. ListaPacchetti::ListaPacchetti(const int n) {
  6.   count++;                    
  7.   Nelem=n;
  8.   V=new A[Nelem];                                          
  9. }
  10.  
  11. ListaPacchetti::ListaPacchetti(const int n, const A & e) {
  12.   count++;  
  13.   Nelem=n;
  14.   V=new A[Nelem];  
  15.   for(int i=0; i<Nelem; i++)
  16.       V[i]=e;                                      
  17. }
  18.  
  19. ListaPacchetti::ListaPacchetti(const ListaPacchetti & L) : Nelem(L.Nelem){
  20.   count++;
  21.   V=new A[Nelem];  
  22.   for(int i=0; i<Nelem; i++)
  23.       V[i]=L.V[i];                                      
  24. }
  25.  
  26. A & ListaPacchetti::operator[](int index){
  27. return V[index];
  28. }
  29.  
  30. const A & ListaPacchetti::operator[](int index) const {
  31. return V[index];
  32. }
  33.  
  34. ostream & operator<<(ostream& os, const ListaPacchetti & L)
  35. {
  36.   for(int i=0; i<L.Nelem; i++)
  37.       os << L.V[i] << endl;
  38.   return os;                
  39. }  
  40.  
  41. istream & operator>>(istream& in, ListaPacchetti & L){
  42. cout << "\n Inserire la dimensione della lista di pacchetti: ";
  43. in >> L.Nelem;
  44. if(L.V) delete [] L.V;
  45. L.V=new A[L.Nelem];
  46. cout << "\n Inserire la lista di pacchetti: " << endl;
  47. for(int i=0; i<L.Nelem; i++)
  48.       in >> L.V[i];
  49. return in;                
  50. }      
  51.  
  52.  
  53. A & ListaPacchetti::Access(int index) throw(EccezioneOutOfRange){
  54.      if(index >=0 && index <Nelem)
  55.      return V[index];
  56.      else throw EccezioneOutOfRange();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment