rod1231234

LOL

May 5th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. template<class T>
  7. class Vetor
  8. {
  9.     T *vet;
  10.     int tam;
  11.    
  12. public:
  13.     Vetor(int n)
  14.     {
  15.         vet = new T(n);
  16.         tam=n;
  17.     }
  18.     ~Vetor();
  19.     void LeiaVetor();
  20.     void ImprimaVetor();
  21. };
  22.  
  23.  
  24.  
  25. template<class T>
  26. Vetor<T>::~Vetor()
  27. {
  28.     delete []vet;
  29.     cout << "destrutor";
  30. };
  31.  
  32. template <class T>
  33. void Vetor<T>::LeiaVetor()
  34. {
  35.     cout << "Digite o vetor\n";
  36.     int *p;
  37.     p=vet;
  38.     for (int i=0 ; i<tam ; i++)
  39.     {
  40.         cin >> *p;
  41.         p++;
  42.     }
  43. };
  44.  
  45. template <class T>
  46. void Vetor<T>::ImprimaVetor()
  47. {
  48.     cout << "O vetor que vc digitou\n";
  49.     int *p;
  50.     p=vet;
  51.     for(int i=0 ; i<tam ; i++)
  52.     {
  53.         cout << *p << " ";
  54.         p++;
  55.     }
  56.    
  57. };
  58.  
  59.  
  60.  
  61. int main()
  62. {
  63.     Vetor<int> V(10);
  64.     V.LeiaVetor();
  65.     V.ImprimaVetor();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment