• C

Search and Sort in a Simple Database

Hello to anybody, I need help on creating a program that allowed the user to search or sort on a database on student information.


In this program each stduent has fields: name, student ID, phone number, and grade

-name field has student's last and first names
-student ID had five digits from 0 to 9
- phone number has 10 characters
-grade is an integer between 0 to 99

What the problem is that how will I create a string array or a multiarray string that allows the user's to search the database by student's name, studend ID, phone number or grade and sort the database by any of the four fields upon the user's choice then prints out all the records in the database in database in Ascending order.


I am not sure if I am clear enough on my question but if there is anything unclear please let me know. thank you
Ofakile1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent OlsenData Warehouse Architect / DBACommented:
Hi Ofakile1,

You're going to need several things to organize the data in a way that makes access/sorting easy.  The easiest, though wordiest, approach will be to write a search routine for every field upon which you might want to search.

Define a structure that defines the fields you want to track.  Below is an example.  Adjust it to fit your needs.

typedef struct
{
  char LastName[20];
  char FirstName[20];
  int  ID;
  char Phone[11];
  int  Grade;
} Student_t;

If you'll store your data as an array of pointers to the records, sorting is very easy, as is searching.

Student_t **StudentList = NULL;  /*  Array of student records  */
int       StudentCount = 0;      /*  Number of records in the StudentList array  */


From here, it's simply a matter of writing routines to AddStudent(), SortByName(), SearchByFirstName(), SearchByLastName(), etc.


Good Luck!
Kent
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.