few questions

i would like to know how do i readln something, then check whether wat data type is it ??

for example, i asked the user to enter name and if numbers are entered, then the compiler will return to code screen and giving errors... i would like the program to detect wat kind of data type is accepted and then tell the use to enter the correct data type.

how do i, by using pascal, somehow(if it's possible) from DOS(if using bios) or any other way .. to have a real-time time and date in my program whenever i execute the program . it shows the actual current time.

i'm currently assigned to code a library system. i'm kinda stuck at the borrow/return part. there's this condition where is the book it overdue in 14 day, a fine will be produced. my date format would be day/month/year = 03/11/1999 .. i do not know how to make the program to calculate the fine if the date is around 16+ because if date of 16 onwards (plus 14 for overdue) will become december dates .. and also i must make this compatible to every all the months. i hope u guys get what i mean. i may be confusing explaining all these. but it's not easy for me to explain too ..

and lasty, as with the library system program, i have three external file which is the member.dat, booklist.dat and inout.dat . inout.dat shows the records of books borrowed,by whom, date borrowed/return. my problem is that when a book is borrowed from the booklist, if another member would like to borrow the same book... how do i check for the availability of the book? i had a suggestion from a friend who told me to use a marker. i need more alternatives..
thanx
sewersideAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dbruntonCommented:
Read the users input as a string of text.  The program will accept this even if is numbers.  Then test the string to see if there are numbers in it.

The GetDate function will return the current date if you are using Turbo Pascal

GetDate(var Year, Month, Day, DayOfWeek : word);

You need routines to:

A     convert all dates into days from the beginning of the year
B      convert a day from the beginning of the year into mm//dd/yy

Use these fo calculate fines.

The inout.dat file should have something in it that you mark to indicate thet the book is being borrowed.

0
BigRatCommented:
The normal way of writing a library system (and I have written one) is to keep objects such as Media and Reader in index files - indexed by media number and library card number accordingly. When an issue takes place one checks that the media and borrower numbers exist by looking them up in the files. For maintaining a list of issued media one has an account file - indexed by media number. One checks that the media number is not in this file on issue, and that it is in this file on return.
   To claim ovedue media (sending letters) you'll have to process the account file serially. If you also add borrower number as a duplicate index to the account file, you can implement nice features like restricting a reader from taking too many books. (On issue you count the number of books he has).
0
BigRatCommented:
As far as date processing is concerned the best way is to store dates internally as Gregorian numbers. Ie: the number of days since a certain date in a 32-bit integer. You can find routines to convert to and from this format on the Internet. The nicest thing is that adding 16 days to it is very simple.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

My name is MudSystems EngineerCommented:
First Why don't you grade me the last question???

Ho to read data and know what type is...

Program Read_Data_Types;
USES
  CRT;
CONST
  TStr: Array[0..3] Of String[7] = ('Char','String','Byte','Integer');
TYPE
  Types = (TChar,TString,TByte,TInteger);
VAR
  ChrType: Char;
  StrType: String;
  BytType: Byte;
  IntType: Integer;
  Check: Boolean;

Function ReadDataFromKbd(T: Types): Boolean;
VAR
  TempReading: String; (* You allways read with this VAR *)
  TempNum: LongInt;
  So: Boolean;
  Code: Integer;
Begin
  So:=False;
  WriteLn('Please enter a ',TStr[Ord(T)],': ');
  ReadLn(TempReading);
  If Ord(T) in[2,3] Then (* Check If *)
    Begin
      Val(TempReading,TempNum,Code);
      If Code = 0 Then
        Begin
          If ((Ord(T) = 2) And ((TempNum >= 0) And (TempNum <= 255))) Then
            Begin
              BytType:=TempNum;
              So:=True
            End
          Else If ((Ord(T) = 3) And ((TempNum >= -32768) And (TempNum <= 32767))) Then
            Begin
              IntType:=TempNum;
              So:=True
            End
        End
    End
  Else If Not((Ord(T) = 0) and (TempReading[0] > #01)) Then
    Begin
      ChrType:=TempReading[1];
      So:=True
    End
  Else  (* Since a string could be a string of numbers *)
    Begin
      StrType:=TempReading;
      So:=False;
    End;
  ReadDataFromKbd:=So
End;

Begin
  ClrScr;

  (* Check for a Char; Since a Char could be a number with one digit then
     This function does that *)
  Repeat
    Check:=ReadDataFromKbd(TChar);
    If Not Check Then
      WriteLn('Please try Again...')
  Until Check;

  (*Check for a Byte numbers from 0..255*)
  Repeat
    Check:=ReadDataFromKbd(TByte);
    If Not Check Then
      WriteLn('Please try Again...')
  Until Check;

  (*Check for a Integer numbers from -32768..32767*)
  Repeat
    Check:=ReadDataFromKbd(TInteger);
    If Not Check Then
      WriteLn('Please try Again...')
  Until Check;

  (*Check for a String, Since a string Could be a string of numbers, then...*)
  ReadDataFromKbd(TString);
End.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
My name is MudSystems EngineerCommented:
For how to display the date time go to:

  http://www.experts-exchange.com/jsp/qShow.jsp?ta=pascal&qid=10212579 
0
My name is MudSystems EngineerCommented:
UNIT _TPDATES;

INTERFACE

Function DOWW(Day,Month,Year: Integer): Integer;
         {D_O_W > Day of week > D¡a de la semana 0=Dom. 6=Sab.}
Function NumDia(Day,Month,Year: Integer): Integer;
         {NumDia > N£mero de d¡a ordinario (1..366)}
Procedure MesDia(OD,Year: Integer; VAR Day,Month: Integer);
         {MesDia > Mes y d¡a de n£m. de d¡a ord. de un a¤o}
Function ValDate(Day,Month,Year: Integer): Boolean;
         {ValDate > Valida una fecha (TRUE > buena; FALSE > mala}
Function DifDia(Day1,Month1,Year1,Day2,Month2,Year2: Integer): Longint;
         {DifDia > N£mero de d¡as entre dos fechas}
Procedure NewDate(Day,Month,Year,Days: Integer; VAR NewD,NewM,NewY: Integer);
         {NewDate > Retorna nueva fecha con un n£mero de d¡as especificado
                    en Days y la fecha dada.}
Function BiSies(Year: Integer): Integer;
         {BiSies > (1 > A¤o bisiesto; 0 > a¤o no bisiesto)}
Function To_Serial(Day,Month,Year: Integer): Longint;
         {To_Serial > Retorna n£mero de d¡as en JULIAN calendario}
Procedure From_Serial(Serial_Day: Longint; VAR Day,Month,Year: Integer);
         {From_Serial > Retorna una fecha por su numero serial}
Function DOWStr(Day,Month,Year: Integer): String;
         {DIASEMSTR > Retorna el nombre del d¡a de la fecha dada}
Function MesStr(Month: Integer): String;
         {MesStr > Retorna el nombre del mes de la fecha dada}
Function NumStr(Num: Integer; Anio: Boolean): String;
         {YEARSTR > Retorna el a¤o en una cadena de caracteres}
IMPLEMENTATION

USES
  CRT,DOS,_TPCOMUN;
CONST
  D_O_W: Array[0..6] Of String[9] =
  ('KVTPUNV','QZSJX','SGXZKY','VRN[LXUN\','P[K\KY',']PLYULZ','YGHGJU');
  Mes: Array[1..12] Of String[10]=
  ('JSJWT','MLIYLYV','RFW_T','FGWNQ','QE]S','OZSNT','OZQNT',
  'GMUYZU',']OZ^SOWL\O','VJ[\IYL','WX_RNVK[N','MRLRNVK[N');
  Mil: Array[0..9] Of String[11] =
  ('','PLO','KVZ''TPS','\ZM[(UQT','M_K^\Y*WSV','LRWLX)VRU',
  '[MQ[(UQT','\RN]N)VRU','WKPW(UQT','W^N_N)VRU');
  Cen: Array[0..9] Of String[13] =
  ('','IOKTZU','NY]MSOX^Y]','_]P^NTPY_Z^','PbNa_\PVR[a\`','[_SXSOX^Y]',
  '^PT^NTPY_Z^','^P_PNTPY_Z^','ZNSZNTPY_Z^','YZaPNTPY_Z^');
  Dec0: Array[0..9] Of String[10] =
  ('','HMI^','\KOTZK','[YLPU[H','K]IZMV\I','LRWL^NW]J',
  'ZLZLU[H','ZL[LU[H','VJOLU[H','UV]LU[H');
  Dec1: Array[1..5] Of String[8] =
  ('SRGI','HSGI','YWJHJ','JH[VYJL','W[OTIK');
  Uni: Array[0..9] Of String[6] =
  ('','XQR','GRV','XVIW','I[GZXU','HNSHT','WIMW','XNJYJ','SGLS','SZJ[J');

Procedure Inicial;
VAR
  I,J: Integer;
Begin
  For J:=0 To 6 Do
    For I:=1 To Length(D_O_W[J]) Do
      D_O_W[J,I]:=Chr(Ord(D_O_W[J,I])-Length(D_O_W[J]));
  For J:=1 To 12 Do
    For I:=1 To Length(Mes[J]) Do
      Mes[J,I]:=Chr(Ord(Mes[J,I])-Length(Mes[J]));
  For J:=0 To 9 Do
    Begin
      For I:=1 To Length(Mil[J]) Do
        Mil[J,I]:=Chr(Ord(Mil[J,I])-Length(Mil[J]));
      For I:=1 To Length(Cen[J]) Do
          Cen[J,I]:=Chr(Ord(Cen[J,I])-Length(Cen[J]));
      For I:=1 To Length(Dec0[J]) Do
          Dec0[J,I]:=Chr(Ord(Dec0[J,I])-Length(Dec0[J]));
      For I:=1 To Length(Uni[J]) Do
          Uni[J,I]:=Chr(Ord(Uni[J,I])-Length(Uni[J]))
    End;
  For J:=1 To 5 Do
    For I:=1 To Length(Dec1[J]) Do
      Dec1[J,I]:=Chr(Ord(Dec1[J,I])-Length(Dec1[J]))
End;

Function DOWW(Day,Month,Year: Integer): Integer;
VAR
  Century,YR,DW: Integer;
Begin
  If Month < 3 Then
    Begin
      Month:=Month + 10;
      Year:=Year - 1
    End
  Else
    Month:=Month - 2;
  Century:=Year Div 100;
  YR:=Year Mod 100;
  DW:=(((26 * Month - 2) Div 10) +
      Day + YR + (YR Div 4) +
      (Century Div 4) -
      (2 * Century)) Mod 7;
  If DW < 0 Then
    DOWW:=DW + 7
  Else
    DOWW:=DW
End;

Function BiSies(Year: Integer): Integer;
Begin
  If Year And 3 <> 0 Then
    BiSies:=0
  Else If Year Mod 100 <> 0 Then
    BiSies:=1
  Else If Year Mod 400 <> 0 Then
    BiSies:=0
  Else
    BiSies:=1
End;

Function NumDia(Day,Month,Year: Integer): Integer;
VAR
  OD: Integer;
Begin
  If Month < 3 Then
    Month:=Month + 10
  Else
    Month:=Month - 2;
  OD:=(306 * Month - 2) Div 10 - 30;
  If OD<306 Then
    NumDia:=OD + 59 + BiSies(Year) + Day
  Else
    NumDia:=OD - 306 + Day
End;

Procedure MesDia(OD,Year: Integer; VAR Day,Month: Integer);
VAR
  LYF,ADJ_MO: Integer;
Begin
  LYF:=BiSies(Year) + 60;
  If OD < LYF Then
    OD:=OD + 305
  Else
    OD:=OD-LYF;
  ADJ_MO:=(OD * 10 + 4) Div 306 + 1;
  Day:=OD-((ADJ_MO * 306 - 2) Div 10 - 30) + 1;
  If ADJ_MO < 11 Then
    Month:=ADJ_MO + 2
  Else
    Month:=ADJ_MO - 10
End;

Function ValDate(Day,Month,Year: Integer): Boolean;
VAR
  OD,M,D: Integer;
Begin
  OD:=NumDia(Day,Month,Year);
  If (OD > 366) OR (OD < 1) Then
    ValDate:=False
  Else
    Begin
      MesDia(OD,Year,D,M);
      If (D=Day) And (M=Month) Then
        ValDate:=True
      Else ValDate:=False
    End
End;

Function To_Serial(Day,Month,Year: Integer): Longint;
VAR
  M,Y: Longint;
Begin
  If Month > 2 Then
    Begin
      M:=Month - 3;
      Y:=Year
    End
  Else
    Begin
      M:=Month + 9;
      Y:=Year - 1
    End;
  To_Serial:=((Y Div 100) * 146097) Div 4 +
             ((Y Mod 100) * 1461) Div 4 +
             (153 * M + 2) Div 5 + Day;
End;

Function DifDia(Day1,Month1,Year1,Day2,Month2,Year2: Integer): Longint;
Begin
  DifDia:=To_Serial(Day2,Month2,Year2) - To_Serial(Day1,Month1,Year1)
End;

Procedure From_Serial(Serial_Day: Longint; VAR Day,Month,Year: Integer);
VAR
  J,D: Longint;
Begin
  J:=Serial_Day * 4 - 1;
  D:=((J Mod 146097) Div 4) * 4 + 3;
  Year:=(J Div 146097) * 100 + (D Div 1461);
  D:=(((D Mod 1461) + 4) Div 4) * 5 - 3;
  Month:=D Div 153;
  Day:=((D Mod 153) + 5) Div 5;
  If Month < 10 Then
    Month:=Month + 3
  Else
    Begin
      Month:=Month - 9;
      Year:=Year+1
    End
End;

Procedure NewDate(Day,Month,Year,Days: Integer; VAR NewD,NewM,NewY: Integer);
Begin
  From_Serial(To_Serial(Day,Month,Year) + Days,NewD,NewM,NewY);
End;

Function DOWStr(Day,Month,Year: Integer): String;
Begin
  DOWStr:=D_O_W[DOWW(Day,Month,Year)]
End;

Function MesStr(Month: Integer): String;
Begin
  If Month In [1..12] Then
    MesStr:=Mes[Month] Else MesStr:='';
End;

Function NumStr(Num: Integer; Anio: Boolean): String;
VAR
  StrNum: String;
  VE: Boolean;
Begin
  StrNum:=''; VE:=False;
  If (Num>0) And (Num<10000) Then
    Begin
      If Num>999 Then
        Begin
          StrNum:=StrNum+Mil[Trunc(Int(Num/1000))]+' ';
          Num:=Num-Trunc(Int(Num/1000))*1000
        End;
      If Num>99 Then
        Begin
          StrNum:=StrNum+Cen[Trunc(Int(Num/100))]+' ';
          If Num=100 Then Delete(StrNum,Length(StrNum)-2,2);
          Num:=Num-Trunc(Int(Num/100))*100;
        End;
      If Num IN [11..15] Then
        Begin
          Num:=Num-Trunc(Int(Num/10))*10; StrNum:=StrNum+Dec1[Num]; Num:=0;
        End
      Else If (Num>9) And NOT(Num IN [11..15]) Then
        Begin
          If (Num>20) And (Num<30) Then VE:=True;
          StrNum:=StrNum+Dec0[Trunc(Int(Num/10))];
          Num:=Num-Trunc(Int(Num/10))*10;
          If Num<>0 Then
            Begin
              If VE Then
                Begin
                  Delete(StrNum,Length(StrNum),1);
                  StrNum:=StrNum+'I'+Uni[Num]; Num:=0
                End
              Else StrNum:=StrNum+' Y '+Uni[Num]; Num:=0
            End
        End;
      If Num>0 Then
       Begin
         If NOT(Anio) And (Num=1) Then StrNum:='PRIMERO'
         Else StrNum:=StrNum+Uni[Num];
       End;
    End
  Else StrNum:='FECHA ERRONEA';
  NumStr:=StrNum
End;

Begin
  Inicial;
End.
0
sewersideAuthor Commented:
thanx alot whatboy
i was wondering if anyone could send me the library system code so that i can refer to??
0
sewersideAuthor Commented:
to bigrat, can i have a look at ur library system please?
0
My name is MudSystems EngineerCommented:
0
BigRatCommented:
sewerside: It's a commerical system that costs a lot of money.

whatboy: I'll grade the code for you. Null Point - there's hardly a comment line in the code which tells you what the hell's going on!!!
0
My name is MudSystems EngineerCommented:
Well actually i myself don't and didn't use nor create that unit, but what i did was a more "RAW" reading of the database, it was a pain since back then i didn't have Internet access, so i managed to deencrypt [for to say it in some way] the format of the DBF files... So for the comments of that unit... i give a ... a.... i dunno... what do you think...
0
BigRatCommented:
Well whatboy the only saving grace is that you didn't write it yourself. But whoever did, ought to be shot! (Preferably without a last cigarette)
0
sewersideAuthor Commented:
it's ok now .. i've done the library system myself ... and had presented it .. it does have some minor logical problem but was alrite i guess
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.