Skip to content

Instantly share code, notes, and snippets.

@vinipsmaker
Created December 23, 2013 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinipsmaker/8090952 to your computer and use it in GitHub Desktop.
Save vinipsmaker/8090952 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Compra
{
float preco;
Compra *proxima;
};
struct Cliente
{
string nome;
Compra *compras;
};
vector<Cliente> clientes;
void menu()
{
cout << "Opções:\n"
" 1 - Ler clientes\n"
" 2 - Cadastrar cliente\n"
" 3 - Detalhar cliente\n"
" Q - Sair" << endl;
}
void ler_clientes()
{
if ( !clientes.size() ) {
cout << "Nenhum cliente cadastrado" << endl;
return;
}
cout << "Clientes:" << endl;
for ( vector<Cliente>::iterator it = clientes.begin(), end = clientes.end()
; it != end ; ++it ) {
cout << " Nome: " << it->nome << endl;
if ( it->compras )
cout << " Primeira compra: " << it->compras->preco << endl;
cout << " --" << endl;
}
}
void cadastrar_cliente()
{
cout << "Digite o nome do cliente:" << endl;
Cliente cliente;
cin >> cliente.nome;
clientes.push_back(cliente);
cout << "Cliente \"" << cliente.nome << "\" inserido com sucesso" << endl;
}
void detalhar_cliente()
{
cout << "detalhar_cliente()" << endl;
}
int main()
{
menu();
char opcao;
while ( cin >> opcao ) {
switch ( opcao ) {
case '1':
ler_clientes();
break;
case '2':
cadastrar_cliente();
break;
case '3':
detalhar_cliente();
break;
case 'q':
case 'Q':
return 0;
break;
}
menu();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment