Advertisement
Guest User

asd

a guest
Sep 25th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. class Vetor
  9. {
  10. private:
  11.     int tamanho;
  12.     int *vetor;
  13.  
  14. public:
  15.     Vetor(int t = 99);
  16.     Vetor operator()(int t=20);
  17.     void SetElemento(int, int);
  18.     int GetTamanho();
  19.     void Mostrar();
  20. };
  21.  
  22.  
  23. Vetor::Vetor(int t)
  24. {
  25.     this->tamanho = t;
  26.     vetor = new int[tamanho];
  27. }
  28.  
  29. Vetor Vetor::operator()(int t)
  30. {
  31.     this->tamanho = t;
  32.     vetor = new int[t];
  33. }
  34.  
  35. int Vetor::GetTamanho()
  36. {
  37.     return tamanho;
  38. }
  39.  
  40. void Vetor::SetElemento(int pos, int valor)
  41. {
  42.     this->vetor[pos] = valor;
  43. }
  44.  
  45. void Vetor::Mostrar()
  46. {
  47.     int indx = 0;
  48.     int tam = GetTamanho();
  49.     for(; indx < tam ; indx++)
  50.     {
  51.         cout <<"[" <<indx <<"] = " <<vetor[indx] <<endl;
  52.     }
  53. }
  54.  
  55. int main(int argc, char** argv)
  56. {
  57.     Vetor v1(50);
  58.     Vetor *v2;
  59.     Vetor v3;
  60.     v3(100);
  61.     Vetor v4(123);
  62.     v2 = new Vetor();
  63.     cout<<"Tamanho v1: "<<v1.GetTamanho()<<endl;
  64.     cout<<"Tamanho v2: "<<v2->GetTamanho()<<endl;
  65.     cout<<"Tamanho v3: "<<v3.GetTamanho()<<endl;
  66.     cout<<"Tamanho v4: "<<v4.GetTamanho()<<endl;
  67.  
  68.  
  69.     int tam = v1.GetTamanho();
  70.     for ( int indx = 0;indx < tam ; indx++)
  71.     {
  72.         v1.SetElemento(indx, indx * 10);
  73.     }
  74.  
  75.     v1.Mostrar();
  76.     cout<<"-------" <<endl;
  77.     //v2->Mostrar();
  78.  
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement