Help with Linked Lists - C++

This is a discussion on Help with Linked Lists - C++ within the C++ Programming forums, part of the General Programming Boards category; I'm trying to build a banking program with the capability to create new accounts (savings or checking), process a deposit, ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    5

    Help with Linked Lists - C++

    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.

    Code:
    #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. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Double Linked Dynamic Lists Vs Unrolled Linked Lists
    By lantzvillian in forum C Programming
    Replies: 6
    Last Post: 02-14-2012, 12:07 PM
  2. Replies: 4
    Last Post: 05-01-2010, 10:19 PM
  3. Question about Linked lists of lists
    By hear_no_evil in forum C Programming
    Replies: 2
    Last Post: 11-08-2004, 01:49 AM
  4. question on linked lists(stack with linked lists)
    By dionys in forum C Programming
    Replies: 1
    Last Post: 06-02-2004, 11:08 AM
  5. Linked List of Linked lists Revisited.
    By Qui in forum C++ Programming
    Replies: 11
    Last Post: 04-11-2004, 09:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21