2013-02-28 62 views
-1

这是我的代码到目前为止,incase你不能告诉我想写一本字典,可能与1字母的每个字母,也许只是15左右随机条目。这里是我到目前为止Pascal字符串和记录

program Dictionary; 

uses crt; 

Type 
Asdf = String[26]; 
Definition = Record 
        First, Full, NorV, Class : Asdf; 
        End; 
Var 
A, B, C, D, E, F, g, h, i, j, k, l, m, n, o, p, q, r, 
s, t, u, v, w, x, y, z : Definition; 

BEGIN 
a.First := 'a'; 
a.Full := 'apple'; 
a.NorV := 'noun'; 
a.Class := 'fruit'; 

b.First := 'b'; 
b.full := 'bee'; 
b.NorV := 'noun'; 
b.Class := 'insect'; 

c.first := 'c'; 
c.full := 'cat'; 
c.NorV := 'noun'; 
c.class := 'animal'; 

d.first := 'd'; 
d.full := 'dunk'; 
d.Norv := 'verb'; 
d.class := 'action'; 

e.first := 'e'; 
e.full := 'egg'; 
e.norv := 'noun'; 
e.class := 'food'; 

f.first := 'f'; 
f.full := 'forget'; 
f.norv := 'verb'; 
f.class := 'action'; 

g.First := 'g'; 
g.Full := 'grape'; 
g.NorV := 'noun'; 
g.Class := 'fruit'; 

h.First := 'h'; 
h.Full := 'horse'; 
h.NorV := 'noun'; 
h.class := 'animal'; 

i.First := 'i'; 
i.Full := 'invent'; 
i.NorV := 'verb'; 
i.class := 'action'; 

j.First := 'j'; 
j.Full := 'jump'; 
j.NorV := 'noun'; 
j.class := 'action'; 

k.First := 'k'; 
k.Full := 'kangaroo'; 
k.NorV := 'noun'; 
k.class := 'animal'; 

l.First := 'l'; 
l.Full := 'look'; 
l.NorV := 'verb'; 
l.class := 'action'; 

m.First := 'm'; 
m.Full := 'mango'; 
m.NorV := 'noun'; 
m.Class := 'fruit'; 

n.First := 'n'; 
n.Full := 'noose'; 
n.NorV := 'noun'; 
n.class := 'object'; 

o.First := 'o'; 
o.Full := 'orangutan'; 
o.NorV := 'noun'; 
o.class := 'animal'; 

p.First := 'p'; 
p.Full := 'prod'; 
p.NorV := 'verb'; 
p.class := 'action'; 

q.First := 'q'; 
q.Full := 'queen'; 
q.NorV := 'noun'; 
q.class := 'royalty'; 

r.First := 'r'; 
r.Full := 'run'; 
r.NorV := 'verb'; 
r.class := 'action'; 

s.First := 's'; 
s.Full := 'shoot'; 
s.NorV := 'verb'; 
s.class := 'action'; 

t.First := 't'; 
t.Full := 'train'; 
t.NorV := 'noun'; 
t.class := 'transport'; 

u.First := 'u'; 
u.Full := 'umbrella'; 
u.NorV := 'noun'; 
u.class := 'object'; 

v.First := 'v'; 
v.Full := 'vegetable'; 
v.NorV := 'noun'; 
v.class := 'vegetable'; 

w.First := 'w'; 
w.Full := 'walk'; 
w.NorV := 'verb'; 
w.class := 'action'; 

x.First := 'x'; 
x.Full := 'xylophone'; 
x.NorV := 'noun'; 
x.class := 'object'; 

y.First := 'y'; 
y.Full := 'yank'; 
y.NorV := 'verb'; 
y.class := 'action'; 

z.First := 'z'; 
z.Full := 'zoo'; 
z.NorV := 'noun'; 
z.class := 'area'; 

Writeln ('Type the first letter of the word you want to view'); 
Readln (

END。

我应该在最后放什么,以便在输入时可以搜索?如果需要,我可以添加更多变量。请帮助!

回答

0

您尝试在字符串的位置1处设置字符。第一个工作原因是因为'a'字符串可以被编译器输入到字符中。其他字符串不能被输入。放弃索引,事情应该工作(未经测试)。

BEGIN 
Def.FirstLetter := 'a'; 
Def.FullName := 'apple'; 
Def.NounorVerb := 'noun' 
END.  
2

当你发现很难枚举多个变量。

标准的解决方案是将它们放在一个数组

var 
    myarray: array['A'..'Z'] of Definition; 

,然后用

var 
    myloopvar: Char; 

for myloopvar := 'A' to 'Z' do 
    if myarray[myloopvar].firstletter = 'X' then 
    DoSomething; 
枚举