assembly to cpp code example

Example: c++ to assembly

#include <iostream>
#include <fstream>

using namespace std;

#define FILENAME "data.bin"

void what_action();

void register_menu();
void login_menu();

void add_user(string username, string password);
bool check_user(string username, string password);

int main()
{
    what_action();
}

void what_action()
{
    short int input;

    cout << "1. Login\n2. Register" << endl;
    cin >> input;

    switch(input)
    {
        case 1:
        login_menu();
        break;

        case 2:
        register_menu();
        break;

        default:
        cout << "Type Again!" << endl;;
        what_action();
        break;
    }
}

void register_menu()
{
    string user, pw;
    int agree;
    
    cout << "Username: ";
    cin >> user;
    
    cout << "Password: ";
    cin >> pw;

    cout << "Have You Read our Agreement ? ( 1 = yes )";
    cin >> agree;

    switch(agree)
    {
        case 1:
        add_user(user, pw);
        break;

        default:
        cout << "Please Read our Agreement First !" << endl; 
        register_menu();
        break;
    }
}

void login_menu()
{
    string user, pw;
    
    cout << "Username: ";
    cin >> user;
    
    cout << "Password: ";
    cin >> pw;

    if(check_user(user, pw) == true)
        cout << "you have logged in succefully !" << endl;
    else
        cout << "Data is Wrong!" << endl;
}

void add_user(string username, string password)
{
    ofstream file;
    file.open(FILENAME, ios_base::app);

    file << username << "\n";
    file << password << "\n";

    file.close();
}

bool check_user(string username, string password)
{
    ifstream file;

    string line;
    bool what_to_return;

    file.open(FILENAME, ios_base::binary);

    if(file.is_open())
    {
        while(getline(file, line))
        {
            string usr, pw;

            usr = line;

            getline(file,line);

            pw = line;

            if(usr == username && password == pw)
            {
                what_to_return = true;
                break;
            }
            else
                what_to_return = false;
        }
    }

    return what_to_return;
}

Tags:

Cpp Example