{
When you create a new file it is placed to the c:\ drive
Like c:\something.txt.And when you asked that give a name
without extension and path add only name like:something
}
Program MainProgram;
{$APPTYPE CONSOLE}
Type Millionaire_Record=Record
first_name: String[12];
last_name: String[12];
address: String[25];
End;
Const N=100;
NewFilePath='C:\';
NewFileExtension='.Txt';
Var Person: array[1..N] of Millionaire_Record;
OnePerson:Millionaire_Record;
i:Byte; //0..255
User:Byte;
{ -= The Procedures =- }
//-= for reading a file =-
Procedure ReadingContestant;
Var F:text; //this will our *.text file
F1:String; //this for lines
F2:String;//file name
Begin
Write('Give me the file name,that located in c:\ drive: ');
ReadLn(F2);
Assign(F,NewFilePath+F2+NewFileExtension);//file rendering to variable
{$I-} //IO check off
Reset(F); //while try to open that file for reading
{$I+} //IO check on
If IoResult <> 0 Then Begin //if there was error then alert
WriteLn('Error when try to read this file');
ReadLn; //waiting for enter button
Halt; //exit the main program
End;
i:=1;
While Not(EoF(F))Do Begin //while not end of file
ReadLn(F,F1); //read F,F1=lines
WriteLn(i,'.',F1); //write only lines
Inc(i);
End;
Close(F); //close the opened file
End;
//*****************************************************
//-= enrolling =-
Procedure EnrolContestant;
Var EnCo:Byte;
EnCo2:String;
EnCo3:Text;
Begin
Write('How many contestants do you want to enrol? : ');
ReadLn(EnCo);
For i:=1 To EnCo Do Begin
Write(i,' First name: ');
ReadLn(OnePerson.first_name);
Write(' Last name: ');
ReadLn(OnePerson.last_name);
Write(' Her/His address: ');
ReadLn(OnePerson.address);
Person[i]:=OnePerson;
End;
WriteLn;
Write('Give me the file name without extension and path: ');
ReadLn(EnCo2);
If (EnCo2 = '') Then Begin
Write('Missing Data');
ReadLn;
Halt;
End
Else Begin
Assign(EnCo3,NewFilePath+EnCo2+NewFileExtension);
{$I-}
Append(EnCo3);
{$I+}
If (IoResult<>0) Then Begin
Write('Missing Data');
ReadLn;
Halt;
End;
For i:=1 To EnCo Do Begin
Write(EnCo3,Person[i].first_name,' ');
Write(EnCo3,Person[i].last_name,' ');
WriteLn(EnCo3,Person[i].address);
End;
Close(EnCo3);
WriteLn('Process succesful');
Write('Press Enter to quit');
ReadLn;
Halt;
End;
End;
//******************************************************
//-= exiting =-
Procedure Exiting;
Begin
Write('Press enter to quit...');
ReadLn;
Halt;
End;
//******************************************************
//-=creating a new file for list=-
Procedure NewList;
Var NewFile:Text;
NewFileName:String;
Begin
Write('Give me the new file name without extension and path: ');
ReadLn(NewFileName);
If (NewFileName = '') Then Begin
Write('Missing data,press enter to quit.');
ReadLn;
Halt;
End
Else Begin
Assign(NewFile,NewFilePath+NewFileName+NewFileExtension);
{$I-}
Reset(NewFile);
{$I+}
If (IoResult<>0) Then Begin
{$I-}
Rewrite(NewFile);
Close(NewFile);
{$I+}
If (IoResult=0)Then Begin
WriteLn(NewFilePath+NewFileName+NewFileExtension,' is ready to use.');
Write('When you press the enter button,the program will exit');
ReadLn;
Halt;
End
Else Begin
Write('Error when trying to create a new file.');
ReadLn;
Halt;
End;
End;
End;
End;
//********************************************************
//-= Modifying phone number =-
Procedure Modify_Phone;
Begin //not ready yet....
Write('Under construction');
ReadLn;
Halt;
End;
//********************************************************
//-=First ten finalist=-
Procedure FirstTen;
Begin //not ready yet....
Write('Under construction');
ReadLn;
Halt;
End;
//********************************************************
//-= Selecting an option =-
Procedure SelectOption;
Begin
WriteLn('What do you want to do:');
WriteLn;
WriteLn('1.Open file for reading.List all the contestants.');
WriteLn;
WriteLn('2.Create a new file.Create a new list.');
Writeln;
WriteLn('3.Modifying contestant/s data.Phone number modifiying.');
Writeln;
WriteLn('4.Show 10 finalist.');
Writeln;
WriteLn('5.Add new contestant/s.');
WriteLn;
WriteLn('6.Exit the main program.');
Writeln;
{$I-}
ReadLn(User);
{$I+}
If (IoResult<>0) Then Begin
Write('Wrong data entered,press enter to quit.');
ReadLn;
Halt;
End
Else Begin
Case (User) Of
1:ReadingContestant;
2:NewList;
3:Modify_Phone;//not ready yet
4:FirstTen; //not ready yet
5:EnrolContestant;
6:Exiting;
End;
End;
End;
//*************-=End Of Procedures=-*************************
Begin//main program
SelectOption;
ReadLn;
End.//of main program
{
-= Note By FlamingClaw =-
All programs created by me are written and tested
in Dev Pascal and/or Turbo Pascal 7.0
Of course working!And working in Delphi 7 too.
-= Created By FlamingClaw =-
-=2009.04.15=-
}
//