اذهب إلى المحتوى

السؤال

نشر

عندما اقوم بعمل run للكود لا شئ يحدث في ال console

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;
const string ClientsFileName = "clients.txt";
const string UsersFileName = "users.txt";
stUser CurrentUser;

struct sClient
{
    string AccountNumber;
    string PinCode;
    string Name;
    string Phone;
    double AccountBalance;
    bool MarkForDelete = false;
};
struct stUser
{
    string UserName = "";
    string Password = "";
    int Permission = -1;
    bool MarkForDelete = false;
};
enum enMainMenuePermissions
{
    eAll = -1, pListClients = 1,
    pAddNewClient = 2, pDeleteClient = 4,
    pUpdateClient = 8, pFindClient = 16,
    pTransactions = 32, pManageUsers = 64
};
enum enMainMenueOptions
{
    eListClients = 1, eAddNewClient = 2,
    eDeleteClient = 3, eUpdateClient = 4,
    eFindClient = 5, eTransactions = 6,
    eManageUsers = 7, eLogOut = 8
};
enum enTransactionMenueOptions
{
    eDeposite = 1, eWithdrawal = 2,
    eTotalBalances = 3, eMainMenue = 4
};
enum enManageUsersMenueOptions
{
    eUsersList = 1, eAddUser = 2,
    eDeleteUser = 3, eUpdateUser = 4,
    eFindUser = 5, eMainMenueManage = 6
};


void ShowMainMenue();
void ShowTransactionScreen();
void Login();
void ShowManageUsersScreen();

vector<string> SplitString(string S1, string Delim)
{
    vector<string> vString;
    short pos = 0;
    string sWord; // define a string variable  

    // use find() function to get the position of the delimiters  
    while ((pos = S1.find(Delim)) != std::string::npos)
    {
        sWord = S1.substr(0, pos); // store the word   
        if (sWord != "")
        {
            vString.push_back(sWord);
        }

        S1.erase(0, pos + Delim.length());  /* erase() until positon and move to next word. */
    }

    if (S1 != "")
    {
        vString.push_back(S1); // it adds last word of the string.
    }

    return vString;

}

sClient ConvertClientLineRecord(string Line, string Seperator = "#//#")
{
    sClient Client;
    vector<string> vClientData;
    vClientData = SplitString(Line, Seperator);

    Client.AccountNumber = vClientData[0];
    Client.PinCode = vClientData[1];
    Client.Name = vClientData[2];
    Client.Phone = vClientData[3];
    Client.AccountBalance = stod(vClientData[4]);//cast string to double
    return Client;
}

stUser ConvertUserLineRecord(string Line, string Seperator = "#//#")
{
    stUser User;
    vector<string> vUserData;
    vUserData = SplitString(Line, Seperator);

    User.UserName = vUserData[0];
    User.Password = vUserData[1];
    User.Permission = stoi(vUserData[2]);

    return User;
}


string CovertClientRecordToLine(sClient Client, string Seperator = "#//#")
{

    string stClientRecord = "";
    stClientRecord += Client.AccountNumber + Seperator;
    stClientRecord += Client.PinCode + Seperator;
    stClientRecord += Client.Name + Seperator;
    stClientRecord += Client.Phone + Seperator;
    stClientRecord += to_string(Client.AccountBalance);
    return stClientRecord;
}

string CovertUserRecordToLine(stUser User, string Seperator = "#//#")
{

    string stUserRecord = "";
    stUserRecord += User.UserName + Seperator;
    stUserRecord += User.Password + Seperator;
    stUserRecord += to_string(User.Permission);

    return stUserRecord;
}

bool ClientExistsByAccountNumber(string AccountNumber, string FileName)
{

    vector <sClient> vClients;
    fstream MyFile;
    MyFile.open(FileName, ios::in);//read Mode

    if (MyFile.is_open())
    {
        string Line;
        sClient Client;

        while (getline(MyFile, Line))
        {
            Client = ConvertClientLineRecord(Line);
            if (Client.AccountNumber == AccountNumber)
            {
                MyFile.close();
                return true;
            }
            vClients.push_back(Client);
        }

        MyFile.close();

    }
    return false;
}
bool UserExistsByUserName(string UserName, string FileName)
{

    vector <stUser> vUsers;
    fstream MyFile;
    MyFile.open(FileName, ios::in);//read Mode

    if (MyFile.is_open())
    {
        string Line;
        stUser User;

        while (getline(MyFile, Line))
        {
            User = ConvertUserLineRecord(Line);
            if (User.UserName == UserName)
            {
                MyFile.close();
                return true;
            }
            vUsers.push_back(User);
        }

        MyFile.close();

    }
    return false;
}
sClient ReadNewClient()
{
    sClient Client;
    cout << "Enter Account Number? ";

    // Usage of std::ws will extract allthe whitespace character
    getline(cin >> ws, Client.AccountNumber);

    while (ClientExistsByAccountNumber(Client.AccountNumber, ClientsFileName))
    {
        cout << "\nClient with [" << Client.AccountNumber << "] already exists, Enter another Account Number? ";
        getline(cin >> ws, Client.AccountNumber);
    }

    cout << "Enter PinCode? ";
    getline(cin, Client.PinCode);

    cout << "Enter Name? ";
    getline(cin, Client.Name);

    cout << "Enter Phone? ";
    getline(cin, Client.Phone);

    cout << "Enter AccountBalance? ";
    cin >> Client.AccountBalance;

    return Client;
}
int ReadPermissionsToSet()
{
    int Permissions = 0;
    char Answer = 'N';

    cout << "Do you want to give the user all permissions? ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
        return -1;
    
    cout << "Do you want to give the user access to: " << endl;
    cout << "Show Clients Lists y/n? ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
        Permissions += enMainMenuePermissions::pListClients;
    
    cout << "Add New Client y/n? ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
        Permissions += enMainMenuePermissions::pAddNewClient;

    cout << "Delete Client y/n? ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
        Permissions += enMainMenuePermissions::pDeleteClient;
    
    cout << "Update Client y/n? ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
        Permissions += enMainMenuePermissions::pUpdateClient;

    cout << "Find Client y/n? ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
        Permissions += enMainMenuePermissions::pFindClient;

    cout << "Transactions y/n? ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
        Permissions += enMainMenuePermissions::pTransactions;

    cout << "Manage Users y/n? ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
        Permissions += enMainMenuePermissions::pManageUsers;

}
stUser ReadNewUser()
{
    stUser User;
    cout << "Enter User Name? ";

    // Usage of std::ws will extract allthe whitespace character
    getline(cin >> ws, User.UserName);

    while (UserExistsByUserName(User.UserName, UsersFileName))
    {
        cout << "\nUser with [" << User.UserName << "] already exists, Enter another User Name ? ";
        getline(cin >> ws, User.UserName);
    }

    cout << "Enter Password? ";
    getline(cin, User.Password);

    char Choice = 'N';
    cout << "Do You want to give the user full permistions ?" << endl;
    cin >> Choice;

    User.Permission = ReadPermissionsToSet();

    return User;
}

vector <sClient> LoadCleintsDataFromFile(string FileName)
{
    vector <sClient> vClients;
    fstream MyFile;
    MyFile.open(FileName, ios::in);//read Mode

    if (MyFile.is_open())
    {
        string Line;
        sClient Client;

        while (getline(MyFile, Line))
        {
            Client = ConvertClientLineRecord(Line);
            vClients.push_back(Client);
        }
        MyFile.close();
    }
    return vClients;
}
vector <stUser> LoadUsersDataFromFile(string FileName)
{
    vector <stUser> vUsers;
    fstream MyFile;
    MyFile.open(FileName, ios::in);//read Mode

    if (MyFile.is_open())
    {
        string Line;
        stUser User;

        while (getline(MyFile, Line))
        {
            User = ConvertUserLineRecord(Line);
            vUsers.push_back(User);
        }
        MyFile.close();
    }
    return vUsers;
}

void PrintClientRecordLine(sClient Client)
{
    cout << "| " << setw(15) << left << Client.AccountNumber;
    cout << "| " << setw(10) << left << Client.PinCode;
    cout << "| " << setw(40) << left << Client.Name;
    cout << "| " << setw(12) << left << Client.Phone;
    cout << "| " << setw(12) << left << Client.AccountBalance;
}
void PrintUserRecordLine(stUser User)
{
    cout << "| " << setw(20) << left << User.UserName;
    cout << "| " << setw(10) << left << User.Password;
    cout << "| " << setw(20) << left << User.Permission;
}

void ShowAllClientsScreen()
{
    vector <sClient> vClients = LoadCleintsDataFromFile(ClientsFileName);

    cout << "\n\t\t\t\t\tClient List (" << vClients.size() << ") Client(s).";
    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;

    cout << "| " << left << setw(15) << "Accout Number";
    cout << "| " << left << setw(10) << "Pin Code";
    cout << "| " << left << setw(40) << "Client Name";
    cout << "| " << left << setw(12) << "Phone";
    cout << "| " << left << setw(12) << "Balance";
    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;

    if (vClients.size() == 0)
        cout << "\t\t\t\tNo Clients Available In the System!";
    else

        for (sClient Client : vClients)
        {

            PrintClientRecordLine(Client);
            cout << endl;
        }

    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;
}
void ShowAllUsersScreen()
{
    vector <stUser> vUsers = LoadUsersDataFromFile(UsersFileName);
    cout << "\n\t\t\t\t\tClient List (" << vUsers.size() << ") Client(s).";
    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;

    cout << "| " << left << setw(20) << "UserName";
    cout << "| " << left << setw(10) << "Password";
    cout << "| " << left << setw(20) << "Permissions";
    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;

    if (vUsers.size() == 0)
        cout << "\t\t\t\tNo Users Available In the System!";
    else

        for (stUser User : vUsers)
        {

            PrintUserRecordLine(User);
            cout << endl;
        }

    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;
}
void PrintClientCard(sClient Client)
{
    cout << "\nThe following are the client details:\n";
    cout << "-----------------------------------";
    cout << "\nAccout Number: " << Client.AccountNumber;
    cout << "\nPin Code     : " << Client.PinCode;
    cout << "\nName         : " << Client.Name;
    cout << "\nPhone        : " << Client.Phone;
    cout << "\nAccount Balance: " << Client.AccountBalance;
    cout << "\n-----------------------------------\n";
}

bool FindClientByAccountNumber(string AccountNumber, vector <sClient> vClients, sClient& Client)
{
    for (sClient C : vClients)
    {

        if (C.AccountNumber == AccountNumber)
        {
            Client = C;
            return true;
        }

    }
    return false;
}

sClient ChangeClientRecord(string AccountNumber)
{
    sClient Client;

    Client.AccountNumber = AccountNumber;

    cout << "\n\nEnter PinCode? ";
    getline(cin >> ws, Client.PinCode);

    cout << "Enter Name? ";
    getline(cin, Client.Name);

    cout << "Enter Phone? ";
    getline(cin, Client.Phone);

    cout << "Enter AccountBalance? ";
    cin >> Client.AccountBalance;
    return Client;
}

bool MarkClientForDeleteByAccountNumber(string AccountNumber, vector <sClient>& vClients)
{

    for (sClient& C : vClients)
    {

        if (C.AccountNumber == AccountNumber)
        {
            C.MarkForDelete = true;
            return true;
        }

    }

    return false;
}

vector <sClient> SaveCleintsDataToFile(string FileName, vector <sClient> vClients)
{
    fstream MyFile;
    MyFile.open(FileName, ios::out);//overwrite

    string DataLine;

    if (MyFile.is_open())
    {
        for (sClient C : vClients)
        {

            if (C.MarkForDelete == false)
            {
                //we only write records that are not marked for delete.  
                DataLine = CovertClientRecordToLine(C);
                MyFile << DataLine << endl;
            }

        }

        MyFile.close();
    }

    return vClients;
}

void AddDataLineToFile(string FileName, string  stDataLine)
{
    fstream MyFile;
    MyFile.open(FileName, ios::in | ios::app);
    if (MyFile.is_open())
    {
       MyFile << stDataLine << endl;
       MyFile.close();
    }
}

void AddNewUser()
{
    stUser User;
    User = ReadNewUser();
    AddDataLineToFile(UsersFileName, CovertUserRecordToLine(User));
}
void AddNewClient()
{
    sClient Client;
    Client = ReadNewClient();
    AddDataLineToFile(ClientsFileName, CovertClientRecordToLine(Client));
}

void AddNewClients()
{
    char AddMore = 'Y';
    do
    {
        cout << "Adding New Client:\n\n";

        AddNewClient();
        cout << "\nClient Added Successfully, do you want to add more clients? Y/N? ";
        cin >> AddMore;

    } while (toupper(AddMore) == 'Y');

}
void AddNewUsers()
{
    char AddMore = 'Y';
    do
    {
        //system("cls");
        cout << "Adding New User:\n\n";

        AddNewUser();
        cout << "\nClient Added Successfully, do you want to add more Users? Y/N? ";
        cin >> AddMore;

    } while (toupper(AddMore) == 'Y');

}

bool DeleteClientByAccountNumber(string AccountNumber, vector <sClient>& vClients)
{
    sClient Client;
    char Answer = 'n';

    if (FindClientByAccountNumber(AccountNumber, vClients, Client))
    {

        PrintClientCard(Client);

        cout << "\n\nAre you sure you want delete this client? y/n ? ";
        cin >> Answer;
        if (Answer == 'y' || Answer == 'Y')
        {
            MarkClientForDeleteByAccountNumber(AccountNumber, vClients);
            SaveCleintsDataToFile(ClientsFileName, vClients);

            //Refresh Clients 
            vClients = LoadCleintsDataFromFile(ClientsFileName);

            cout << "\n\nClient Deleted Successfully.";
            return true;
        }

    }
    else
    {
        cout << "\nClient with Account Number (" << AccountNumber << ") is Not Found!";
        return false;
    }
}
bool FindUserByUserName(string UserName,vector <stUser> vUsers,stUser &User)
{
    for (stUser U : vUsers)
    {

        if (U.UserName == UserName)
        {
            User = U;
            return true;
        }

    }
    return false;
}
void PrintUserCard(stUser User)
{
    cout << "\nThe following are the User details:\n";
    cout << "-----------------------------------";
    cout << "\nUsername : " << User.UserName;
    cout << "\nPin Code     : " << User.Password;
    cout << "\n-----------------------------------\n";
}
bool MarkUserForDeleteByUserName(string UserName, vector <stUser>& vUsers)
{

    for (stUser& U : vUsers)
    {

        if (U.UserName == UserName)
        {
            U.MarkForDelete = true;
            return true;
        }

    }

    return false;
}
vector <stUser> SaveUsersDataToFile(string FileName, vector <stUser> vUsers)
{
    fstream MyFile;
    MyFile.open(FileName, ios::out);//overwrite

    string DataLine;

    if (MyFile.is_open())
    {
        for (stUser U : vUsers)
        {

            if (U.MarkForDelete == false)
            {
                //we only write records that are not marked for delete.  
                DataLine = CovertUserRecordToLine(U);
                MyFile << DataLine << endl;
            }

        }

        MyFile.close();
    }

    return vUsers;
}
bool DeleteUserByUserName(string UserName, vector <stUser>& vUsers)
{
    stUser User;
    char Answer = 'n';

    if (FindUserByUserName(UserName, vUsers, User))
    {

        PrintUserCard(User);

        cout << "\n\nAre you sure you want delete this User? y/n ? ";
        cin >> Answer;
        if (Answer == 'y' || Answer == 'Y')
        {
            MarkUserForDeleteByUserName(UserName, vUsers);
            SaveUsersDataToFile(UsersFileName, vUsers);

            //Refresh Clients 
            vUsers = LoadUsersDataFromFile(UsersFileName);

            cout << "\nUser Deleted Successfully.";
            return true;
        }

    }
    else
    {
        cout << "User with Account Number (" << UserName << ") is Not Found!";
        return false;
    }
}
bool UpdateClientByAccountNumber(string AccountNumber, vector <sClient>& vClients)
{

    sClient Client;
    char Answer = 'n';

    if (FindClientByAccountNumber(AccountNumber, vClients, Client))
    {

        PrintClientCard(Client);
        cout << "\n\nAre you sure you want update this client? y/n ? ";
        cin >> Answer;
        if (Answer == 'y' || Answer == 'Y')
        {
            for (sClient& C : vClients)
            {
                if (C.AccountNumber == AccountNumber)
                {
                    C = ChangeClientRecord(AccountNumber);
                    break;
                }
            }

            SaveCleintsDataToFile(ClientsFileName, vClients);

            cout << "\n\nClient Updated Successfully.";
            return true;
        }

    }
    else
    {
        cout << "\nClient with Account Number (" << AccountNumber << ") is Not Found!";
        return false;
    }
}

string ReadClientAccountNumber()
{
    string AccountNumber = "";

    cout << "\nPlease enter AccountNumber? ";
    cin >> AccountNumber;
    return AccountNumber;

}

void ShowDeleteClientScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tDelete Client Screen";
    cout << "\n-----------------------------------\n";

    vector <sClient> vClients = LoadCleintsDataFromFile(ClientsFileName);
    string AccountNumber = ReadClientAccountNumber();
    DeleteClientByAccountNumber(AccountNumber, vClients);
}
string ReadUserName()
{
    string UserName = "";

    cout << "\nPlease enter Username? ";
    cin >> UserName;
    return UserName;
}
void ShowDeleteUserScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tDelete User Screen";
    cout << "\n-----------------------------------\n";

    vector <stUser> vUsers = LoadUsersDataFromFile(UsersFileName);
    string UserName = ReadUserName();
    DeleteUserByUserName(UserName, vUsers);
}
void ShowUpdateClientScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tUpdate Client Info Screen";
    cout << "\n-----------------------------------\n";

    vector <sClient> vClients = LoadCleintsDataFromFile(ClientsFileName);
    string AccountNumber = ReadClientAccountNumber();
    UpdateClientByAccountNumber(AccountNumber, vClients);

}
stUser ChangeUserRecord()
{
    stUser User;

    cout << "\n\nEnter Username? ";
    getline(cin >> ws,User.UserName );

    cout << "Enter Password? ";
    getline(cin, User.Password);

    User.Permission = ReadPermissionsToSet();

    return User;
}
bool UpdateUserByUserName(string UserName, vector <stUser>& vUsers)
{

    stUser User;
    char Answer = 'n';

    if (FindUserByUserName(UserName, vUsers, User))
    {

        PrintUserCard(User);
        cout << "\n\nAre you sure you want update this user? y/n ? ";
        cin >> Answer;
        if (Answer == 'y' || Answer == 'Y')
        {
            for (stUser& U : vUsers)
            {
                if (U.UserName == UserName)
                {
                    U = ChangeUserRecord();
                    break;
                }
            }

            SaveUsersDataToFile(UsersFileName, vUsers);

            cout << "\n\nUser Updated Successfully.";
            return true;
        }

    }
    else
    {
        cout << "\nUser with Username (" << UserName << ") is Not Found!";
        return false;
    }
}
void ShowUpdateUserScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tUpdate User Info Screen";
    cout << "\n-----------------------------------\n";

    vector <stUser> vUsers = LoadUsersDataFromFile(UsersFileName);
    string UserName = ReadUserName();
    UpdateUserByUserName(UserName, vUsers);

}
void ShowAddNewClientsScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tAdd New Clients Screen";
    cout << "\n-----------------------------------\n";

    AddNewClients();
}
void ShowAddNewUsersScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tAdd New User Screen";
    cout << "\n-----------------------------------\n";

    AddNewUsers();
}

void ShowFindClientScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tFind Client Screen";
    cout << "\n-----------------------------------\n";

    vector <sClient> vClients = LoadCleintsDataFromFile(ClientsFileName);
    sClient Client;
    string AccountNumber = ReadClientAccountNumber();
    if (FindClientByAccountNumber(AccountNumber, vClients, Client))
        PrintClientCard(Client);
    else
        cout << "\nClient with Account Number[" << AccountNumber << "] is not found!";
}
void ShowFindUserScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tFind User Screen";
    cout << "\n-----------------------------------\n";

    vector <stUser> vUsers = LoadUsersDataFromFile(UsersFileName);
    stUser User;
    string UserName = ReadUserName();
    if (FindUserByUserName(UserName, vUsers, User))
        PrintUserCard(User);
    else
        cout << "\nUser with User name [" << UserName << "] is not found!";
}
void ShowEndScreen()
{
    cout << "\n-----------------------------------\n";
    cout << "\tProgram Ends :-)";
    cout << "\n-----------------------------------\n";
}


void GoBackToMainMenue()
{
    cout << "\n\nPress any key to go back to Main Menue...";
    system("pause>0");
    ShowMainMenue();

}

void GoBackToManageUsers()
{
    cout << "\n\nPress any key to go back to Manage Menue...";
    system("pause>0");
    ShowManageUsersScreen();
}

void GoBackToTransactionMenue()
{
    cout << "\n\nPress any key to go back to Transcraption menue...";
    system("pause>0");
    ShowTransactionScreen();

}
short ReadMainMenueOption()
{
    cout << "Choose what do you want to do? [1 to 8]? ";
    short Choice = 0;
    cin >> Choice;

    return Choice;
}
short ReadTransactionMenueOption()
{
    cout << "Choose what do you want to do? [1 to 4]? ";
    short Choice = 0;
    cin >> Choice;

    return Choice;
}
void DepositBalanceToClientByAccountNumber(string AccountNumber, double Amount, vector <sClient> vClients)
{
    char Answer = 'n';

    cout << "Are you sure you wanna perform this transaction ? Y/y ";
    cin >> Answer;

    if (Answer == 'Y' || Answer == 'y')
    {
        for (sClient& C : vClients)
        {
            if (C.AccountNumber == AccountNumber)
            {
                C.AccountBalance += Amount;
                SaveCleintsDataToFile(ClientsFileName, vClients);
                cout << "\n\nDone Successfully, new Balance is: " << C.AccountBalance;
            }
        }
    }

}
void ShowDepositeScreen()
{
    cout << "==================\n";
    cout << "Deposite Screen\n";
    cout << "==================\n";

    sClient Client;
    vector <sClient> vClients = LoadCleintsDataFromFile(ClientsFileName);
    string AccountNumber = ReadClientAccountNumber();

    while (!FindClientByAccountNumber(AccountNumber, vClients, Client))
    {
        cout << "Client with number (" << AccountNumber << ") is not exist .\n";
        AccountNumber = ReadClientAccountNumber();
    }

    PrintClientCard(Client);

    double Amount;
    cout << "Please enter deposit amount? ";
    cin >> Amount;
    DepositBalanceToClientByAccountNumber(AccountNumber, Amount, vClients);
}
void ShowWithDrawalScreen()
{
    cout << "==================\n";
    cout << "WithDrawal Screen\n";
    cout << "==================\n";

    sClient Client;
    vector <sClient> vClients = LoadCleintsDataFromFile(ClientsFileName);
    string AccountNumber = ReadClientAccountNumber();

    while (!FindClientByAccountNumber(AccountNumber, vClients, Client))
    {
        cout << "Client with number (" << AccountNumber << ") is not exist .\n";
        AccountNumber = ReadClientAccountNumber();
    }

    PrintClientCard(Client);

    double Amount;
    cout << "Please enter deposit amount? ";
    cin >> Amount;
    while (Amount > Client.AccountBalance)
    {
        cout << "Amount Exceeds the balance, you can withdraw up to " << Client.AccountBalance << endl;
        cout << "Please,Enter another Amount: ";
        cin >> Amount;
    }
    DepositBalanceToClientByAccountNumber(AccountNumber, Amount * -1, vClients);

}
void PrintClientRecordBalanceLine(sClient Client)
{
    cout << "| " << setw(15) << left << Client.AccountNumber;
    cout << "| " << setw(40) << left << Client.Name;
    cout << "| " << setw(12) << left << Client.AccountBalance;
    cout << endl;
}
void ShowTotalBalances()
{
    vector <sClient> vClients = LoadCleintsDataFromFile(ClientsFileName);

    cout << "\n\t\t\t\t\Balance List (" << vClients.size() << ") Client(s).";
    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;

    cout << "| " << left << setw(15) << "Accout Number";
    cout << "| " << left << setw(40) << "Client Name";
    cout << "| " << left << setw(12) << "Balance";
    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;

    double TotalBalnces = 0;
    if (vClients.size() == 0)
        cout << "\t\tNo Clients Available In the System!";
    else
    {
        for (sClient Client : vClients)
        {
            PrintClientRecordBalanceLine(Client);
            TotalBalnces += Client.AccountBalance;
        }
    }


    cout << "\n_______________________________________________________";
    cout << "_________________________________________\n" << endl;
    cout << "\t\t\t\tTotal Balances = " << TotalBalnces << endl;
}
void PerformTransactionMenueOption(enTransactionMenueOptions TransactionMenueOption)
{
    switch (TransactionMenueOption)
    {
    case enTransactionMenueOptions::eDeposite:
        system("cls");
        ShowDepositeScreen();
        GoBackToTransactionMenue();
        break;
    case enTransactionMenueOptions::eWithdrawal:
        system("cls");
        ShowWithDrawalScreen();
        GoBackToTransactionMenue();
        break;
    case enTransactionMenueOptions::eTotalBalances:
        system("cls");
        ShowTotalBalances();
        GoBackToTransactionMenue();
        break;
    case enTransactionMenueOptions::eMainMenue:
        GoBackToMainMenue();
    }
}

