Last active
May 5, 2016 15:39
-
-
Save KaeLL/6050345 to your computer and use it in GitHub Desktop.
Primeira versão de alterações!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
#define NOMINMAX | |
#include <Windows.h> | |
using namespace std; | |
bool validateInput( string ); | |
void start(); | |
void editar(); | |
void consultar_todos(); | |
void consultar_atual(); | |
void apagar(); | |
void cls(); | |
int main() | |
{ | |
ios_base::sync_with_stdio( false ); | |
start(); | |
} | |
bool validateInput( string num ) | |
{ | |
for ( unsigned short i = 0; i < num.size(); ++i ) | |
if ( num[ i ] < 48 || num[ i ] > 57 ) | |
return false; | |
return true; | |
} | |
void start() | |
{ | |
char op; | |
do | |
{ | |
cout << "Qual das Opcoes Abaixo voce deseja?\n\n" | |
"1 - Editar Numero de Despacho Atual\n\n" | |
"2 - Consultar Documentos de Despacho Anteriores\n\n" | |
"3 - Consultar Proximo Numero de Despacho\n\n" | |
"4 - Apagar Registro de Despacho\n\n" | |
"5 - Sair do Aplicativo\n\n"; | |
cin >> op; | |
cls(); | |
switch ( op ) | |
{ | |
case '1': | |
editar(); | |
break; | |
case '2': | |
consultar_todos(); | |
break; | |
case '3': | |
consultar_atual(); | |
break; | |
case '4': | |
apagar(); | |
break; | |
case '5': | |
exit( 0 ); | |
break; | |
default: | |
cout << "\a\nOpcao Invalida!\nDigite novamente\n\n"; | |
} | |
} while ( true ); | |
} | |
void editar() | |
{ | |
char a; | |
string num, name, subject; | |
ofstream outfile; | |
outfile.open( "test.txt", ios::app | ios::out ); | |
do | |
{ | |
if ( outfile.is_open() && outfile.good() ) | |
{ | |
cout << "Numero do Despacho: "; | |
while ( cin >> num && !validateInput( num ) ) | |
cout << "\nEste campo deve ser preenchido com valor numerico, tente novamente.\n\n" | |
"Numero do Despacho: "; | |
} | |
cin.ignore( numeric_limits < streamsize >::max(), '\n' ); | |
cout << "Nome do Enderecado: "; | |
getline( cin, name ); | |
cout << "Assunto do Documento: "; | |
getline( cin, subject ); | |
outfile << num << '\n' << name << '\n' << subject << endl; | |
cout << "\nDeseja inserir mais documentos de despacho? [S/N]\n"; | |
cin >> a; | |
} while ( a != 'n' && a != 'N' ); | |
outfile.close(); | |
} | |
void consultar_todos() | |
{ | |
stringstream num; | |
ifstream infile; | |
infile.open( "test.txt" ); | |
if ( infile.is_open() && infile.good() ) | |
{ | |
while ( infile.good() ) | |
num << infile.get(); | |
string resultado; | |
num >> resultado; | |
cout << resultado; | |
infile.close(); | |
} | |
} | |
void consultar_atual() | |
{ | |
string num; | |
ifstream infile; | |
infile.open( "test.txt" ); | |
if ( infile.is_open() && infile.good() ) | |
{ | |
infile >> num; | |
while ( !infile.fail() ) | |
{ | |
cout << num << endl; | |
getline( infile, num ); | |
} | |
infile.close(); | |
} | |
} | |
void apagar() | |
{ | |
char b; | |
cout << "\nISSO REMOVERA TODOS OS REGISTROS DE DESPACHO, prosseguir? 1 - Sim|2 - Nao\n"; | |
cin >> b; | |
cin.ignore(); | |
switch ( b ) | |
{ | |
case '1': | |
remove( "test.txt" ); | |
cout << "\nRegistro excluido com sucesso.\n"; | |
getchar(); | |
break; | |
case '2': | |
cout << "\nOs dados nao foram removidos.\n"; | |
getchar(); | |
break; | |
default: | |
cout << "\a\nOpcao Invalida!\n\n"; | |
getchar(); | |
break; | |
} | |
} | |
void cls() | |
{ | |
COORD coordScreen = | |
{ 0, 0 }; | |
DWORD cCharsWritten; | |
CONSOLE_SCREEN_BUFFER_INFO csbi; | |
DWORD dwConSize; | |
if ( !GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &csbi ) ) return; | |
dwConSize = csbi.dwSize.X * csbi.dwSize.Y; | |
if ( !FillConsoleOutputCharacter( GetStdHandle( STD_OUTPUT_HANDLE ), ( TCHAR ) ' ', dwConSize, coordScreen, &cCharsWritten ) ) return; | |
if ( !GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &csbi )) return; | |
if ( !FillConsoleOutputAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten ) ) return; | |
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coordScreen ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment