Click here to Skip to main content
15,888,170 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
Define a data structure which will hold all the users and their details in server

Note: Should not make use of database.
Posted

First off ask whoever asked you these questions:

"Oi, lecturer! Why a data structure and not a class? And why are we talking about data when we should be talking about behaviours?"

Then when you've done that work out what behaviours you'd expect from a "user" of a client server system, e.g:

- given a supplied user name, salt and password hash, are they authenticated?
- given a resource identifier are they allowed to access that resource?
- they can edit themselves if given a means of I/O

When you've done that lot (and those descriptions make a great basis for unit tests in the next phase) you can:

- work out what data you need to maintain to support the behaviours
- implement the behaviours and other C++ paraphernalia you need

Finally:

- As you want something that'll hold everything about all users choose a standard library collection class according you performance requirements (or just use std::vector) and pile objects of the class you create in it.
 
Share this answer
 
Comments
jayammahc 7-Jun-12 6:55am    
Thanks..
Sandeep Mewara 7-Jun-12 15:16pm    
5!
I suspect the answer your lecturer is looking for is that the server should maintain currently connected multiple clients as a linked list.

This is because a client can disappear/disconnect at any time, from any position, and you want to simply remove the client without copying memory and as quickly as possible. And note that this will be happening a lot.

You could use other collection classes such as arrays but it would not be as effiicient in terms of speed.
 
Share this answer
 
Comments
jayammahc 8-Jun-12 0:17am    
No, here the question is how to save the user details on server that has entered by them as a client, but we are not supposed to use any database.

Is there any way to save the user details on Server without maintaining database??
Aescleal 8-Jun-12 4:00am    
The big problem with the question is that whoever asked it didn't specify what a database is. When it comes down to it most relational databases are just vast arrays of data and the metadata (schemas/indices) describing them. However something like the Berkeley DB is also called a database and that's a map of key/value pairs. Microsoft use the word database all over the shop, completely willy nilly.

So it might be an idea to ask your lecturer exactly what he means by database. Depending on his definition it might preclude doing certain things in C++.
JackDingler 8-Jun-12 16:42pm    
Yeah my first thought, is that any table of records is a database.

In can be in memory or a text file..., it would still be a database.

Perhaps the instructor doesn't want an off the shelf solution to be used?
michaelmel 9-Jun-12 7:37am    
I am confident that unless we are stretching semantics to absurd levels, a linked list is NOT a database. The same applies to other types of collection classes and data stores.

Whilst in most general sense "database" is simply a collection of data, in real life the term is narrower and implies something a bit more permanent than transient data (such as linked list or array in RAM).
JackDingler 9-Jun-12 10:11am    
A linked list isn't a table of records, unless you're stretching your disparagement to absurd levels.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900