Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <vector>
- using namespace std;
- class Vetor
- {
- private:
- int tamanho;
- int *vetor;
- public:
- Vetor(int t = 99);
- Vetor operator()(int t=20);
- void SetElemento(int, int);
- int GetTamanho();
- void Mostrar();
- };
- Vetor::Vetor(int t)
- {
- this->tamanho = t;
- vetor = new int[tamanho];
- }
- Vetor Vetor::operator()(int t)
- {
- this->tamanho = t;
- vetor = new int[t];
- }
- int Vetor::GetTamanho()
- {
- return tamanho;
- }
- void Vetor::SetElemento(int pos, int valor)
- {
- this->vetor[pos] = valor;
- }
- void Vetor::Mostrar()
- {
- int indx = 0;
- int tam = GetTamanho();
- for(; indx < tam ; indx++)
- {
- cout <<"[" <<indx <<"] = " <<vetor[indx] <<endl;
- }
- }
- int main(int argc, char** argv)
- {
- Vetor v1(50);
- Vetor *v2;
- Vetor v3;
- v3(100);
- Vetor v4(123);
- v2 = new Vetor();
- cout<<"Tamanho v1: "<<v1.GetTamanho()<<endl;
- cout<<"Tamanho v2: "<<v2->GetTamanho()<<endl;
- cout<<"Tamanho v3: "<<v3.GetTamanho()<<endl;
- cout<<"Tamanho v4: "<<v4.GetTamanho()<<endl;
- int tam = v1.GetTamanho();
- for ( int indx = 0;indx < tam ; indx++)
- {
- v1.SetElemento(indx, indx * 10);
- }
- v1.Mostrar();
- cout<<"-------" <<endl;
- //v2->Mostrar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement