1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #include <iostream>
- #include <limits>
- #include "documento.hh"
- #include "fila.hh"
- void adicionarDocumento(Fila &fila){
- std::string nome;
- std::cout << std::endl << "Nome do documento: ";
- std::cin >> nome;
- int prioridade;
- while(std::cout << "Prioridade: (1) - Baixa, (2) - Média, (3) - Alta" << std::endl && (!(std::cin >> prioridade) || (prioridade != 1 && prioridade != 2 && prioridade != 3))){
- std::cin.clear();
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- std::cout << "Prioridade inválida!" << std::endl;
- }
- fila.adicionarDocumento(new Documento(nome, prioridade));
- }
- void imprimir(Fila &fila){
- std::cout << std::endl;
- if(fila.estaVazia())
- std::cout << "A fila está vazia" << std::endl;
- else
- while(!fila.estaVazia()){
- Documento* tmp = fila.imprimir();
- std::cout << tmp->retornaNome() << " - prioridade: " << tmp->retornaPrioridade() << std::endl;
- delete tmp;
- }
-
- }
- int main(){
- Fila fila;
- while(true){
- int opt;
- while(
- std::cout << std::endl
- << "(1) - Adicionar documento" << std::endl
- << "(2) - Imprimir" << std::endl
- << "(3) - Sair" << std::endl
- && (!(std::cin >> opt))
- || (opt != 1 && opt != 2 && opt != 3)
- ){
- std::cin.clear();
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- std::cout << "Opção inválida!" << std::endl;
- }
- switch(opt){
- case 1:{
- adicionarDocumento(fila);
- }
- break;
- case 2:{
- imprimir(fila);
- }
- break;
- case 3:
- return false;
- }
- }
- }
|