Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
#include <iostream> #include <string> using namespace std; int menu(){ int opcao; cout << "===============================================" << endl; cout << "| MENU |" << endl; cout << "===============================================" << endl; cout << "| 1-> CADASTRAR EMPREGADO. |" << endl; cout << "| 2-> IMPRIMIR LISTA POR MATRICULA |" << endl; cout << "| 3-> IMPRIMIR LISTA POR NOME |" << endl; cout << "| 4-> REMOVER EMPREGADO . |" << endl; cout << "| 5-> ALTERAR DADOS DO EMPREGADO. |" << endl; cout << "| 6-> CONSULTAR DADOS PELA MATRICULA. |" << endl; cout << "| 7-> CONSULTAR DADOS PELO NOME . |" << endl; cout << "| 8-> SAIR. |" << endl; cout << "===============================================" << endl; cout <<endl<< "ESCOLHA UMA OPÇÃO: "; cin >> opcao; system("cls"); return opcao; } struct func { int matricula; string nome; float salario; }; struct tno { func cadastro; tno *prox; }; struct tlista { tno *primeiro; }; void inicializa(tlista &lista){ lista.primeiro = NULL; } tno* busca_lista_matricula(tlista lista, int x){ tno *aux = lista.primeiro; while (aux != NULL){ if (aux->cadastro.matricula == x) return aux; aux = aux->prox; } return NULL; } tno* busca_lista_nome(tlista lista, string x){ tno *aux = lista.primeiro; while (aux != NULL){ if (aux->cadastro.nome == x) return aux; aux = aux->prox; } return NULL; } void consulta_mat(tlista lista, int mat){ if(lista.primeiro == NULL){ cout<<"LISTA VAZIA!!!"<<endl; return; } tno *aux = busca_lista_matricula(lista, mat); if(aux == NULL){ cout << "EMPREGADO NÃO EXISTE!" << endl; return; } cout << "Matricula: " << aux->cadastro.matricula << endl << "Nome: " << aux->cadastro.nome << endl << "Salario: " << aux->cadastro.salario << endl; } void consulta_nome(tlista lista, string mat){ if (lista.primeiro == NULL){ cout << "LISTA VAZIA!!!" << endl; return; } tno *aux = busca_lista_nome(lista, mat); if (aux == NULL){ cout << "EMPREGADO NÃO EXISTE!" << endl; return; } cout << "Matricula: " << aux->cadastro.nome << endl << "Nome: " << aux->cadastro.matricula << endl << "Salario: " << aux->cadastro.salario << endl; } void inserir_matricula(tlista &lista, func x){ tno *no, *aux; no = new tno; if (no == NULL){ cout << "ATENÇÂO!!! (ERRO) " << endl; return; } no->cadastro = x; no->prox = NULL; if (lista.primeiro == NULL) lista.primeiro = no; else{ aux = lista.primeiro; while (aux->prox != NULL) aux = aux->prox; aux->prox = no; } } void remove(tlista &lista, int mat) { tno *remover = busca_lista_matricula(lista, mat); if (remover == NULL){ cout << "MATRICULA NÃO EXISTE!!!" << endl; return; } if (lista.primeiro == remover){ lista.primeiro = remover->prox; delete remover; } else{ tno *anterior = lista.primeiro; while (anterior->prox != remover) anterior = anterior->prox; anterior->prox = remover->prox; delete remover; } } void altera_lista(tlista &lista, int mat){ tno *aux = busca_lista_matricula(lista, mat); func novo; if (aux == NULL){ cout << "MATRICULA NÃO EXISTE!!!" << endl; return; } cout << "Nova Matricula: "; cin >> novo.matricula; if (busca_lista_matricula(lista, novo.matricula) != NULL){ cout << "MATRICULA JÁ EXISTE!!!" << endl; return; } cout << "Novo Nome: "; cin >> novo.nome; cout << "Novo Salario: "; cin >> novo.salario; aux->cadastro = novo; } void listar_matricula(tlista lista){ tno *no = lista.primeiro; while (no != NULL){ tno *menor = no; tno *no2 = no->prox; while (no2 != NULL){ if (no2->cadastro.matricula < menor->cadastro.matricula){ menor = no2; } no2 = no2->prox; } int aux = no -> cadastro.matricula; no->cadastro.matricula = menor->cadastro.matricula; menor->cadastro.matricula = aux; no = no->prox; } } void listar_nome(tlista lista){ tno *no = lista.primeiro; while (no != NULL){ tno *menor = no; tno *no2 = no->prox; while (no2 != NULL){ if (no2->cadastro.nome < menor->cadastro.nome){ menor = no2; } no2 = no2->prox; } string aux = no->cadastro.nome; no->cadastro.nome = menor->cadastro.nome; menor->cadastro.nome = aux; no = no->prox; } } void imprime(tlista lista,int x){ if (lista.primeiro == NULL){ cout << "LISTA ESTA VAZIA!" << endl; return; } char s; do{ if (x == 2){ listar_matricula(lista); } else{ listar_nome(lista); } for (tno *aux = lista.primeiro; aux != NULL; aux = aux->prox){ cout << endl << "===============================================" << endl << "MATRICULA :" << aux->cadastro.matricula << endl << "NOME :" << aux->cadastro.nome << endl << "SALARIO :" << aux->cadastro.salario << endl << "===============================================" << endl; } cout << "Deseja Sair S/N: "; cin >> s; } while (s != 's'); } int main(){ setlocale(LC_ALL, "Portuguese"); tlista lista; inicializa(lista); func dados; int opcao; do{ opcao = menu(); switch (opcao){ case 1: cout << "Matricula: "; cin >> dados.matricula; if (busca_lista_matricula(lista, dados.matricula) != NULL){ cout << "EMPREGADO JÁ CADASTRADO" << endl; } else{ cout << "Nome: "; cin >> dados.nome; cout << "Salario: "; cin >> dados.salario; inserir_matricula(lista, dados); } break; case 2: imprime(lista,opcao); break; case 3: imprime(lista,opcao); break; case 4: int c; cout << "Digite o Numero da Natricula: "; cin >> c; remove(lista, c); break; case 5: int x; cout << "Digite Numero da Matricula: " << endl; cin >> x; altera_lista(lista, x); break; case 6: int a; cout << "Digite Numero da Matricula: "; cin >> a; consulta_mat(lista, a); break; case 7: string b; cout << "Iforme o Nome do Empregado: "; cin >> b; consulta_nome(lista, b); break; } } while (opcao != 8); system("pause"); return 0; }
Compartilhar