main.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <iostream>
  2. #include <limits>
  3. #include "documento.hh"
  4. #include "fila.hh"
  5. void adicionarDocumento(Fila &fila){
  6. std::string nome;
  7. std::cout << std::endl << "Nome do documento: ";
  8. std::cin >> nome;
  9. int prioridade;
  10. while(std::cout << "Prioridade: (1) - Baixa, (2) - Média, (3) - Alta" << std::endl && (!(std::cin >> prioridade) || (prioridade != 1 && prioridade != 2 && prioridade != 3))){
  11. std::cin.clear();
  12. std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  13. std::cout << "Prioridade inválida!" << std::endl;
  14. }
  15. fila.adicionarDocumento(new Documento(nome, prioridade));
  16. }
  17. void imprimir(Fila &fila){
  18. std::cout << std::endl;
  19. if(fila.estaVazia())
  20. std::cout << "A fila está vazia" << std::endl;
  21. else
  22. while(!fila.estaVazia()){
  23. Documento* tmp = fila.imprimir();
  24. std::cout << tmp->retornaNome() << " - prioridade: " << tmp->retornaPrioridade() << std::endl;
  25. delete tmp;
  26. }
  27. }
  28. int main(){
  29. Fila fila;
  30. while(true){
  31. int opt;
  32. while(
  33. std::cout << std::endl
  34. << "(1) - Adicionar documento" << std::endl
  35. << "(2) - Imprimir" << std::endl
  36. << "(3) - Sair" << std::endl
  37. && (!(std::cin >> opt))
  38. || (opt != 1 && opt != 2 && opt != 3)
  39. ){
  40. std::cin.clear();
  41. std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  42. std::cout << "Opção inválida!" << std::endl;
  43. }
  44. switch(opt){
  45. case 1:{
  46. adicionarDocumento(fila);
  47. }
  48. break;
  49. case 2:{
  50. imprimir(fila);
  51. }
  52. break;
  53. case 3:
  54. return false;
  55. }
  56. }
  57. }