This question was rejected because lack of a text file, which I do not see a way to upload. I saved the first part of the file as an image because that is all I can upload. If that doesn't suffice, please advise how to include a text file. In C++, I would like some help improving or making a better password lookup function for a Hash Table class/program I made,  The function:   it is supposed to lookup a user password using their ID and name which I read in from a text file. The one I have only works for the first 10 records, which I highlighted below in the program.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

This question was rejected because lack of a text file, which I do not see a way to upload. I saved the first part of the file as an image because that is all I can upload. If that doesn't suffice, please advise how to include a text file.

In C++, I would like some help improving or making a better password lookup function for a Hash Table class/program I made, 

The function:   it is supposed to lookup a user password using their ID and name which I read in from a text file. The one I have only works for the first 10 records, which I highlighted below in the program.

string lookupPassword (string inUserID, string inUserName){

string thePassword;

...

return thePassword;

}

Here is part of the program thus far:

// Hash.cpp 

#include <iostream>
#include<string>
#include<iomanip>
#include<fstream>
using namespace std;
//node class
class nodeBST {
private:    //user data
    string userID;
    string userName;
    string userPW;
    //BST left and right children
    nodeBST* ptrLeftNode;
    nodeBST* ptrRightNode;

public:
    //constructor
    nodeBST() { userID = " "; userName = " "; userPW = " "; ptrLeftNode = NULL; ptrRightNode = NULL; }
    //get and set methods for ID, Name, PW
    string getUserID() { return userID; }
    void setUserID(string inUserID) { userID = inUserID; }
    string getUserName() { return userName; }
    void setUserName(string inUserName) { userName = inUserName; }
    string getUserPW() { return userPW; }
    void setUserPW(string inUserPW) { userPW = inUserPW; }
    //get and set left and right children pointers
    void setPtrLeftNode(nodeBST* inPtrLeftNode) { ptrLeftNode = inPtrLeftNode; }
    nodeBST* getPtrLeftNode() { return ptrLeftNode; }
    void setPtrRightNode(nodeBST* inPtrRightNode) { ptrRightNode = inPtrRightNode; }
    nodeBST* getPtrRightNode() { return ptrRightNode; }
};
class myHash {  //hash class
private:
    //hash table with chaining - using BST's
    nodeBST* myHashTable[10]; //10 BST root node headers
    int recordCount = 0; //count initialization
public:
    myHash() {  //constructor 
        recordCount = 0;
        for (int i = 0; i < 10; i++) { myHashTable[i] = NULL; }
    } //loads 100 record text file into hash table
    void loadHashTableFromFile(string inFileName) {
        string inUserID;
        string inUserName;
        string inUserPW;
        string aWord;
        ifstream fin;
        cout << "Reading in File for Hash Table" << endl;
        fin.open(inFileName);  //opens file
        for (int i = 0; i < 100; i++) {
            if (fin >> aWord) {
                if (i % 3 == 0) {
                    inUserID = aWord;
                }
                else if (i % 3 == 1) {
                    inUserName = aWord;
                }
                else if (i % 3 == 2) {
                    inUserPW = aWord;
                    addRecord(inUserID, inUserName, inUserPW);
                }
            }
        }
        fin.close();  //closes file
    }
    string lookupPassword(string inUserId, string inUserName) {   //******This is where I need help****
        string thePassWord = "Goofy";  //initialize PW temp value
        //gather user index
        int index = myHashFunction(inUserId);
        //root to hold index for user ID
        nodeBST* root = myHashTable[index];
        //set PW by looking up userPW through root
        thePassWord = root->getUserPW();
        return thePassWord;

    }
    int myHashFunction(string inUserID) {
        //calculate array index and return index value 0 -9
        int index = 0;
        char aChar = inUserID[inUserID.length() - 1];
        index = aChar - '0';
        return index;
    }
    void addRecord(string inUserID, string inUserName, string inUserPW) {
        int index = 0;

        //calculate index = ID's last digit
        index = myHashFunction(inUserID);

        //declare new node and add to BST
        nodeBST* newNode = new nodeBST;

        //assign values to new node
        newNode->setUserID(inUserID);
        newNode->setUserName(inUserName);
        newNode->setUserPW(inUserPW);

        //check if root node occupied
        if (myHashTable[index] == NULL) {  //add to root
            myHashTable[index] = newNode;
        }
        else {
            //add to BST
            //find location to add new node
            recuriseInsertRecord(myHashTable[index], newNode);
        }
    }
    

I have print and traversal functions but I cut them out. Thank You for your time!

0001 Joe r2d2
0002 Ngo abb8
0003 Fundy 1234
0004 Tobie 4321
0005 Quitos password2
0006 Dorra $9uk#
0007 leeson querty
0008 Mateo CP30
0009 Basum JohnC42
0010 Jasum Thurm#1
0011 Jamie fooDawgTite
0012 Jared J-Rod77
0013 Ghost duffy16
0014 Craig lostBuddy3
0015 Shepard desperate Times15
0016 CJ theStrugglelzReal
0017 Stephaine littleBuddy7
0018 Eric Drifter4Life
0019 Roland the TowerDark
0020 Bill20 billthegreat20
0021 Chase21 chaseh21
0022 Will22 willthegreat22
0023 Noodle niceGuy65
0024 Will24 willd24
0025 Chase25 chased25
0026 Chez inAHaze8
0027 Will27 willd27
0028 Paul28 paulh28
0029 Josh Booniez13
Transcribed Image Text:0001 Joe r2d2 0002 Ngo abb8 0003 Fundy 1234 0004 Tobie 4321 0005 Quitos password2 0006 Dorra $9uk# 0007 leeson querty 0008 Mateo CP30 0009 Basum JohnC42 0010 Jasum Thurm#1 0011 Jamie fooDawgTite 0012 Jared J-Rod77 0013 Ghost duffy16 0014 Craig lostBuddy3 0015 Shepard desperate Times15 0016 CJ theStrugglelzReal 0017 Stephaine littleBuddy7 0018 Eric Drifter4Life 0019 Roland the TowerDark 0020 Bill20 billthegreat20 0021 Chase21 chaseh21 0022 Will22 willthegreat22 0023 Noodle niceGuy65 0024 Will24 willd24 0025 Chase25 chased25 0026 Chez inAHaze8 0027 Will27 willd27 0028 Paul28 paulh28 0029 Josh Booniez13
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY