Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #define t 5
- using namespace std;
- int main (){
- int v[t],i,o,p,j;
- bool achou;
- do {
- system("cls");
- cout<<"\t****************************************************"<<endl;
- cout<<"\t*\tEscolha uma opcao *"<<endl;
- cout<<"\t*\t[1] Carregar vetor zerado *"<<endl;
- cout<<"\t*\t[2] Inserir valores no vetor *"<<endl;
- cout<<"\t*\t[3] Exibir o vetor *"<<endl;
- cout<<"\t*\t[0] Sair *"<<endl;
- cout<<"\t****************************************************"<<endl;
- cout<<"\t\tInforme uma opcao "<<endl;
- cin>>o;
- switch(o){
- case 1:
- cout<<"\t\tCarregando o vetor zerado..."<<endl;
- for (i=0;i<t;i++)
- v[i]=0;
- cout<<"\t\tVetor inicalizado com sucesso! "<<endl;
- system("pause");
- break;
- case 3:
- cout<<"\t\tExibindo o vetor..."<<endl;
- cout<<"\t\t[";
- for (i=0;i<t;i++)
- cout<<v[i]<<", ";
- cout<<"]"<<endl;
- system("pause");
- break;
- case 2:
- cout<<"\t\tInforme a posicao"<<endl;
- cin>>i;
- if (i>(t-1))
- cout<<"\t\tPosicao fora do intervalo do vetor!"<<endl;
- else{
- if(v[i]==0) {
- cout<<"\t\tInforme o valor do V["<<i<<"]"<<endl;
- cin>>v[i];
- cout<<"\t\tValor inserido com sucesso!"<<endl;
- }
- else{
- cout<<"\t\t A posicao escolhida já está preenchida!!"<<endl;
- cout<<"\t\t Remanejando o vetor..."<<endl;
- j=0;
- achou=false;
- while(j<t && ! achou)
- if (v[j]==0){
- achou=true;
- v[j]=v[i];
- }
- else
- j++;
- if(achou){
- cout<<"\t\tInforme o valor V["<<i<<"] ="<<endl;
- cin>>v[i];
- }
- else
- j++;
- if(achou){
- cout<<"\t\tInforme o valor de V["<<i<<"] ="<<endl;
- cin>>v[i];
- }
- else
- cout<<"Nao há mais espaco para o remanejamento!"<<endl;
- }
- }
- system("pause");
- break;
- }
- } while (o!=0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement