C++ assignment

closed account (NCo3URfi)
Can anyone please help me with this.Please

Create a database system using linked-list for any one the following:

-Student Record System (Name, Matric number, Date of Birth)

Create multiple sorting functions to sort the database according to different parameters.

Implement an efficient searching algorithm to search the database.

Hello mihrjeev,

Welcome to the forum.

I would start with deciding if you want to use a class or struct to hold your information. I mean just the basic information, Name, Matric Number, DOB and anything else yo will need. At the end of all that information you will need a pointer to "next" and maybe a pointer to "prev".

What I would work on first is getting the input from the user and store it where necessary. do not worry about the pointers right now, They are for later.

When that is done start on the linked list part and get that working.

Pretty much the last thing to work on is the sorting the linked list followed by, if you want, to store the linked list to a file.

Work up some code and post it we can work from. Remember to work in small steps or parts and it is helpful if you put something down on paper to give you an idea of what the program will do. More pseudo code than actual code. The more you plan the easier it is to code when you what to do and which direction you will need to go.

Hope that helps,

Andy
Do you have to create a linked list, sort algorithms, and a search or can you use
std::list, std::sort and std::binary_search. ?

OOOPS: Totally forgot that std::sort and std::binary_search don't work with std::list.
Last edited on
One can at least learn form the "std::list, std::sort and std::binary_search". For one, the std::list has its own 'sort' member function -- for a reason. We'll get to that a bit later.


First, both std::sort and std::list::sort do have a common feature: they take 'comp' as parameter. What is the 'comp'?

(Some) sorting algorithms do have:
1
2
3
if ( ! comp( A, B ) ) {
  swap( A, B )
}

The 'comp' returns true, if the A and B are already in desired order. The rest of "std::sort and std::list::sort" have no say on the matter.

Therefore, the "Create multiple sorting functions" means "create multiple comp", if you do use std::sort or std::list::sort.


The code fragment above calls swap too. Something that exchanges the two values (if they weren't in right order). Swapping values is relatively trivial, but it involves copying a value. Value can be complex and the copy thus relatively expensive.

The linked list has an alternative option. It can swap the nodes that hold the values. If it does, then it has to update links, which is cheap but less easy to do correctly. std::sort is not aware about linked lists, but list::sort is.


"Database" sounds fancy, but what you really will have is a "list of records". You can define a record with struct/class.


It could be educational to write the program first with std::list and other std components. Then replace each component with one of your own. Most can be broken into independent subtasks.
To start off, if you have to create a linked list from scratch yourself, creating a class for various operations and a struct for the nodes/records would be useful. So you would create a class with member functions such as "addRecord", "deleteRecord", etc. For your struct, this would be used to hold the name, date, etc, as well as the pointer to point to the next thing in the list, a pointer that points to the previous record might be an option as well. You would also have some members in your class that are pointers such as "head", "temp", etc., to point to other nodes/records, or null.
Last edited on
Topic archived. No new replies allowed.