Jump to content

hey guys I'm trying to write a display all function for my hash table and I'm running into

issues with trying to access private data members of the videoGame class in the

displayAll function for my table class.  I was thinking about writing a function of sorts 

to call from the tables displayAll function but I have no idea. Any help is much appreciated. 

class videoGame
{
	public:
		videoGame(void);//Done
		~videoGame(void);//Done
		int createGame(char * ctitle, char * cdescription, char * ccategory, char * cplatform, char * crecommendations, int crating);//Done
		int copyGame(const videoGame & newGame);//Done
		int editRec(/*Game*/);
		int retrieve(char * keyValue, videoGame & found)const;//Done
	private:
		char * title;
		char * description;
		char * category;
		char * platform;
		char * recommendations;
		int rating;

};


struct node
{
	videoGame game;
	node * next;
};


class table
{
	public:
		table(int size=5);//Done
		~table();
		int insert(char * keyValue, const videoGame & toAdd);//Done
		int remove(char * keyValue, videoGame & found);
		int retrieve(char * searchTitle, videoGame & found)const;//Done
		int displayAll(videoGame)const;
		int displayPlatform(char * searchPlatform);
	private:
		node ** hashTable;
		int tableSize;
		int hashFunction(char * keyValue)const;
};

 

i5 4670k| Asrock H81M-ITX| EVGA Nex 650g| WD Black 500Gb| H100 with SP120s| ASUS Matrix 7970 Platinum (just sold)| Patriot Venom 1600Mhz 8Gb| Bitfenix Prodigy. Build log in progress 

Build Log here: http://linustechtips.com/main/topic/119926-yin-yang-prodigy-update-2-26-14/

Link to comment
https://linustechtips.com/topic/688147-hash-table-display-all-with-chaining/
Share on other sites

Link to post
Share on other sites

Look into iterators such as used in std::unordered_map (C++ own hashmap).

You might also want to use templates so that your hashtable can also store other classes than "videoGame".

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to post
Share on other sites

20 hours ago, SSL said:

You need to add public accessor methods to the VideoGame class. That is the only way to expose private members while maintaining encapsulation.

i finally figured to just add a display function to the videoGame class and have the display all function call the basic display

i5 4670k| Asrock H81M-ITX| EVGA Nex 650g| WD Black 500Gb| H100 with SP120s| ASUS Matrix 7970 Platinum (just sold)| Patriot Venom 1600Mhz 8Gb| Bitfenix Prodigy. Build log in progress 

Build Log here: http://linustechtips.com/main/topic/119926-yin-yang-prodigy-update-2-26-14/

Link to post
Share on other sites

On 11/11/2016 at 1:14 PM, SSL said:

 

Except that is a violation of the single-responsibility principle.

I'm currently in a low level programming class so it isn't as big of an issue right now.  For future reference, how would I do that without violating that principle?

i5 4670k| Asrock H81M-ITX| EVGA Nex 650g| WD Black 500Gb| H100 with SP120s| ASUS Matrix 7970 Platinum (just sold)| Patriot Venom 1600Mhz 8Gb| Bitfenix Prodigy. Build log in progress 

Build Log here: http://linustechtips.com/main/topic/119926-yin-yang-prodigy-update-2-26-14/

Link to post
Share on other sites

1 minute ago, CJPowell27 said:

I'm currently in a low level programming class so it isn't as big of an issue right now.  For future reference, how would I do that without violating that principle?

 

Just put the display code in a separate class. You're using classes to begin with, so "low level" hardly need be a barrier to following basic principles of good design.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×