I have made a hashtable that stores numbers perfectly but now I need to change it so that it stores student records ie id number, first name, surname, and GPA. I would really appreciate any help
Somewhere you specified int (or whatever number type you're storing) as what your hash table stores. Instead, specify record, where record is a struct you defined like this:
I just called the numbers it stores idNum. Ya i have a header file will all the other definitions of the functions i just didnt post all the code.
Heres the orginal header file with idNum with will become record:
If you're not actually writing the hash table yourself
I have coded a hash table and don't want to completely change it to use a standard c++ one.
I want to just change the hash table i have to store student records instead of numbers so i know i'll need to make changes to a few of the other functions
in the code that i have
I tired putting it in the header file but i got errors so i'm guessing it needs to go in the .cpp file but i'm not sure exactly where it goes.
I'm sure i would be able to do it if i just had to add a name instead of a number but since i have four items to add i'm not sure how to do it and then i have to change bits of my code to store the record not a number.
i could post the rest of my code here if that would help
kw1991, you can put it in it's own header file, and just include the header in the cpp file. You will have to change the way that you access the records, though, since there is another level of abstraction involved. Instead of just directly accessing the idNum from the hash table, you'll have to access the idNumber portion of the record from the hash table.
#include "StdAfx.h"
#include <string>
struct record {
int idNumber;
std::string firstName;
std::string surname;
int GPA;
};
You could also use the using directive like so: using std::string
I don't recommend this, however, it's better to avoid any type of 'using' directive when you're in a header file.
it worked thanks but i'm not sure how to change the idNum to the idNumber from records.
I know you suggested something like myHash.myRecord.idNumber but everything i try gives errors.
heres some of the code HashTable.cpp, maybe you could help me if fix it?
I'm pretty sure that in order to change a member, you have to directly reference that member. So you can't change idNum, since it's not a member of your struct anymore, you'll have to change idNumber (if that's what you named the variable). Just go through and make sure all of your variable names match up properly.
sorry i dont really understand. You told me that i cant just replace idNum with idNumber so how do i reference it?
I need to get rid of all the idNum's in the code since i'm not inserting just numbers into the code anymore, I need to insert idNumber, firstName, surname and GPA.
Like when i insert a new record into the table it will ask for the idNumber, firstName, surname and GPA and when i search for a record i just enter the idNumber and all the other information comes up. thats what i'm hoping to do anyway