0

Dear Sir,

After finishing the 1st part, I still have many problem of the question.

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.

The 2nd part is to generate the 10 finalist's numbers. Randomly generate 10 numbers, these numbers must range from 1 to the number of people in the file. I cannot have duplicate numbers being drawn.

Cheers,

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by FlamingClaw
0

long ago,you asked the community for a lotto games,there I send a source for the generating numbers,and one number exists only once.Try to use your head a bit,the mechanism was written.Of course that is another question that how can you read a file to array that contains records?,.
You need to learn more about the pascal language.
You have to use the BlockRead and BlockWrite procedures. See after these.

Reads one or more records from an open file into a variable.

Unit

System

Category

IO routines

Delphi syntax:

procedure BlockRead(var F: File; var Buf; Count: Integer [; var AmtTransferred: Integer]);

Description

F is an untyped file variable, Buf is any variable, Count is an expression of type Integer, and AmtTransferred is an optional variable of type Integer.

BlockRead reads Count or fewer records from the file F into memory, starting at the first byte occupied by Buf. The actual number of complete records read (less than or equal to Count) is returned in AmtTransferred.

The entire transferred block occupies at most Count * RecSize bytes. RecSize is the record size specified when the file was opened (or 128 if the record size was not specified).

If the entire block was transferred, AmtTransferred is equal to Count.

If AmtTransferred is less than Count, ReadBlock reached the end of the file before the transfer was complete. If the file's record size is greater than 1, AmtTransferred returns the number of complete records read.

If AmtTransferred isn't specified, an I/O error occurs if the number of records read isn't equal to Count. If the $I+ compiler directive is in effect, errors raise an EInOutError exception.

**** **** **** **** ****
Writes one or more records from a variable to an open file.

Unit

System

Category

IO routines

Delphi syntax:

procedure BlockWrite(var f: File; var Buf; Count: Integer [; var AmtTransferred: Integer]);

Description

F is an untyped file variable, Buf is any variable, Count is an expression of type Integer, and AmtTransferred is an optional variable of type Integer.

BlockWrite writes Count or fewer records to the file F from memory, starting at the first byte occupied by Buf. The actual number of complete records written (less than or equal to Count) is returned in AmtTransferred. 

The entire block transferred occupies at most Count * RecSize bytes. RecSize is the record size specified when the file was opened (or 128 if the record size was unspecified). 

If the entire block is transferred, AmtTransferred is equal to Count on return. 

If AmtTransferred is less than Count, the disk became full before the transfer was complete. In this case, if the file's record size is greater than 1, AmtTransferred returns the number of complete records written.

BlockWrite advances the current file position by AmtTransferred records.

If AmtTransferred isn't specified, an I/O error occurs if the number written isn't equal to Count. If the $I+ compiler directive is in effect, errors raise an EInOutError exception.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.