Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SistemaCadastro.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <locale.h>
- #include <stdio.h>
- #include <Windows.h>
- #include <stdlib.h>
- #include <io.h>
- int MenuPrincipal()
- {
- int Option = 0;
- printf("\t SISTEMA DE CADASTRO DE VEICULOS \n\n-> Selecione uma opção:\n1 para incluir um novo veículo\n2 para alterar um veículo\n3 para excluir um veículo\n4 para listar todos os veículos\n99 para finalizar o sistema!\nOpção desejada: ");
- scanf("%d", &Option);
- return Option;
- }
- int IncluirVeiculo()
- {
- return 0;
- }
- int AlterarVeiculo()
- {
- return 0;
- }
- int ExcluirVeiculo()
- {
- return 0;
- }
- int ListarVeiculos()
- {
- ListaDiretorio("C:\\Veiculos");
- return 0;
- }
- Veiculos ReadVeiculo(char* path)
- {
- Veiculos m;
- if (fileExists(path))
- {
- FILE* f = fopen(path, "r+");
- fread(&m, sizeof(Veiculos), 1, f);
- return m;
- }
- else
- {
- printf("\n\nVeiculo não cadastrado no banco de dados!");
- }
- }
- int WriteVeiculo(int CodigoVeiculo, char* NomeVeiculo, char* Modelo, char* Marca, float ConsumoGas, float ConsumoEta)
- {
- Veiculos m;
- char temp[128];
- sprintf(temp, "C:\\Veiculos\\%d.bin", CodigoVeiculo);
- if (fileExists(temp) == false)
- {
- FILE* f = fopen(temp, "a+");
- fwrite(&m, sizeof(Veiculos), 1, f);
- printf("\n\nVeiculo cadastrado com sucesso!\n\n");
- }
- else
- {
- printf("\n\nVeiculo já está cadastrado em nosso banco de dados!\n\n");
- }
- }
- bool fileExists(char *filename)
- {
- if (FILE *arq = fopen(filename, "r"))
- return true;
- return false;
- }
- bool ListaDiretorio(const char *sDir)
- {
- struct _finddata_t c_file;
- int hFind;
- char sPath[2048];
- //Specify a file mask. *.* = We want everything!
- sprintf(sPath, "%s\\*.*", sDir);
- hFind = _findfirst(sPath, &c_file);
- if (hFind == -1)
- {
- printf("Erro ao encontrar o diretorio: [%s]\n", sDir);
- return false;
- }
- do
- {
- //Find first file will always return "."
- // and ".." as the first two directories.
- if (strcmp(c_file.name, ".") != 0
- && strcmp(c_file.name, "..") != 0)
- {
- //Build up our file path using the passed in
- // [sDir] and the file/foldername we just found:
- sprintf(sPath, "%s\\%s", sDir, c_file.name);
- Veiculos m;
- m = ReadVeiculo(sPath);
- printf("Veiculo:\n\t %d \t %s \t %s \t %s \t %1.2f \t %1.2f\n", m.Codigo, m.Nome, m.Modelo, m.Marca, m.cGasolina, m.cEtanol);
- }
- } while (_findnext(hFind, &c_file)); //Find the next file.
- if (hFind != -1)
- _findclose(hFind);
- return true;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "Portuguese");
- int Option = 0;
- if (!fileExists("C:\\Veiculos\\check-in.txt"))
- {
- CreateDirectory((LPCWSTR)"C:\\Veiculos", NULL);
- FILE *fp = fopen("C:\\Veiculos\\check-in.txt", "rb");
- }
- do
- {
- Option = MenuPrincipal();
- switch (Option)
- {
- //Incluir
- case 1:
- {
- IncluirVeiculo();
- break;
- }
- //Alterar
- case 2:
- {
- AlterarVeiculo();
- break;
- }
- //Exluir
- case 3:
- {
- ExcluirVeiculo();
- break;
- }
- //Listar
- case 4:
- {
- ListarVeiculos();
- break;
- }
- case 99:
- {
- Option = 99;
- break;
- }
- default:
- {
- printf(">>> SELECIONE OUTRA OPÇÃO!\n\n");
- Option = 0;
- break;
- }
- }
- } while (Option != 99);
- printf("\nObrigado por usar nossos sistemas...\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement