Skip to content

Instantly share code, notes, and snippets.

@KaeLL
Last active May 5, 2016 15:39

Revisions

  1. KaeLL revised this gist May 5, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cls.h
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ void cls()
    {
    COORD coordScreen = { 0, 0 };
    DWORD dwConSize,
    cCharsWritten;
    cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    if ( !GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &csbi )) return;
  2. KaeLL revised this gist May 5, 2016. 2 changed files with 19 additions and 202 deletions.
    202 changes: 0 additions & 202 deletions Commit1.cpp
    Original file line number Diff line number Diff line change
    @@ -1,202 +0,0 @@

    #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 );
    }
    19 changes: 19 additions & 0 deletions cls.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@

    #include <Windows.h>

    void cls()
    {
    COORD coordScreen = { 0, 0 };
    DWORD dwConSize,
    cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    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 );
    }
  3. KaeLL created this gist Jul 21, 2013.
    202 changes: 202 additions & 0 deletions Commit1.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,202 @@

    #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 );
    }