943,576 Members | Top Members by Rank

Ad:
Apr 7th, 2009
0

How can I list all the contestants?

Expand Post »
I have a menu system which can allows me to list all the contestants. The following is my menu system:

Program Student_millionaire;

{$APPTYPE CONSOLE}

uses
SysUtils, OurCrt;

Var User_Choice:Integer;

Procedure ContestantsList;
Begin
WriteLn('1 pressed,listing all the contestants...');
ReadLn;
End;

Procedure Generate10finalists;
Begin
WriteLn('2 pressed,generating the 10 finalist''s numbers...');
ReadLn;
End;

Procedure UpdateFinalists;
Begin
WriteLn('3 pressed,finding and listing the finalists...');
ReadLn;
End;

Procedure ChangeDetails;
Begin
WriteLn('4 pressed,changing the phone a friend details...');
ReadLn;
End;

Procedure EnrolContestant;
Begin
WriteLn('5 pressed,enroling a new contestant...');
ReadLn;
End;

Procedure GetOutOfHere;
Begin
WriteLn('6 pressed,exiting...');
Sleep(1000);

End;

Begin
User_Choice:=0;
While User_Choice <> 6 Do Begin
ClrScr;
WriteLn('Please enter an integer in the range 1...6');
WriteLn;
WriteLn(' 1 List all the contestants');
WriteLn(' 2 Generate the 10 finalist''s numbers');
WriteLn(' 3 Find and list the finalists');
WriteLn(' 4 Change the phone a friend details');
WriteLn(' 5 Enrol a new contestant');
WriteLn(' 6 Exit');
WriteLn;

ReadLn(User_Choice);

Case (User_Choice) of
1:ContestantsList;
2:Generate10finalists;
3:UpdateFinalists;
4:ChangeDetails;
5:EnrolContestant;
6:GetOutOfHere;
Else
Begin
WriteLn('Wrong Number..');
WriteLn('Exiting...');
End;
End;
End;
End.

To fulfill the listing of the contestant:-
1. May I want to declare a file of records?
2. May I want to prepare a file for output with the assign and rewrite statements?
3. May I want to store records in a file with write?
4. May I want to write files with multiple records?
5. Close a file.

And I have written the following programming, but it doesn't work:

program Project2;

{$APPTYPE CONSOLE}

type
Millionaire_record=record
first_name: String[12];
last_name: String[12];
address: String[25];
end;

var
Person: Millionaire_Record;
Person: array[1..40] of Millionaire_Record;

begin
WriteLn('Enter the first name of person >> ');
ReadLn('person.first name');

end.

May I need to combine this program together with the first program? How can I do?
Attached Files
File Type: txt gameshow.txt (1.7 KB, 17 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
turbomen is offline Offline
113 posts
since Feb 2009
Apr 7th, 2009
0

Re: How can I list all the contestants?

Before worrying about putting it all together, work on the parts of the program. For instance, you have identified the record to store your data, but how are you loading user input into the record array? Solve this as you would eat an elephant, one bite at a time.

In order to manage the record array you need to keep track of which records are already filled and where to insert new data, so you need a counter. You may also want to ask the user for data for more than one record at a time so you need a loop such as while or Repeat/ until. you also need a way to get out of the loop and continue with your program or exit.

My suggestion si to start with a small operating program and continue to add features, testing it often. Let us know how it progresses for you.
Reputation Points: 11
Solved Threads: 11
Junior Poster in Training
jsosnowski is offline Offline
68 posts
since Nov 2007
Apr 7th, 2009
0

Re: How can I list all the contestants?

You're right 'jsosnowski',big eating .But do not worry 'turbomen'...
First thing that you have to do is thinking of the algorithm of the main program,a bit more than you did it last time.And what do you want?To write these data to a text file,and read these data back to an array?Or just fill an array with these data?(Person:Array[1..40]of Millionaire_Record)?
And for your question the answer is you can.Put your second program in a procedure,and itegrate it in the main program.Take apart the second program a bit.Add the record type to the main program...

delphi Syntax (Toggle Plain Text)
  1. {just for help....}
  2. Program MainProgram;
  3.  
  4. {$APPTYPE CONSOLE}
  5.  
  6. Type Millionaire_Record=Record
  7. first_name: String[12];
  8. last_name: String[12];
  9. address: String[25];
  10. End;
  11.  
  12. Var Person: array[1..40] of Millionaire_Record;
  13. OnePerson:Millionaire_Record;
  14.  
  15.  
  16. //this is now living
  17. Procedure EnrolContestant;
  18. Begin
  19. Write('First name: ');
  20. ReadLn(OnePerson.first_name);
  21. Write('Last name: ');
  22. ReadLn(OnePerson.last_name);
  23. Write('Her/His address: ');
  24. ReadLn(OnePerson.address);
  25. WriteLn;
  26. WriteLn('Checking data...');//this just to verify data
  27. Write('First name: ');
  28. WriteLn(OnePerson.first_name);
  29. Write('Last name: ');
  30. WriteLn(OnePerson.last_name);
  31. Write('Her/His address: ');
  32. WriteLn(OnePerson.address);
  33. End;
  34.  
  35.  
  36. Begin //main
  37. EnrolContestant; //call our procedure
  38.  
  39. ReadLn;
  40. End.
  41.  
  42.  
  43. {
  44. If you want to continue your project then send a sign to us ,we can help to you
  45.  
  46. With respect:FlamingClaw
  47. }
Last edited by FlamingClaw; Apr 7th, 2009 at 12:44 pm.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Apr 7th, 2009
1

Re: How can I list all the contestants?

Or if you just fill the array then look at my solution,just example but working try it.
Delphi Syntax (Toggle Plain Text)
  1.  
  2. Program MainProgram;
  3.  
  4. {$APPTYPE CONSOLE}
  5.  
  6. Type Millionaire_Record=Record
  7. first_name: String[12];
  8. last_name: String[12];
  9. address: String[25];
  10. End;
  11.  
  12. Var Person: array[1..3] of Millionaire_Record;
  13. OnePerson:Millionaire_Record;
  14. i:Byte;
  15.  
  16. //this is now living
  17. Procedure EnrolContestant(x:Byte);
  18. Begin
  19. Write(x,' First name: ');
  20. ReadLn(OnePerson.first_name);
  21. Write(' Last name: ');
  22. ReadLn(OnePerson.last_name);
  23. Write(' Her/His address: ');
  24. ReadLn(OnePerson.address);
  25. End;
  26.  
  27.  
  28. Begin //main
  29.  
  30. For i:=1 To 3 Do Begin
  31. EnrolContestant(i); //call our procedure
  32. //fill 3 person data,and put them in the array
  33. Person[i]:=OnePerson;
  34. End;
  35.  
  36. //get back the data from the array
  37. For i:=1 To 3 Do Begin
  38. Write(i,'. ',Person[i].first_name,' ');
  39. Write(Person[i].last_name,' ');
  40. WriteLn(Person[i].address);
  41. End;
  42. ReadLn;
  43. End.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Apr 15th, 2009
0

Re: How can I list all the contestants?

//
delphi Syntax (Toggle Plain Text)
  1. {
  2. When you create a new file it is placed to the c:\ drive
  3. Like c:\something.txt.And when you asked that give a name
  4. without extension and path add only name like:something
  5.  
  6. }
  7. Program MainProgram;
  8.  
  9. {$APPTYPE CONSOLE}
  10.  
  11. Type Millionaire_Record=Record
  12. first_name: String[12];
  13. last_name: String[12];
  14. address: String[25];
  15. End;
  16. Const N=100;
  17. NewFilePath='C:\';
  18. NewFileExtension='.Txt';
  19.  
  20. Var Person: array[1..N] of Millionaire_Record;
  21. OnePerson:Millionaire_Record;
  22. i:Byte; //0..255
  23. User:Byte;
  24.  
  25. { -= The Procedures =- }
  26. //-= for reading a file =-
  27. Procedure ReadingContestant;
  28. Var F:text; //this will our *.text file
  29. F1:String; //this for lines
  30. F2:String;//file name
  31. Begin
  32. Write('Give me the file name,that located in c:\ drive: ');
  33. ReadLn(F2);
  34. Assign(F,NewFilePath+F2+NewFileExtension);//file rendering to variable
  35. {$I-} //IO check off
  36. Reset(F); //while try to open that file for reading
  37. {$I+} //IO check on
  38. If IoResult <> 0 Then Begin //if there was error then alert
  39. WriteLn('Error when try to read this file');
  40. ReadLn; //waiting for enter button
  41. Halt; //exit the main program
  42. End;
  43. i:=1;
  44. While Not(EoF(F))Do Begin //while not end of file
  45. ReadLn(F,F1); //read F,F1=lines
  46. WriteLn(i,'.',F1); //write only lines
  47. Inc(i);
  48. End;
  49. Close(F); //close the opened file
  50. End;
  51. //*****************************************************
  52. //-= enrolling =-
  53. Procedure EnrolContestant;
  54. Var EnCo:Byte;
  55. EnCo2:String;
  56. EnCo3:Text;
  57. Begin
  58. Write('How many contestants do you want to enrol? : ');
  59. ReadLn(EnCo);
  60. For i:=1 To EnCo Do Begin
  61. Write(i,' First name: ');
  62. ReadLn(OnePerson.first_name);
  63. Write(' Last name: ');
  64. ReadLn(OnePerson.last_name);
  65. Write(' Her/His address: ');
  66. ReadLn(OnePerson.address);
  67. Person[i]:=OnePerson;
  68. End;
  69. WriteLn;
  70. Write('Give me the file name without extension and path: ');
  71. ReadLn(EnCo2);
  72. If (EnCo2 = '') Then Begin
  73. Write('Missing Data');
  74. ReadLn;
  75. Halt;
  76. End
  77. Else Begin
  78. Assign(EnCo3,NewFilePath+EnCo2+NewFileExtension);
  79. {$I-}
  80. Append(EnCo3);
  81. {$I+}
  82. If (IoResult<>0) Then Begin
  83. Write('Missing Data');
  84. ReadLn;
  85. Halt;
  86. End;
  87. For i:=1 To EnCo Do Begin
  88. Write(EnCo3,Person[i].first_name,' ');
  89. Write(EnCo3,Person[i].last_name,' ');
  90. WriteLn(EnCo3,Person[i].address);
  91. End;
  92. Close(EnCo3);
  93. WriteLn('Process succesful');
  94. Write('Press Enter to quit');
  95. ReadLn;
  96. Halt;
  97. End;
  98. End;
  99. //******************************************************
  100. //-= exiting =-
  101. Procedure Exiting;
  102. Begin
  103. Write('Press enter to quit...');
  104. ReadLn;
  105. Halt;
  106. End;
  107.  
  108. //******************************************************
  109. //-=creating a new file for list=-
  110. Procedure NewList;
  111. Var NewFile:Text;
  112. NewFileName:String;
  113. Begin
  114. Write('Give me the new file name without extension and path: ');
  115. ReadLn(NewFileName);
  116. If (NewFileName = '') Then Begin
  117. Write('Missing data,press enter to quit.');
  118. ReadLn;
  119. Halt;
  120. End
  121. Else Begin
  122. Assign(NewFile,NewFilePath+NewFileName+NewFileExtension);
  123. {$I-}
  124. Reset(NewFile);
  125. {$I+}
  126. If (IoResult<>0) Then Begin
  127. {$I-}
  128. Rewrite(NewFile);
  129. Close(NewFile);
  130. {$I+}
  131. If (IoResult=0)Then Begin
  132. WriteLn(NewFilePath+NewFileName+NewFileExtension,' is ready to use.');
  133. Write('When you press the enter button,the program will exit');
  134. ReadLn;
  135. Halt;
  136. End
  137. Else Begin
  138. Write('Error when trying to create a new file.');
  139. ReadLn;
  140. Halt;
  141. End;
  142. End;
  143. End;
  144. End;
  145. //********************************************************
  146. //-= Modifying phone number =-
  147. Procedure Modify_Phone;
  148. Begin //not ready yet....
  149. Write('Under construction');
  150. ReadLn;
  151. Halt;
  152. End;
  153. //********************************************************
  154. //-=First ten finalist=-
  155. Procedure FirstTen;
  156. Begin //not ready yet....
  157. Write('Under construction');
  158. ReadLn;
  159. Halt;
  160. End;
  161. //********************************************************
  162. //-= Selecting an option =-
  163. Procedure SelectOption;
  164. Begin
  165. WriteLn('What do you want to do:');
  166. WriteLn;
  167. WriteLn('1.Open file for reading.List all the contestants.');
  168. WriteLn;
  169. WriteLn('2.Create a new file.Create a new list.');
  170. Writeln;
  171. WriteLn('3.Modifying contestant/s data.Phone number modifiying.');
  172. Writeln;
  173. WriteLn('4.Show 10 finalist.');
  174. Writeln;
  175. WriteLn('5.Add new contestant/s.');
  176. WriteLn;
  177. WriteLn('6.Exit the main program.');
  178. Writeln;
  179. {$I-}
  180. ReadLn(User);
  181. {$I+}
  182. If (IoResult<>0) Then Begin
  183. Write('Wrong data entered,press enter to quit.');
  184. ReadLn;
  185. Halt;
  186. End
  187. Else Begin
  188. Case (User) Of
  189. 1:ReadingContestant;
  190. 2:NewList;
  191. 3:Modify_Phone;//not ready yet
  192. 4:FirstTen; //not ready yet
  193. 5:EnrolContestant;
  194. 6:Exiting;
  195. End;
  196. End;
  197. End;
  198. //*************-=End Of Procedures=-*************************
  199.  
  200.  
  201. Begin//main program
  202. SelectOption;
  203. ReadLn;
  204. End.//of main program
  205.  
  206. {
  207. -= Note By FlamingClaw =-
  208.  
  209. All programs created by me are written and tested
  210. in Dev Pascal and/or Turbo Pascal 7.0
  211. Of course working!And working in Delphi 7 too.
  212. -= Created By FlamingClaw =-
  213. -=2009.04.15=-
  214. }
  215.  
  216. //
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Blind Input
Next Thread in Pascal and Delphi Forum Timeline: Hi everyone from roulingo





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC