0

I'm trying to build a banking program with the capability to create new accounts (savings or checking), process a deposit, process a withdrawal, or print one or all of the accounts at this "bank". I am doing this utilizing two classes, one for 'Checking' and one for 'Savings'.

I've more or less written all of the code needed but I could use some help utilizing linked lists in a few spots that are commented within my 'main' function where I am needing to search through my classes and then send the proper 'Savings' or 'Checking' variable to my class functions. I've had issues implementing linked lists for classes and my textbook along with online sources have not helped me understand proper usage of them.

If it help, comments of this variety occur in lines: 191, 192, 198, 203, 228, 230, 241, 243, 269, 271, 282, 284, 312, 314, 325, 327, 335, 337, 342, 344

Thanks in advance for any assistance.

#include <iostream>

using namespace std;

class Savings
{
    private:
        string FName;
        string LName;
        string Address;
        int SSN;
        double TotBalance;

    public:
        Savings SavingsCreate(Savings *a);
        Savings SavingsDep(Savings *b);
        Savings SavingsWit(Savings *c);
        Savings SavingsPrint(Savings *e);
};

Savings Savings::SavingsCreate(Savings *a)
{
    cout << endl;
    cout << "Enter your first name: ";
    cin >> a->FName;
    cout << endl << endl;
    cout << "Enter your last name: ";
    cin >> a->LName;
    cout << endl << endl;
    cout << "Enter your street address: ";
    cin >> a->Address;
    cout << endl << endl;
    cout << "Please enter your Soc. Sec. # (123456789 Format): ";
    cin >> a->SSN;
    cout << endl << endl;
}

Savings Savings::SavingsDep(Savings *b)
{
    double deposit;

    cout << endl;
    cout << "Deposit Amount: ";
    cin >> deposit;

    b->TotBalance += deposit;

    cout << endl;
    cout << "Current Balance: $" << b->TotBalance;
    cout << endl;
}

Savings Savings::SavingsWit(Savings *c)
{
    double withdraw;

    cout << endl;
    cout << "Withdraw Amount: ";
    cin >> withdraw;

    c->TotBalance -= withdraw;

    cout << endl;
    cout << "Current Balance: $" << c->TotBalance;
    cout << endl;
}

Savings Savings::SavingsPrint(Savings *e)
{
   cout << endl;
    cout << "Name: " << e->FName << " " << e->LName << endl;
    cout << "Address: " << e->Address << endl;
    cout << "Soc. Sec. #: " << e->SSN << endl;
    cout << "Account Type: Savings\n";
    cout << "Interest Rate: 1%\n";
    cout << "Total Balance: $" << e->TotBalance << endl;
    cout << "Interest Gained: $" << e->TotBalance * .01 << endl;
    cout << "Total Balance with Interest Gained: $" << e->TotBalance + (e->TotBalance * .01) << endl;
    cout << endl;
}

class Checking
{
    private:
        string FName;
        string LName;
        string Address;
        int SSN;
        double TotBalance;

    public:
        Checking CheckingCreate(Checking *a);
        Checking CheckingDep(Checking *b);
        Checking CheckingWit(Checking *c);
        Checking CheckingPrint(Checking *e);
};

Checking Checking::CheckingCreate(Checking *a)
{
    cout << endl;
    cout << "Enter your first name: ";
    cin >> a->FName;
    cout << endl << endl;
    cout << "Enter your last name: ";
    cin >> a->LName;
    cout << endl << endl;
    cout << "Enter your street address: ";
    cin >> a->Address;
    cout << endl << endl;
    cout << "Please enter your Social Security Number (123456789 Format): ";
    cin >> a->SSN;
    cout << endl << endl;
}

Checking Checking::CheckingDep(Checking *b)
{
    double deposit;

    cout << endl;
    cout << "Deposit Amount: ";
    cin >> deposit;

    b->TotBalance += deposit;

    cout << endl;
    cout << "Current Balance: $" << b->TotBalance;
    cout << endl;
}

Checking Checking::CheckingWit(Checking *c)
{
    double withdraw;

    cout << endl;
    cout << "Withdraw Amount: ";
    cin >> withdraw;

    c->TotBalance -= withdraw;

    cout << endl;
    cout << "Current Balance: $" << c->TotBalance;
    cout << endl;
}

Checking Checking::CheckingPrint(Checking *e)
{
    cout << endl;
    cout << "Name: " << e->FName << " " << e->LName << endl;
    cout << "Address: " << e->Address << endl;
    cout << "Soc. Sec. #: " << e->SSN << endl;
    cout << "Account Type: Checking\n";
    cout << "Interest Rate: 0%\n";
    cout << "Total Balance: " << e->TotBalance << endl;
    cout << endl;
}

