How can I find and list the finalists?

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2009
Posts: 93
Reputation: turbomen is an unknown quantity at this point 
Solved Threads: 0
turbomen turbomen is offline Offline
Junior Poster in Training

How can I find and list the finalists?

 
0
  #1
Apr 17th, 2009
Dear Sir,

This is the 3rd part of the question, I want to find and list the finalists.

Cheers,
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 450
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 107
FlamingClaw's Avatar
FlamingClaw FlamingClaw is online now Online
Posting Pro in Training

Re: How can I find and list the finalists?

 
0
  #2
Apr 28th, 2009
First you have to create a 1,new file then 2,add member then 3,open and read then 4, you can change the phone number then 5, you can find only 3 finalists(sorry exchange the number in the code)and last 6 exit from the main program....
This program is written in Turbo Pascal 7.0 by me.
Sorry for the missing comments
Good day.
  1. Program Solution01;
  2.  
  3. Uses Crt;
  4.  
  5. Type
  6. TString = String[30];
  7.  
  8. TRecord = Record
  9. FirstName :TString;
  10. LastName :TString;
  11. PhoneNumber:LongInt;
  12. End;
  13.  
  14.  
  15. Const TheFile = 'C:\Record.dat';
  16.  
  17.  
  18. Var User_Choice,Rnd:Integer;
  19. Bag:Set Of Byte;
  20. All:Array[0..99]Of TRecord; {max 100 member}
  21. A:Array[1..10]Of TRecord;
  22. F:File Of TRecord;
  23. i,aindex,bindex,cindex,counter,FS,CF:Byte;
  24.  
  25.  
  26. Procedure MainMenu;Forward;
  27.  
  28. Procedure Terminate; {6. option}
  29. Begin
  30. WriteLn;
  31. Write('Press enter to quit.');
  32. ReadLn;
  33. ReadLn;
  34. Halt;
  35. End;
  36.  
  37. Procedure CreateNew;{1. option}
  38. Begin
  39. ClrScr;
  40. Assign(F,TheFile);
  41. Rewrite(F);
  42. Close(F);
  43. WriteLn('The file is empty.');
  44. WriteLn('File created: ',TheFile);
  45. WriteLn('Now you can add members to this file.');
  46. Write('Press enter to continue.');
  47. ReadLn;
  48. MainMenu;
  49. End;
  50.  
  51. Procedure AddNewMember; {2. option}
  52. Begin
  53. Assign(F,TheFile);
  54. ClrScr;
  55. WriteLn;
  56. WriteLn('How many guy do you want to add,max 10 members?');
  57. Write('Your Choice is: ');
  58. ReadLn(FS);
  59. For i:=1 to Fs Do Begin
  60. WriteLn('---');
  61. Write(i,'. First Name: ');
  62. ReadLn(A[i].FirstName);
  63. Write(' Last Name: ');
  64. ReadLn(A[i].LastName);
  65. Write(' Phone: ');
  66. ReadLn(A[i].PhoneNumber);
  67. If (i=FS) Then WriteLn('---');
  68. End;
  69. WriteLn;
  70. Reset(F);
  71. FileMode:=2;
  72. Seek(F,FileSize(F));
  73. For i:=1 to FS Do Write(F,A[i]);
  74. Close(F);
  75. Write('Writting is success.Press enter to continue.');
  76. ReadLn;
  77. MainMenu;
  78. End;
  79.  
  80. Procedure OpenAndRead;{3. option}
  81. Begin
  82. ClrScr;
  83. Assign(F,TheFile);
  84. Reset(F);
  85. aindex:=0;
  86. While (EoF(F)=False)Do Begin
  87. Read(F,All[aindex]);
  88. WriteLn('-',aindex,'-');
  89. WriteLn('First Name: ',All[aindex].FirstName);
  90. WriteLn('Last Name: ', All[aindex].LastName);
  91. WriteLn('Phone: ',All[aindex].PhoneNumber);
  92. Inc(aindex);
  93. End;
  94. WriteLn;
  95. Write('Press enter to Main menu.');
  96. ReadLn;
  97. MainMenu;
  98. End;
  99.  
  100. Procedure ChangePhone; {4. option}
  101. Begin
  102. ClrScr;
  103. Write('Please give me the member''s number: ');
  104. ReadLn(CF);
  105. Assign(F,TheFile);
  106. Reset(F);
  107. bindex:=0;
  108. While (EoF(F)=False) Do Begin
  109. Read(F,All[bindex]);
  110. If (EoF(F)=True) Then Break;
  111. Inc(bindex,1);
  112. End;
  113. If (CF>bindex) Then Begin
  114. Write('Too big number entered.Can''t change.');
  115. ReadLn;
  116. MainMenu;
  117. End;
  118. WriteLn(CF,'. First Name: ',All[CF].FirstName);
  119. WriteLn('Last Name: ',All[CF].LastName);
  120. WriteLn('Last entered phone number: ',All[CF].PhoneNumber);
  121. Write('The new phone number: ');
  122. ReadLn(All[CF].PhoneNumber);
  123. Seek(F,CF);
  124. Write(F,All[CF]);
  125. Close(F);
  126. Write('Press enter to continue.');
  127. ReadLn;
  128. MainMenu;
  129. End;
  130.  
  131. Procedure FindThree;{5. option}
  132. Begin
  133. ClrScr;
  134. Assign(F,TheFile);
  135. Reset(F);
  136. cindex:=0;
  137. While (EoF(F)=False) Do Begin
  138. Read(F,All[cindex]);
  139. If(EoF(F)=True)Then Break;
  140. Inc(cindex);
  141. End;
  142. If (cindex<=3) Then Begin
  143. Write('The members are too few.');
  144. ReadLn;
  145. MainMenu;
  146. End;
  147. Randomize;
  148. Bag:=[];{empty}
  149. For i:=1 To 3 Do Begin
  150. Rnd:=Random(cindex);
  151. If (Rnd In Bag) Then i:=i-1
  152. Else Begin
  153. Bag:=Bag+[Rnd];
  154. WriteLn(i,'. First Name: ',All[Rnd].FirstName);
  155. WriteLn('Last Name: ',All[Rnd].LastName);
  156. WriteLn('Phone: ',All[Rnd].PhoneNumber);
  157. End;
  158. End;
  159. Close(F);
  160. ReadLn;
  161. MainMenu;
  162. End;
  163.  
  164.  
  165. Procedure MainMenu;{0. option}
  166. Begin
  167. ClrScr;
  168. WriteLn;
  169. WriteLn('Select one number between 0 and 6.');
  170. WriteLn;
  171. WriteLn(' 0.Refresh.');
  172. WriteLn;
  173. WriteLn(' 1.Create a new file.');
  174. WriteLn;
  175. WriteLn(' 2.Add new member.');
  176. WriteLn;
  177. WriteLn(' 3.Open and read an existing file.');
  178. WriteLn;
  179. WriteLn(' 4.Change phone number for one person.');
  180. WriteLn;
  181. WriteLn(' 5.Find the 3 finalist.');
  182. WriteLn;
  183. WriteLn(' 6.Exit.');
  184. WriteLn;
  185. Write('Your Choice is : ');
  186. {$I-}
  187. ReadLn(User_Choice);
  188. {$I+}
  189. If IoResult<>0 Then Terminate;
  190. Case (User_Choice) Of
  191. 0:MainMenu;
  192. 1:CreateNew;
  193. 2:AddNewMember;
  194. 3:OpenAndRead;
  195. 4:ChangePhone;
  196. 5:FindThree;
  197. 6:Terminate;
  198. End;
  199.  
  200. End;
  201.  
  202.  
  203. Begin {main}
  204.  
  205. MainMenu;
  206.  
  207. End.{end of main}
  208. {
  209. -=Created By FlamingClaw=-
  210. -=2009.04.28=-
  211. }
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC