Computer Science Canada Searchable Databases |
Author: | Token [ Fri May 06, 2005 8:06 pm ] | ||||||||||||||
Post subject: | Searchable Databases | ||||||||||||||
Databases and how to search through them The first thing that you want to do is create your database, so we''ll set up a record. Example we'll use is an adress book
okay now we're all set to gather the information. so we will assume that we already have a file set up with a couple of entries in this format first name, last name, home number, cell number, fax number.
Okay so now we'll input all of this information into our reccord through a loop.
Okay, so our system is now created and the data is entered. so now what we have to do is find the name of who their searching for. we'll make this search by last name only.
Alright, so now we have our search, in this case we're searching for Smith...so we run the variable 'search' through the entire record and compare it to the other last names, if its the same then we display it on the screen
Tadum! and then it pops up with the results that matched, you can change it to search for first name or number or somthing just by changing where it says
so there you have it, a searchable database, simple and easy to add and modify. all that code combined is below, along with what would be in the text file, 'archive.txt'
Quote: Joe Smith 555-1234 555-4321 44-171-343433 if you have any questions or comments please let me know. |
Author: | jamonathin [ Fri May 06, 2005 8:44 pm ] | ||
Post subject: | |||
Good tutorial. Our teacher was actually trying to teach us that this year. Even though that was the only thing, and he did it some wierd ass complete different way . . . nvm, lol, but yeah good work on that tut. And im not too sure why you did this
Im pretty sure that for C++, but anyways, good job. + 10 Bits Next to work on is the option of playing around with that data. Such as (D)elete or (W)rite and so on. |
Author: | GlobeTrotter [ Fri May 06, 2005 9:38 pm ] |
Post subject: | |
You could also do a binary search for this problem. It would require sorting the array of records, but the actual searching would be much quicker. FOr example, in an array of 100 names, you way would run through 100 times. Binary Search would run through 7. |
Author: | Token [ Sat May 07, 2005 8:14 pm ] |
Post subject: | |
Hey, well i used put "\nFirst name: ", entry (i).first to display the name, the \n is to set it down a line without just doing a blank put statement (put ""). and could you please explain to me more about this binary thing? ps. thanks for the bits jamonathin |
Author: | GlobeTrotter [ Sat May 07, 2005 11:09 pm ] |
Post subject: | |
I'll describe a case which used binary search. Say I ask you to guess a number between 1 and 100. If after each guess, I tell you whether the guess is higher or lower, you are guaranteed to get it within 7 guesses if you make the right guesses. For example, if you picked the number 13: First you'd guess 50, then 25, then 13. In three guesses. Basically, you do the same thing with a sorted array of records. You go the midway point of the left and right vals, and check if its higher, lower, or equal. If different, you reset the left and right vals. |
Author: | md [ Sun May 08, 2005 8:42 am ] |
Post subject: | |
You have to make sure that whatever your searching is sorted first, generally if your doing a binary search you quicksort first. |
Author: | Token [ Sun May 08, 2005 3:25 pm ] |
Post subject: | |
Hmm inturesting, this would work better for a larger database tho, with phone numbers, really you would only have a maximum of 50-75 contacts, so time isnt really of the essence, but if you were sorting information for say the school's contact information, you would want to do it in a binary sort of fashion. thanks for that info guys and i might add onto the tut. and put it in there. |
Author: | Weelkid_29 [ Mon Jan 23, 2006 7:02 pm ] | ||
Post subject: | a different search mothod | ||
enter all the info for the record then enter the last name for the info u want |