?
Solved

Search and Sort in a Simple Database

Posted on 2004-11-16
1
Medium Priority
?
154 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:Ofakile1
1 Comment
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 300 total points
ID: 12600435
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question