Atividade estruturada para av2
#include <iostream>
#include <stdlib.h> using namespace std;
int vetor[5],tam = 5; int ini=0,fim=0;
// funcoes de teste bool testar_vazio(){ if(fim == ini){ return true;//vazio }else{ return false;//nao vazio }
}
bool testar_lotado() { if(fim == tam){ return true;//lotado }else{ return false;//nao lotado } } // funcao enfileirar int enfileirar(){ int elemento=0; system("cls"); if (testar_lotado() == true){ system("cls"); cout << "Fila Lotada : \n"; system("PAUSE"); }else if(testar_vazio() == true){ cout << "Inserir elemento na Fila : \n"; cin >> elemento; vetor[ini]=elemento; fim++; }else{ cout << "Inserir elemento na Fila :\n"; cin >> elemento; for(int x=fim-1;x>=ini;x--){ vetor[x + 1]= vetor[x]; } vetor[ini] = elemento; fim++; } return 0;
}
// funcao Desenfileirar int desenfileirar(){ if(testar_vazio() == true){ cout << "Fila vazia ! \n"; system("PAUSE");
}else{
for(int x=fim-1;x>=ini;x--){ if(vetor[x] % 5 == 0){// numeros multipos de 5 cout << vetor[x]<<" - "; } if(fim > ini){fim--;}// reduçao desnecessaria
} system("PAUSE"); } return 0;
}
int menu(){
int opcao=1; while(opcao !=0) { cout << "fila\n"; cout << "0 - sai\n"; cout << "1 - enfileirar \n"; cout << "2 - desenfileirar \n"; cout << "Entre com opcao : "; cin >> opcao ; cout << "\n";
if(opcao == 0){ cout << " sair do programa: \n"; break; } if(opcao == 1){ enfileirar(); } if(opcao == 2){ desenfileirar(); } system("cls"); }
return 0;
}
int main()
{
menu(); return 0;
}
Atividade 2 estruturada ;
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cctype>
using namespace std; char vetor[5],p[5];
int