推介:| Web Hosting | 外賣系統 | Server colocation | Web Shop System | Makeup course |

查看完整版本: pascal 極不可能的問題,哭求大家!!!!!!!!

我要破紀錄 2008-10-28 19:16

pascal 極不可能的問題,哭求大家!!!!!!!!

see this code  selection sort
procedure sorting;
begin
i:=1;
while i<36 do
begin
j:=36;
while j>i do
begin
if markofstudent[j] < markofstudent[j-1] then
begin
temp[j]:=love[j];
love[j]:=love[j-1];
love[j-1] :=temp[j]
end;
j:=j-1
end;
i:=i+1
end;
for i:= 1 to 36 do
writeln(love[i],'')

而家個love(string) array 同markofstudent(integer) array d 野一樣,
love save 左分 (string)  markofstudent都係save左分(integer)
why write出尼唔係全部咁sort ,係2學生個2個學生咁sort,why?

arararchchch 2008-10-28 22:52

[quote]原帖由 我要破紀錄 於 28-10-2008 19:16 發表
see this code  selection sort
procedure sorting;
begin
i:=1;
while ii do
begin
if markofstudent[j] < markofstudent[j-1] then
begin
temp[j]:=love[j];
love[j]:=love[j-1];
love[j-1] :=temp[j]
... [/quote]

Use array of records!!:boxing:[code]program CIT_project;
uses wincrt;
const
  no_of_std = xxx {<-- you set it}
type
std_data = record   {<-- storing data of one student in a systematic way}
           ans: string;
           marks: integer; {<-- or real}
          end;
std_array = array [1..no_of_std] of std_data;

var
std_list: std_array;

procedure Selection_Sort;
var
love : std_data;    {<-- a temporary storage of a student data for sorting}
begin
... {Your code here}
end;

Begin {main}
...  {Your code here}
End.[/code][u][size=7]H[/size]ow to use records??
[/u]
- name[j].field


name - the name of the record variable, in this case, std_list

[j]       - the loop counter, allows you to sort

field   - the field required to do tasks, in this case, mark of ans are possible.

          - if the field is omited, the computer will treat the record, not a single field, as a commodity

[u][size=7]A[/size]ssignments syntax[/u]

If we want to assign the mark of the first student to be 70 the syntax is:[code]
  std_list[1].mark := 70;[/code]However, for sorting/ swapping two records, the syntax is:
{The type of variable temp is [color=red]std_data[/color]}[code]   
   temp := std_list[j];   {the fields are omitted because we only consider the whole record}
   std_list[j] := std_list[j+1];
   std_list[j + 1] := temp;[/code]

[[i] 本帖最後由 arararchchch 於 2008-10-28 23:36 編輯 [/i]]

我要破紀錄 2008-10-29 20:24

thx you thx you

arararchchch 2008-10-29 23:20

[quote]原帖由 [i]我要破紀錄[/i] 於 29-10-2008 20:24 發表 [url=http://xocat.com/f/redirect.php?goto=findpost&pid=5510581&ptid=222682][img]http://xocat.com/f/images/common/back.gif[/img][/url]
thx you thx you [/quote]

Does the code work?

我要破紀錄 2008-10-30 19:51

我唔用record 用返我的方法why唔得?

arararchchch 2008-10-30 22:11

[quote]原帖由 [i]我要破紀錄[/i] 於 30-10-2008 19:51 發表 [url=http://xocat.com/f/redirect.php?goto=findpost&pid=5514977&ptid=222682][img]http://xocat.com/f/images/common/back.gif[/img][/url]
我唔用record 用返我的方法why唔得? [/quote]

It's OK, but record is more easy to organize and use...

Otherwise, you have to use parallel arrays...

Good luck!!

[[i] 本帖最後由 arararchchch 於 2008-10-31 18:16 編輯 [/i]]

jayzhou_2046 2008-10-31 23:12

回復 5# 的帖子

1.  小弟相信閣下用love的string array去儲存名字, 而
     markofstudent則是對應的integer array去儲存積分
2.  那麼, 在sorting內, 閣下要根據
      markofstudent[j] < markofstudent[j-1]
      把love及markofstudent同時swap

arararchchch 2008-11-1 10:48

[quote]原帖由 [i]jayzhou_2046[/i] 於 31-10-2008 23:12 發表 [url=http://xocat.com/f/redirect.php?goto=findpost&pid=5519620&ptid=222682][img]http://xocat.com/f/images/common/back.gif[/img][/url]
1.  小弟相信閣下用love的string array去儲存名字, 而
     markofstudent則是對應的integer array去儲存積分
2.  那麼, 在sorting內, 閣下要根據
      markofstudent[j] < markofstudent[j-1]
      把love及m ... [/quote]

補充一下

2.為Parallel arrays

我要破紀錄 2008-11-3 22:24

jayzhou is good

arararchchch 2008-11-3 23:12

[quote]原帖由 [i]我要破紀錄[/i] 於 3-11-2008 22:24 發表 [url=http://xocat.com/f/redirect.php?goto=findpost&pid=5533872&ptid=222682][img]http://xocat.com/f/images/common/back.gif[/img][/url]
jayzhou is good [/quote]

版主始終係版主...

恕小弟班門弄斧...
頁: [1]
查看完整版本: pascal 極不可能的問題,哭求大家!!!!!!!!