Advertisement
luishh

v16

May 9th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #define t 5
  4. using namespace std;
  5. int main (){
  6.     int v[t],i,o,p,j;
  7.     bool achou;
  8.     do {
  9.         system("cls");
  10.         cout<<"\t****************************************************"<<endl;
  11.         cout<<"\t*\tEscolha uma opcao                          *"<<endl;
  12.         cout<<"\t*\t[1] Carregar vetor zerado                  *"<<endl;
  13.         cout<<"\t*\t[2] Inserir valores no vetor               *"<<endl;
  14.         cout<<"\t*\t[3] Exibir o vetor                         *"<<endl;
  15.         cout<<"\t*\t[0] Sair                                   *"<<endl;
  16.         cout<<"\t****************************************************"<<endl;
  17.         cout<<"\t\tInforme uma opcao "<<endl;
  18.         cin>>o;
  19.         switch(o){
  20.             case 1:
  21.                 cout<<"\t\tCarregando o vetor zerado..."<<endl;
  22.                 for (i=0;i<t;i++)
  23.                 v[i]=0;
  24.                 cout<<"\t\tVetor inicalizado com sucesso! "<<endl;
  25.                 system("pause");
  26.                 break;
  27.             case 3:
  28.                 cout<<"\t\tExibindo o vetor..."<<endl;
  29.                 cout<<"\t\t[";
  30.                 for (i=0;i<t;i++)
  31.                 cout<<v[i]<<", ";
  32.                 cout<<"]"<<endl;
  33.                 system("pause");
  34.                 break;
  35.                 case 2:
  36.                 cout<<"\t\tInforme a posicao"<<endl;
  37.                 cin>>i;
  38.                 if (i>(t-1))
  39.                 cout<<"\t\tPosicao fora do intervalo do vetor!"<<endl;
  40.                 else{
  41.                     if(v[i]==0) {
  42.                         cout<<"\t\tInforme o valor do V["<<i<<"]"<<endl;
  43.                         cin>>v[i];
  44.                         cout<<"\t\tValor inserido com sucesso!"<<endl;
  45.                     }
  46.                     else{
  47.                         cout<<"\t\t A posicao escolhida já está preenchida!!"<<endl;
  48.                         cout<<"\t\t Remanejando o vetor..."<<endl;
  49.                         j=0;
  50.                         achou=false;
  51.                         while(j<t && ! achou)
  52.                         if (v[j]==0){
  53.                             achou=true;
  54.                             v[j]=v[i];
  55.                         }
  56.                         else
  57.                          j++;
  58.                          if(achou){
  59.                             cout<<"\t\tInforme o valor V["<<i<<"] ="<<endl;
  60.                             cin>>v[i];
  61.                                            
  62.                          }
  63.                          else
  64.                          j++;
  65.                          if(achou){
  66.                             cout<<"\t\tInforme o valor de V["<<i<<"] ="<<endl;
  67.                              cin>>v[i];
  68.                          }
  69.                          else
  70.                           cout<<"Nao há mais espaco para o remanejamento!"<<endl;
  71.                     }
  72.                 }
  73.                 system("pause");
  74.                 break;
  75.         }
  76.     } while (o!=0);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement