🔒 Closed Paturo naman kung pano ko lalagyan ng function yung admin para magbura ng account sa list,

Status
Not open for further replies.

Mauwanna0327

Honorary Poster
#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <windows.h>

using namespace std;

//FUNCTIONS
int accReg ();
int login ();
int menu ();
int deposit ();
int withdraw ();
int check ();
int balance = 10000;
int accNo = NULL;
int col = NULL;
int dep, wd, checkBalance;
int depositedbal = 0;
int withdrawnbal = 0;
string user [100] [2];
string username, password;

int main()
{
cout<<"\n---------------------------------"<<endl;
cout<<" welcome "<<endl;
cout<<"---------------------------------"<<endl;

system ("pause");
system ("cls");

int choice;

cout<<"\n----- homepage ----- " <<endl;
cout<<"[1] - sign up for an account " <<endl;
cout<<"[2] - log in " <<endl;

cout<<"[3] - goto administrator`s menu " <<endl;

cout<<"\nEnter choice: ";
cin>>choice;

if (choice == '1')
{
system ("cls");
accReg();
}
else if (choice == '2')
{
system ("cls");
login();
}
else if (choice == 'C' || choice == 'c')
{
system ("cls");

struct Record
{
int d;
int w;
int cb;
int bal;
int db;
int wb;
Record *next;
};

Record *head;
head = NULL;

Record *newRecord;
Record *recordPointer;

newRecord = new Record;
newRecord -> d = dep;
newRecord -> w = wd;
newRecord -> cb = checkBalance;
newRecord -> bal = balance;
newRecord -> db = depositedbal;
newRecord -> wb = withdrawnbal;
newRecord -> next = NULL;

if (head == NULL)
{
head = newRecord;
}
else
{
recordPointer = head;
while (recordPointer -> next)
{
recordPointer = recordPointer -> next;
}
recordPointer -> next = newRecord;
}

cout<<"\n----- T R A N S A C T I O N R E C O R D -----"<<endl<<endl;
cout<<"Transaction Number\tUsername\tType of Transaction\tAmount\tBalance"<<endl;

Record *displayP;
displayP = head;

while (displayP)
{
int row = 0;
if (displayP->d!=NULL)
{
cout<<" "<<row<<" \t"<<username<<"\tDeposit \t"<<displayP->d<<" \t"<<displayP->db<<endl;
row++;
}
if (displayP->cb!=NULL)
{
if (displayP->d!=NULL)
{
displayP->bal = displayP->db;
cout<<" "<<row<<" \t"<<username<<"\tCheck Balance\t\t\t\t"<<displayP->bal<<endl;
row++;
}
else
{
cout<<" "<<row<<" \t"<<username<<"\tCheck Balance\t\t\t\t"<<displayP->bal<<endl;
row++;
}
}
if (displayP->w!=NULL)
{
if (displayP->bal == displayP->db)
{
displayP->wb = displayP->bal - displayP->w;
cout<<" "<<row<<" \t"<<username<<"\tWithdraw \t"<<displayP->w<<" \t"<<displayP->wb<<endl;
row++;
}
}

displayP = displayP->next;
cout<<endl;
}

char homechoice;
cout<<"\n\nDo you want to go to homepage? "<<endl;
cout<<"[Y] - YES"<<endl;
cout<<"[N] - NO"<<endl;
cout<<"\nEnter choice: ";
cin>>homechoice;

if (homechoice == 'Y' || homechoice == 'y')
{
system("cls");
main();
}
else
{
return 0;
}
}
else if (choice == 'D' || choice == 'd')
{
system ("cls");
cout<<"\n----- A C C O U N T L I S T -----"<<endl<<endl;
cout<<"Account Number \t Username \t Password"<<endl;

struct accList
{
int a;
int b;
accList *next;
};

accList *head;
head = NULL;

accList *newList;
newList = new accList;
newList -> a = accNo;
newList -> b = col;
newList -> next = NULL;
head = newList;

accList *displayP;
displayP = head;

while (displayP)
{
for (int a = 0; a<=accNo; a++)
{
cout<<" "<<a<<" \t";
for (int b = 0; b<2; b++) {
cout<<user [a] <<"\t\t";
}
cout<<endl;
}

displayP = displayP -> next;
cout<<endl;
}


char homechoice;
cout<<"\n\nDo you want to go to homepage?"<<endl;
cout<<"[Y] - YES"<<endl;
cout<<"[N] - NO"<<endl;
cout<<"\nEnter choice: ";
cin>>homechoice;

if (homechoice == 'Y' || homechoice == 'y')
{
system ("cls");
main();
}
else
{
return 0;
}
}
else
{
cout<<"\n\nInvalid choice.";
system ("pause");
system ("cls");
main();
}
}

int accReg()
{
cout<<"\n----- sign up for an account -----"<<endl<<endl;

char cho;
int col = 0;

cout<<"Account Number ["<<accNo<<"]"<<endl;
cout<<"Enter username: ";
cin>>user [accNo] [col];
col++;
cout<<"Enter password: ";
cin>>user [accNo] [col];

cout<<"\n\nDo you want to register another account? "<<endl;
cout<<"[Y] - YES"<<endl;
cout<<"[N] - NO"<<endl;
cout<<"Enter choice: ";
cin>>cho;

if (cho == 'Y' || cho == 'y')
{
system ("cls");
accNo++;
accReg();
}
else
{
system("cls");
main();
}
}

int login()
{
cout<<"\n----- L O G I N -----"<<endl<<endl;

int no;
cout<<"Enter account number: ";
cin>>no;
cout<<"Enter username: ";
cin>>username;
cout<<"Enter password: ";
cin>>password;

if (no>=0 && no<=accNo)
{
if (username == user [no] [0] && password == user [no] [1])
{
cout<<"\nLogin Successfully!"<<endl;
system ("pause");
system ("cls");
menu();
}
else
{
int no;
cout<<"\nEnter account number: ";
cin>>no;
cout<<"Enter username: ";
cin>>username;
cout<<"Enter password: ";
cin>>password;

if (no>=0 && no<=accNo)
{
if (username == user [no] [0] && password == user [no] [1])
{
cout<<"\nLogin Successfully!"<<endl;
system ("pause");
system ("cls");
menu();
}
}
else
{
int no;
cout<<"\nEnter account number: ";
cin>>no;
cout<<"Enter username: ";
cin>>username;
cout<<"Enter password: ";
cin>>password;

if (no>=0 && no<=accNo)
{
if (username == user [no] [0] && password == user [no] [1])
{
cout<<"\nLogin Successfully!"<<endl;
system ("pause");
system ("cls");
menu();
}
}
else
{
cout<<"\nSorry, you've reached the number of tries to login.";
system ("pause");
system ("cls");
main();
}
}
}
}
}

int menu()
{
cout<<"\n----- M E N U -----"<<endl<<endl;

int c, c1;

cout<< "[1] - Account List" <<endl;
cout<< "[2] - Deposit" <<endl;
cout<< "[3] - Withdraw" <<endl;
cout<< "[4] - Check Balance" <<endl;
cout<< "[5] - Homepage" <<endl;
cout<< "[6] - Transaction Record" <<endl;

cout<<"[9] - Exit"<<endl;
cout<<"\nEnter choice: ";
cin>>c;

if (c == 'A' || c == 'a')
{
system("cls");
deposit();
cout<<"\nDo you want another transaction?"<<endl;
cout<<"[Y] - YES"<<endl;
cout<<"[N] - NO"<<endl;
cout<<"\nEnter choice: ";
cin>>c1;

if (c1 == 'Y' || c1 == 'y')
{
system("cls");
menu();
}
else
{
return 0;
}
}
else if (c == 'B' || c == 'b')
{
system ("cls");
withdraw();
cout<<"\nDo you want another transaction?"<<endl;
cout<<"[Y] - YES"<<endl;
cout<<"[N] - NO"<<endl;
cout<<"\nEnter choice: ";
cin>>c1;

if (c1 == 'Y' || c1 == 'y')
{
system("cls");
menu();
}
else
{
return 0;
}
}
else if (c == 'C' || c == 'c')
{
system ("cls");
check();
cout<<"\nDo you want another transaction?"<<endl;
cout<<"[Y] - YES"<<endl;
cout<<"[N] - NO"<<endl;
cout<<"\nEnter choice: ";
cin>>c1;

if (c1 == 'Y' || c1 == 'y')
{
system("cls");
menu();
}
else
{
return 0;
}
}
else if (c == 'D' || c == 'd')
{
system ("cls");
main();
}
else if (c == 'E' || c == 'e')
{
return 0;
}
else
{
cout<<"\nInvalid choice."<<endl;
system ("cls");
menu();
}
}

int deposit()
{
cout<<"\nEnter amount to deposit: ";
cin>>dep;
cout<<"\nYou successfully deposit "<<dep<<" pesos.";

balance = balance + dep;
depositedbal = balance;
}

int withdraw()
{
cout<<"\nEnter amount to withdraw: ";
cin>>wd;

if (wd>=100 && wd%100==0 && wd<=balance)
{
cout<<"\nYou successfully withdraw "<<wd<<" pesos.";
}
else
{
cout<<"\nInvalid amount to withdraw.";
}

balance = balance - wd;
withdrawnbal = balance;
}

int check()
{
checkBalance = balance;

cout<<"\nYour balance is "<<checkBalance<<" pesos.";
}
 
Code:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <windows.h>

using namespace std;

//FUNCTIONS
int accReg ();
int login ();
int menu ();
int deposit ();
int withdraw ();
int check ();
int balance = 10000;
int accNo = NULL;
int col = NULL;
int dep, wd, checkBalance;
int depositedbal = 0;
int withdrawnbal = 0;
string user [100] [2];
string username, password;

int main()
{
    cout<<"\n---------------------------------"<<endl;
    cout<<" welcome "<<endl;
    cout<<"---------------------------------"<<endl;

    system ("pause");
    system ("cls");

    int choice;

    cout<<"\n----- homepage ----- " <<endl;
    cout<<"[1] - sign up for an account " <<endl;
    cout<<"[2] - log in " <<endl;

    cout<<"[3] - goto administrator`s menu " <<endl;

    cout<<"\nEnter choice: ";
    cin>>choice;

    if (choice == '1')
    {
        system ("cls");
        accReg();
    }
    else if (choice == '2')
    {
        system ("cls");
        login();
    }
    else if (choice == 'C' || choice == 'c')
    {
        system ("cls");

        struct Record
        {
            int d;
            int w;
            int cb;
            int bal;
            int db;
            int wb;
            Record *next;
        };

        Record *head;
        head = NULL;

        Record *newRecord;
        Record *recordPointer;

        newRecord = new Record;
        newRecord -> d = dep;
        newRecord -> w = wd;
        newRecord -> cb = checkBalance;
        newRecord -> bal = balance;
        newRecord -> db = depositedbal;
        newRecord -> wb = withdrawnbal;
        newRecord -> next = NULL;

        if (head == NULL)
        {
            head = newRecord;
        }
        else
        {
            recordPointer = head;
            while (recordPointer -> next)
            {
                recordPointer = recordPointer -> next;
            }
            recordPointer -> next = newRecord;
        }

        cout<<"\n----- T R A N S A C T I O N  R E C O R D -----"<<endl<<endl;
        cout<<"Transaction Number\tUsername\tType of Transaction\tAmount\tBalance"<<endl;

        Record *displayP;
        displayP = head;

        while (displayP)
        {
            int row = 0;
            if (displayP->d!=NULL)
            {
                cout<<"        "<<row<<"          \t"<<username<<"\tDeposit       \t"<<displayP->d<<"       \t"<<displayP->db<<endl;
                row++;
            }
            if (displayP->cb!=NULL)
            {
                if (displayP->d!=NULL)
                {
                    displayP->bal = displayP->db;
                    cout<<"        "<<row<<"          \t"<<username<<"\tCheck Balance\t\t\t\t"<<displayP->bal<<endl;
                    row++;
                }
                else
                {
                    cout<<"        "<<row<<"          \t"<<username<<"\tCheck Balance\t\t\t\t"<<displayP->bal<<endl;
                    row++;
                }
            }
            if (displayP->w!=NULL)
            {
                if (displayP->bal == displayP->db)
                {
                    displayP->wb = displayP->bal - displayP->w;
                    cout<<"        "<<row<<"          \t"<<username<<"\tWithdraw     \t"<<displayP->w<<"        \t"<<displayP->wb<<endl;
                    row++;
                }
            }

            displayP = displayP->next;
            cout<<endl;
        }

        char homechoice;
        cout<<"\n\nDo you want to go to homepage? "<<endl;
        cout<<"[Y] - YES"<<endl;
        cout<<"[N] - NO"<<endl;
        cout<<"\nEnter choice: ";
        cin>>homechoice;

        if (homechoice == 'Y' || homechoice == 'y')
        {
            system("cls");
            main();
        }
        else
        {
            return 0;
        }
    }
    else if (choice == 'D' || choice == 'd')
    {
        system ("cls");
        cout<<"\n----- A C C O U N T  L I S T -----"<<endl<<endl;
        cout<<"Account Number \t Username \t Password"<<endl;

        struct accList
        {
            int a;
            int b;
            accList *next;
        };

        accList *head;
        head = NULL;

        accList *newList;
        newList = new accList;
        newList -> a = accNo;
        newList -> b = col;
        newList -> next = NULL;
        head = newList;

        accList *displayP;
        displayP = head;

        while (displayP)
        {
            for (int a = 0; a<=accNo; a++)
            {
                cout<<"      "<<a<<"        \t";
                for (int b = 0; b<2; b++) {
                    cout<<user [a] [b]<<"\t\t";
                }
                cout<<endl;
            }

            displayP = displayP -> next;
            cout<<endl;
        }


        char homechoice;
        cout<<"\n\nDo you want to go to homepage?"<<endl;
        cout<<"[Y] - YES"<<endl;
        cout<<"[N] - NO"<<endl;
        cout<<"\nEnter choice: ";
        cin>>homechoice;

        if (homechoice == 'Y' || homechoice == 'y')
        {
            system ("cls");
            main();
        }
        else
        {
            return 0;
        }
    }
    else
    {
        cout<<"\n\nInvalid choice.";
        system ("pause");
        system ("cls");
        main();
    }
}

