Please help me with this program...
Author |
Message |
redwolfgh
|
Posted: Thu May 14, 2009 10:39 pm Post subject: Please help me with this program... |
|
|
What is it you are trying to achieve?
<Replace all the type Database with your answers/code and remove the <>>
What is the problem you are having?
<Answer Here>
Describe what you have tried to solve this problem
<im trying to make a contact data prgram, but i faced some problems with the search,modify,and the exit feature too, can someone help me ? ? ? >
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<type Database>
Turing: |
record
Number : int
FirstName : string
LastName : string
Phone : string
Email : string
end record
setscreen ("graphics:800;900")
function searchString (lookString, inString : string) : boolean
var lookLength, inLength : int
var numCompares : int
var found : boolean := false
var subString : string
% store the lengths of each string for convenience
% in future calculations
lookLength := length (lookString )
inLength := length (inString )
% only do check if the search string can fit into
% the record
if lookLength <= inLength then
numCompares := inLength - lookLength
for i : 0 .. numCompares
% compare a substring of "inString"
subString := inString ((1 + i ) .. (lookLength + i ))
if subString = lookString then
found := true
end if
end for
end if
result found
end searchString
var contact : Database
var file : int
var winID : int := 0
%View the database
var answer : string
var rep : string
loop
put ""
put "THE MENU"
put "========"
put "Enter the number to do the following tasks you want: "
put "1. To see your contacts "
put "2. To add contact(s)"
put "3. To modify contact(s)"
put "4. To search for contact(s)"
put "5. To exit"
get rep
cls
put " "
if rep = "1" then
open : file, "contactList.dat", read
put "[Record #]" : 12 ..
put "[First Name] " : 13 ..
put "[Last Name]" : 13 ..
put "[Phone Number]" : 18 ..
put " [E-mail Adress]" : 5
put "================================================================================"
loop
exit when eof (file )
read : file, contact
put "[", contact.Number, "]" : 12 ..
put contact.FirstName : 13 ..
put contact.LastName : 12 ..
put contact.Phone : 18 ..
put contact.Email : 5
end loop
close : file
end if
if rep = "4" then
var searchname : string
var searchfound : boolean
open : file, "contactList.dat", read, mod, seek
put "Search for name (or part of name)? " ..
get searchname
searchfound := false
cls
loop
exit when eof (file )
get : file, contact.Number
get : file, contact.FirstName
get : file, contact.LastName
get : file, contact.Phone
get : file, contact.Email
% need to search for the substring in the name field
if searchString (searchname, contact.FirstName ) then
searchfound := true
put contact.Number : 13 ..
put contact.FirstName : 13 ..
put contact.LastName : 13 ..
put contact.Phone : 13 ..
put contact.Email : 5
end if
end loop
if searchfound = false then
put "No matches found for: ", searchname
end if
close : file
elsif rep = "2" then
open : file, "contactList.dat", write, mod, seek
seek : file, *
loop
put " Enter the record number : "
get contact.Number
put "Enter FirstName " ..
get contact.FirstName : *
put "Enter LastName " ..
get contact.LastName : *
put "Enter phone number " ..
get contact.Phone : *
put "Enter E-mail " ..
get contact.Email : *
put "Do you want to conitinue (y/n) ?"
get answer
put " "
write : file, contact
exit when answer = "N" or answer = "n" or answer = "no"
end loop
put ""
close : file
end if
if rep = "5" then
put"End Of Progeam .."
delay(1000)
Window.Close (winID )
end if
end loop
|
Please specify what version of Turing you are using
<Answer Here>
Description: |
|
Download |
Filename: |
NEW PROGRAM [2].T |
Filesize: |
3.49 KB |
Downloaded: |
77 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
saltpro15
|
Posted: Fri May 15, 2009 7:11 am Post subject: RE:Please help me with this program... |
|
|
I think you need a type with your record, I don't actually see database being created anywhere... you just set contact : Database
|
|
|
|
|
|
Dusk Eagle
|
Posted: Fri May 15, 2009 7:33 am Post subject: Re: Please help me with this program... |
|
|
Turing: |
type RecType :
record
Number : int
FirstName : string (10)
LastName : string (20)
Phone : string (10)
Email : string
end record
var rec : RecType
|
You first need to define a type for your record (first line), then create a variable of that type (last line). Then, if I want to change the Number value, I do it like this:
Turing: |
rec.Number := 255
|
Hope this helps!
BTW: Post 100. Woot!
|
|
|
|
|
|
redwolfgh
|
Posted: Sat May 16, 2009 8:26 pm Post subject: RE:Please help me with this program... |
|
|
i have the data type for my record
var contact : Database !!!!
but i think you have to create file called "contactList.dat"
but the search feature is not working !!!
and the modify too !
|
|
|
|
|
|
|
|