int main()
{
    int choice, choice_1, choice_2, choice_3, choice_4;
    int SSN_temp;

    do
    {
        cout << "---------------------------------------------\n";
        cout << "Welcome to the First National Bank\n";
        cout << "Account transaction system\n";
        cout << "---------------------------------------------\n";
        cout << "Please choose from the following menu:\n";
        cout << "       1) Create Account\n";
        cout << "       2) Deposit\n";
        cout << "       3) Withdraw\n";
        cout << "       4) Print Account(s)\n";
        cout << endl;
        cout << "       0) Exit Program\n";
        cout << endl;
        cout << ":";
        cin >> choice;

        switch (choice)
        {
            case 1:
                {
                    cout << endl;
                    cout << "Create a Savings or Checking Account?: \n";
                    cout << "       1) Savings Account - 1% Interest Rate\n";
                    cout << "       2) Checking Account - 0% Interest Rate\n";
                    cout << endl;
                    cout << ":";
                    cin >> choice_1;

                    //Search through linked list for checking or savings classes until NULL is found
                    // and create new variable for 'Savings' or 'Checking' class.

                    switch (choice_1)
                    {
                        case 1:
                            {
                                //"new 'Savings'".SavingsCreate(Savings &"new");
                                break;
                            }
                        case 2:
                            {
                                //"new 'Checking'".CheckingCreate(Checking &"new");
                                break;
                            }
                    }
                    break;
                }
            case 2:
                {
                    cout << endl;
                    cout << "Deposting to Savings or Checking Account?:\n";
                    cout << "       1) Savings Account\n";
                    cout << "       2) Checking Account\n";
                    cout << endl;
                    cout << ":";
                    cin >> choice_2;

                    switch (choice_2)
                    {
                        case 1:
                            {
                                cout << "Please enter your soc. sec. #:\n";
                                cout << endl;
                                cout << ":";
                                cin >> SSN_temp;

                                //Search through linked list for 'Savings' containing matching SSN

                                //"current 'Savings'".SavingsDep(Savings &"current");

                                break;
                            }
                        case 2:
                            {
                                cout << "Please enter your soc. sec. #:\n";
                                cout << endl;
                                cout << ":";
                                cin >> SSN_temp;

                                //Search through linked list for 'Checking' containing matching SSN

                                //"current 'Checking'".CheckingDep(Checking &"current");

                                break;
                            }
                    }
                    break;
                }
            case 3:
                {
                    cout << endl;
                    cout << "Withdrawing from Savings or Checking Account?:\n";
                    cout << "       1) Savings Account\n";
                    cout << "       2) Checking Account\n";
                    cout << endl;
                    cout << ":";
                    cin >> choice_3;

                    switch (choice_3)
                    {
                        case 1:
                            {
                                cout << "Please enter your soc. sec. #:\n";
                                cout << endl;
                                cout << ":";
                                cin >> SSN_temp;

                                //Search through linked list for 'Savings' containing matching SSN

                                //"current 'Savings'".SavingsWit(Savings &"current");

                                break;
                            }
                        case 2:
                            {
                                cout << "Please enter your soc. sec. #:\n";
                                cout << endl;
                                cout << ":";
                                cin >> SSN_temp;

                                //Search through linked list for 'Checking' containing matching SSN

                                //"current 'Checking'".CheckingWit(Checking &"current");

                                break;
                            }
                    }
                    break;
                }

            case 4:
                {
                    cout << endl;
                    cout << "Print Savings Acc., Checking Acc., or all:\n";
                    cout << "       1) Savings Account\n";
                    cout << "       2) Checking Account\n";
                    cout << "       3) All\n";
                    cout << endl;
                    cout << ":";
                    cin >> choice_4;

                    switch (choice_4)
                    {
                        case 1:
                            {
                                cout << "Please enter your soc. sec. #:\n";
                                cout << endl;
                                cout << ":";
                                cin >> SSN_temp;

                                //Search through linked list for 'Savings' containing matching SSN

                                //"current 'Savings'".SavingsPrint(Savings &"current");

                                break;
                            }
                        case 2:
                            {
                                cout << "Please enter your soc. sec. #:\n";
                                cout << endl;
                                cout << ":";
                                cin >> SSN_temp;

                                //Search through linked list for 'Checking' containing matching SSN

                                //"current 'Checking'".CheckingPrint(Checking &"current");

                                break;
                            }
                        case 3:
                            {
                                cout << "Savings Accounts:\n";

                                //Run through linked list for all 'Savings'

                                //"current 'Savings'".SavingsPrint(Savings &"current");

                                cout << endl;
                                cout << "Checking Accounts:\n";

                                //Run through linked list for all 'Checking'

                                //"current 'Checking'".CheckingPrint(Checking &"current");

                                break;
                            }
                    }
                }
        }
    } while (choice != 0);
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Gonbe
1

How about you first create a class representing a linked list that contains some basic operations?

  • Insert a value at a given index.
  • Remove a value at a given index.
  • Obtain the size
  • Get the value at a specified index ([] operator?)
  • Remove the first entry matching a supplied parameter.
  • Count the amount of occurrences of a supplied element.

and so on. You probably only need the first 4 anyway.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.