int accReg()
{
    cout<<"\n----- sign up for an account -----"<<endl<<endl;

    char cho;
    int col = 0;

    cout<<"Account Number ["<<accNo<<"]"<<endl;
    cout<<"Enter username: ";
    cin>>user [accNo] [col];
    col++;
    cout<<"Enter password: ";
    cin>>user [accNo] [col];

    cout<<"\n\nDo you want to register another account? "<<endl;
    cout<<"[Y] - YES"<<endl;
    cout<<"[N] - NO"<<endl;
    cout<<"Enter choice: ";
    cin>>cho;

    if (cho == 'Y' || cho == 'y')
    {
        system ("cls");
        accNo++;
        accReg();
    }
    else
    {
        system("cls");
        main();
    }
}

int login()
{
    cout<<"\n----- L O G I N -----"<<endl<<endl;

    int no;
    cout<<"Enter account number: ";
    cin>>no;
    cout<<"Enter username: ";
    cin>>username;
    cout<<"Enter password: ";
    cin>>password;

    if (no>=0 && no<=accNo)
    {
        if (username == user [no] [0] && password == user [no] [1])
        {
            cout<<"\nLogin Successfully!"<<endl;
            system ("pause");
            system ("cls");
            menu();
        }
        else
        {
            int no;
            cout<<"\nEnter account number: ";
            cin>>no;
            cout<<"Enter username: ";
            cin>>username;
            cout<<"Enter password: ";
            cin>>password;

            if (no>=0 && no<=accNo)
            {
                if (username == user [no] [0] && password == user [no] [1])
                {
                    cout<<"\nLogin Successfully!"<<endl;
                    system ("pause");
                    system ("cls");
                    menu();
                }
            }
            else
            {
                int no;
                cout<<"\nEnter account number: ";
                cin>>no;
                cout<<"Enter username: ";
                cin>>username;
                cout<<"Enter password: ";
                cin>>password;

                if (no>=0 && no<=accNo)
                {
                    if (username == user [no] [0] && password == user [no] [1])
                    {
                        cout<<"\nLogin Successfully!"<<endl;
                        system ("pause");
                        system ("cls");
                        menu();
                    }
                }
                else
                {
                    cout<<"\nSorry, you've reached the number of tries to login.";
                    system ("pause");
                    system ("cls");
                    main();
                }
            }
        }
    }
}

int menu()
{
    cout<<"\n----- M E N U -----"<<endl<<endl;

    int c, c1;

    cout<< "[1] - Account List" <<endl;
    cout<< "[2] - Deposit" <<endl;
    cout<< "[3] - Withdraw" <<endl;
    cout<< "[4] - Check Balance" <<endl;
    cout<< "[5] - Homepage" <<endl;
    cout<< "[6] - Transaction Record" <<endl;

    cout<<"[9] - Exit"<<endl;
    cout<<"\nEnter choice: ";
    cin>>c;

    if (c == 'A' || c == 'a')
    {
        system("cls");
        deposit();
        cout<<"\nDo you want another transaction?"<<endl;
        cout<<"[Y] - YES"<<endl;
        cout<<"[N] - NO"<<endl;
        cout<<"\nEnter choice: ";
        cin>>c1;

        if (c1 == 'Y' || c1 == 'y')
        {
            system("cls");
            menu();
        }
        else
        {
            return 0;
        }
    }
    else if (c == 'B' || c == 'b')
    {
        system ("cls");
        withdraw();
        cout<<"\nDo you want another transaction?"<<endl;
        cout<<"[Y] - YES"<<endl;
        cout<<"[N] - NO"<<endl;
        cout<<"\nEnter choice: ";
        cin>>c1;

        if (c1 == 'Y' || c1 == 'y')
        {
            system("cls");
            menu();
        }
        else
        {
            return 0;
        }
    }
    else if (c == 'C' || c == 'c')
    {
        system ("cls");
        check();
        cout<<"\nDo you want another transaction?"<<endl;
        cout<<"[Y] - YES"<<endl;
        cout<<"[N] - NO"<<endl;
        cout<<"\nEnter choice: ";
        cin>>c1;

        if (c1 == 'Y' || c1 == 'y')
        {
            system("cls");
            menu();
        }
        else
        {
            return 0;
        }
    }
    else if (c == 'D' || c == 'd')
    {
        system ("cls");
        main();
    }
    else if (c == 'E' || c == 'e')
    {
        return 0;
    }
    else
    {
        cout<<"\nInvalid choice."<<endl;
        system ("cls");
        menu();
    }
}

int deposit()
{
    cout<<"\nEnter amount to deposit: ";
    cin>>dep;
    cout<<"\nYou successfully deposit "<<dep<<" pesos.";

    balance = balance + dep;
    depositedbal = balance;
}

int withdraw()
{
    cout<<"\nEnter amount to withdraw: ";
    cin>>wd;

    if (wd>=100 && wd%100==0 && wd<=balance)
    {
        cout<<"\nYou successfully withdraw "<<wd<<" pesos.";
    }
    else
    {
        cout<<"\nInvalid amount to withdraw.";
    }

    balance = balance - wd;
    withdrawnbal = balance;
}

int check()
{
    checkBalance = balance;

    cout<<"\nYour balance is "<<checkBalance<<" pesos.";
}
 
Buti inaayos mo ang format ng code.
1) Ikaw ba ang gumawa ng code niyan TS?
2) Ok lang bang gumamit ng modern C++ syntax? Parang may mga pangit sa flow ng program mo.
3) Required ba kayong gumamit ng raw dynamic memory(new)? Mukhang may memory leak.
 
Buti inaayos mo ang format ng code.
1) Ikaw ba ang gumawa ng code niyan TS?
2) Ok lang bang gumamit ng modern C++ syntax? Parang may mga pangit sa flow ng program mo.
3) Required ba kayong gumamit ng raw dynamic memory(new)? Mukhang may memory leak.
Yup requirements ang naka struct codes ko Yan paps binabago ko para maging fast food system
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 1K
    Views
  • 3
    Participants
Last reply from:
Mauwanna0327

Trending Topics

Online now

Members online
1,111
Guests online
771
Total visitors
1,882

Forum statistics

Threads
2,279,791
Posts
28,993,210
Members
1,226,082
Latest member
diarmdev
Back
Top