void ShowTransactionScreen()
{
    system("cls");
    cout << "===============================\n";
    cout << "[1] Deposite.\n";
    cout << "[2] Withdrawal.\n";
    cout << "[3] Total Balances.\n";
    cout << "[4] Main Menue.\n";
    cout << "===============================\n";
    PerformTransactionMenueOption((enTransactionMenueOptions)ReadTransactionMenueOption());
}
short ReadManageUsersMenueOptions()
{
    cout << "Choose what do you want to do? [1 to 6]? ";
    short Choice = 0;
    cin >> Choice;

    return Choice;
}
void PerformMangeUsersMenueOption(enManageUsersMenueOptions MangeUsersOption)
{
    switch (MangeUsersOption)
    {
    case enManageUsersMenueOptions::eUsersList:
        system("cls");
        ShowAllUsersScreen();
        GoBackToManageUsers();
        break;
    case enManageUsersMenueOptions::eAddUser:
        system("cls");
        ShowAddNewUsersScreen();
        GoBackToManageUsers();
        break;
    case enManageUsersMenueOptions::eDeleteUser:
        ShowDeleteUserScreen();
        GoBackToManageUsers();
        break;
    case enManageUsersMenueOptions::eUpdateUser:
        ShowUpdateUserScreen();
        GoBackToManageUsers();
        break;
    case enManageUsersMenueOptions::eFindUser:
        ShowFindUserScreen();
        GoBackToManageUsers();
        break;
    case eMainMenueManage:
        system("cls");
        ShowMainMenue();
        break;
    }
}
void ShowManageUsersScreen()
{
    system("cls");
    cout << "===========================================\n";
    cout << "\t\tManage Users Menue Screen\n";
    cout << "===========================================\n";
    cout << "[1] Users List\n";
    cout << "[2] Add New User\n";
    cout << "[3] Delete User\n";
    cout << "[4] Update User.\n";
    cout << "[5] Find User.\n";
    cout << "[6] Main Menue.\n";
    cout << "===========================================\n";

    PerformMangeUsersMenueOption((enManageUsersMenueOptions)ReadManageUsersMenueOptions());
}
void PerfromMainMenueOption(enMainMenueOptions MainMenueOption)
{
    switch (MainMenueOption)
    {
    case enMainMenueOptions::eListClients:
    {
        system("cls");
        ShowAllClientsScreen();
        GoBackToMainMenue();
        break;
    }
    case enMainMenueOptions::eAddNewClient:
        system("cls");
        ShowAddNewClientsScreen();
        GoBackToMainMenue();
        break;

    case enMainMenueOptions::eDeleteClient:
        system("cls");
        ShowDeleteClientScreen();
        GoBackToMainMenue();
        break;

    case enMainMenueOptions::eUpdateClient:
        system("cls");
        ShowUpdateClientScreen();
        GoBackToMainMenue();
        break;

    case enMainMenueOptions::eFindClient:
        system("cls");
        ShowFindClientScreen();
        GoBackToMainMenue();
        break;

    case enMainMenueOptions::eTransactions:
        system("cls");
        ShowTransactionScreen();
        break;
    case enMainMenueOptions::eManageUsers:
        system("cls");
        ShowManageUsersScreen();
        break;
    case enMainMenueOptions::eLogOut:
        system("cls");
        Login();
        break;

    }
}

void ShowMainMenue()
{
    system("cls");
    cout << "===========================================\n";
    cout << "\t\tMain Menue Screen\n";
    cout << "===========================================\n";
    cout << "\t[1] Show Client List.\n";
    cout << "\t[2] Add New Client.\n";
    cout << "\t[3] Delete Client.\n";
    cout << "\t[4] Update Client Info.\n";
    cout << "\t[5] Find Client.\n";
    cout << "\t[6] Transactions.\n";
    cout << "\t[7] Manage users\n";
    cout << "\t[8] Log out\n";
    cout << "===========================================\n";
    PerfromMainMenueOption((enMainMenueOptions)ReadMainMenueOption());
}
bool FindUserByUsernameAndPassword(string UserName,string Password,stUser& User)
{
    vector <stUser> vUsers = LoadUsersDataFromFile(UsersFileName);
    for (stUser& U : vUsers)
    {
        if (UserName == U.UserName && Password == U.Password)
        {
            User = U;
            return true;
        }
    }
    return false;
}
bool LoadUserInfo(string UserName,string Password)
{
    if (FindUserByUsernameAndPassword(UserName, Password, CurrentUser))
        return true;
    else
        return false;
}
void Login()
{
    bool LoginFail = false;
    string UserName, Password;

    do
    {
        system("cls");
        cout << "-----------------------------------------" << endl;
        cout << "\t\tLogin Screen" << endl;
        cout << "-----------------------------------------" << endl;
        
        if (LoginFail)
        {
            cout << "Invalid username/password ." << endl;
        }

        cout << "Entr username? ";
        cin >> UserName;
        
        cout << "Entr password? ";
        cin >> Password;

        LoginFail = !LoadUserInfo(UserName,Password);
    } while (LoginFail);
}

int main()
{
    Login();
    system("pause>0");
    return 0;
}

 

Recommended Posts

  • 0
نشر
بتاريخ 17 ساعة قال محمد الديب9:
stUser CurrentUser;

الخطأ هنا في السطر رقم 10 .

حيث أن كود ال c++ يتم تنفيذه بالترتيب أى سطر بعد سطر و هنا انت تقوم باستخدام النوع stUser قبل تعريفه فى سطر 21 . 

لذلك الحل هو نقل سطر 10 إلى ما بعد تعريف ال struct stUser اى ما بعد سطر 27 .

  • 0
نشر
بتاريخ 6 ساعة قال محمد عاطف11:

الخطأ هنا في السطر رقم 10 .

حيث أن كود ال c++ يتم تنفيذه بالترتيب أى سطر بعد سطر و هنا انت تقوم باستخدام النوع stUser قبل تعريفه فى سطر 21 . 

لذلك الحل هو نقل سطر 10 إلى ما بعد تعريف ال struct stUser اى ما بعد سطر 27 .

جزاك الله خيرا 

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...