Skip to content

Instantly share code, notes, and snippets.

@werbet
Created May 4, 2016 21:26
Show Gist options
  • Save werbet/81fe54660542a7fb8281c6c6cfefc938 to your computer and use it in GitHub Desktop.
Save werbet/81fe54660542a7fb8281c6c6cfefc938 to your computer and use it in GitHub Desktop.
Lista de Funcionarios
#include <iostream>
#include <stdio.h>
using namespace std;
class Funcionario
{
private:
int matricula;
char* cpf;
char* nome;
public:
Funcionario(int matricula, char* cpf, char* nome)
{
this->matricula = matricula;
this->cpf = cpf;
this->nome = nome;
}
void imprimir()
{
printf("%s tem matricula %d e cpf %s\n", nome, matricula, cpf);
}
};
class No
{
private:
Funcionario* valor;
No* proximo;
public:
No()
{
this->valor = NULL;
this->proximo = NULL;
}
No(Funcionario* valor)
{
this->valor = valor;
this->proximo = NULL;
}
void imprimir()
{
this->valor->imprimir();
}
void setValor(Funcionario* valor)
{
this-> valor = valor;
}
Funcionario* getValor()
{
return this->valor;
}
void setProximo(No* proximo)
{
this->proximo = proximo;
}
No* getProximo()
{
return this->proximo;
}
};
class Lista
{
private:
No* primeiro;
public:
Lista()
{
this->primeiro = new No();
}
Lista(Funcionario* valor)
{
this->primeiro = new No(valor);
}
void inserirInicio(Funcionario* valor)
{
No* novo = new No(valor);
novo->setProximo(this->primeiro);
this->primeiro = novo;
}
void imprimir()
{
No* aux;
aux = this->primeiro;
while(aux != NULL)
{
aux->imprimir();
aux = aux->getProximo();
}
}
~Lista()
{
No* aux;
aux = this->primeiro;
while(aux != NULL)
{
No* anterior = aux;
aux = aux->getProximo();
//anterior->imprimir();
delete anterior;
}
}
};
int main()
{
int n;
int matricula;
Lista* lista = new Lista(new Funcionario(1, "000001", "Airton Queiroz"));
printf("Digite a quantidade de funcionarios: \n");
scanf("%d", &n);
do
{
printf("Digite a matricula do funcionario: \n");
scanf("%d", &matricula);
lista->inserirInicio(new Funcionario(matricula, "6789", "Eriko"));
n--;
}while(n > 0);
lista->imprimir();
delete lista;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment