Advertisement
Jonas_3k

// Matriz unidimensional @

Mar 29th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. void Adicionar(int *vetor)
  4. {
  5.     char opc;
  6.     do
  7.     {
  8.         int indice,valor;
  9.         cout << "\nInforme a posicao: ";
  10.         cin >> indice;
  11.         while( (indice < 0) || (indice > 10) )
  12.         {
  13.             cout << "Informe uma posicao valida!" << "\ndigite: ";
  14.             cin >> indice;
  15.         }
  16.         cout << "Informe um valor para armazenar: ";
  17.         cin >> valor;
  18.         vetor[indice] = valor;
  19.         cout << "Valor incluido com sucesso! ";
  20.         cout << "Deseja inserir um novo valor? [S]im/[N]ao: ";
  21.         cin >> opc;
  22.  
  23.     }while( (opc == 'S') || (opc == 's') );
  24.     return;
  25. }
  26.  
  27. void Remover(int *vetor)
  28. {
  29.     int valor;
  30.     cout << "Informe o valor a ser removido: ";
  31.     cin  >> valor;
  32.     for(int i; i < 10 ; i++)
  33.     {
  34.         if(vetor[i] == valor)
  35.         {
  36.             cout << "Dado removido";
  37.             break;
  38.         }
  39.     }
  40.     return;
  41. }
  42.  
  43. void Exibir(int *vetor)
  44. {
  45.     for(int i = 0 ; i <= 10 ; i++)
  46.     {
  47.         cout << vetor[i] << '\t';
  48.     }
  49.     return;
  50. }
  51.  
  52. void Zerar(int *vetor)
  53. {
  54.     for( int i = 0 ; i < 10 ; i++)
  55.     {
  56.         vetor[i] = 0;
  57.     }
  58.     cout << "Limpeza de vetor concluida com sucesso\n";
  59.     return;
  60. }
  61.  
  62. int main()
  63. {
  64.     int vetor[10],opc;
  65.     Zerar(vetor);
  66.     do
  67.     {
  68.         cout << "INFORME A OPCAO DESEJADA: \n"
  69.         << "1- Inserir um valor desejado em uma posicao \n"
  70.         << "2- Remover um valor de uma posicao desejada \n"
  71.         << "3- Exibir os valores do vetor \n"
  72.         << "4- Limpar todos os vetores \n" << "5- Sair ::";
  73.         cin  >> opc;
  74.         switch(opc)
  75.         {
  76.             case 1 : Adicionar(vetor); break;
  77.             case 2 : Remover(vetor); break;
  78.             case 3 : Exibir(vetor); break;
  79.             case 4 : Zerar(vetor); break;
  80.             case 5 : return 0;
  81.             default : cout << "Valor errado\n";
  82.         }
  83.  
  84.     }while(true);
  85.     return -1;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement