.


:




:

































 

 

 

 





ۻ

:

Turbo Pascal , .

 

 

, , . :

1.

2. ...

3.

4.

5.

:

1.

2. ,

3.

4. , .


 

 

 


PASCAL

.

program LibraryDB;

Crt, .

uses Crt;

MaxBooks, .

Const MaxBooks = 100;

BookType, . :

1. UDK .

2. Author

3. Name

4. Year

5. Count

Type

BookType = record

UDK: String[11];

Author: String[50];

Name: String[100];

Year: Integer;

Count: Integer;

end;

 

, :

1. Done . ,

2. Choice

3. BooksSize

4. Books

5. BookIndex ,

6. UDK, Author, Name, Year, Count ,

Var

Done: Boolean;

Choice: Integer;

BooksSize: Integer;

Books: array [1..MaxBooks] of BookType;

BookIndex: Integer;

UDK, Author, Name: String;

Year, Count: Integer;

(), .

AddBook . Books . BooksSize .

procedure AddBook(const AUDK, AAuthor, AName: String; AYear, ACount: Integer);

Begin

BooksSize:= BooksSize + 1;

with Books[BooksSize] do

Begin

UDK:= AUDK;

Author:= AAuthor;

Name:= AName;

Year:= AYear;

Count:= ACount;

end;

end;

 

DeleteBook, , Books BookIndex. Books BookIndex. BooksSize .

procedure DeleteBook(BookIndex: Integer);

Var

i: Integer;

Begin

for i:= BookIndex to BooksSize - 1 do

Books[i]:= Books[i + 1];

BooksSize:= BooksSize - 1;

end;

SortBooksByYear, Books . . . , , . . .

procedure SortBooksByYear;

Var

i, j, MinYearI: Integer;

TmpBook: BookType;

Begin

for i:= 1 to BooksSize do

Begin

MinYearI:= i;

for j:= i + 1 to BooksSize do

if Books[j].Year < Books[MinYearI].Year then MinYearI:= j;

if MinYearI <> i then

Begin

TmpBook:= Books[MinYearI];

Books[MinYearI]:= Books[i];

Books[i]:= TmpBook;

end;

end;

end;

 

PrintBooks. .

procedure PrintBooks;

Var

i: Integer;

Begin

for i:= 1 to BooksSize do

with Books[i] do

Begin

WriteLn(' #', i);

WriteLn(' : ', UDK);

WriteLn(' : ', Author);

WriteLn(' : ', Name);

WriteLn(' : ', Year);

WriteLn(' : ', Count);

end;

WriteLn;

end;


SaveBooks Books . . C:\Books. Assign. Rewrite. , , . Books. .

procedure SaveBooks;

Var

i: Integer;

BooksFile: Text;

Begin

Assign(BooksFile, 'C:\Books.txt');

{$I-}

Rewrite(BooksFile);

{$I+}

if IOResult <> 0 then

Begin

WriteLn(': ');

WriteLn(' <ENTER> ');

ReadLn;

end;

for i:= 1 to BooksSize do

with Books[i] do

Begin

WriteLn(BooksFile, ' #', i);

WriteLn(BooksFile, ' : ', UDK);

WriteLn(BooksFile, ' : ', Author);

WriteLn(BooksFile, ' : ', Name);

WriteLn(BooksFile, ' : ', Year);

WriteLn(BooksFile, ' : ', Count);

end;

Close(BooksFile);

end;

 

, , . Done BooksSize.

Begin

Done:= False;

BooksSize:= 0;

 

. .. SaveBooks .

AddBook('122.245.55', 'A. ', ' ', 1975, 5);

AddBook('122.245.56', 'A. ', '20 ', 1977, 7);

AddBook('122.245.57', '. ', ' ', 1980, 4);

AddBook('145.823.98', '.', ' -', 1982, 1);

SaveBooks;

 

. Choice .

while not Done do

Begin

ClrScr;

WriteLn(' ');

WriteLn(' : ');

WriteLn(' 1 ');

WriteLn(' 2 ');

WriteLn(' 3 ');

WriteLn(' 4 - ');

Write(' : ');

ReadLn(Choice);

ClrScr;

 

( )

case Choice of

 

, . , , , . AddBook Books. SaveBooks .

1:begin

WriteLn(' ');

WriteLn;

Write(' : ');

ReadLn(UDK);

Write(' : ');

ReadLn(Author);

Write(' : ');

ReadLn(Name);

Write(' : ');

ReadLn(Year);

Write(' : ');

ReadLn(Count);

AddBook(UDK, Author, Name, Year, Count);

SaveBooks;

end;

 

, . PrintBooks, . DeleteBook Books. , SaveBooks .

2: begin

WriteLn(' ');

PrintBooks;

Write(' : ');

ReadLn(BookIndex);

DeleteBook(BookIndex);

SaveBooks;

end;

 

, . SortBooksByYear. PrintBooks.

3: begin

WriteLn(' ');

SortBooksByYear;

PrintBooks;

WriteLn(' <ENTER> ');

ReadLn;

end;

 

, Done .

4: Done:= True;

, , .

else

begin

WriteLn(': ');

WriteLn(' <ENTER> ');

ReadLn;

end;

program LibraryDB;

uses Crt;

const MaxBooks = 100;

Type

BookType = record

UDK: String[11];

Author: String[50];

Name: String[100];

Year: Integer;

Count: Integer;

end;

Var

Done: Boolean;

Choice: Integer;

BooksSize: Integer;

Books: array [1..MaxBooks] of BookType;

BookIndex: Integer;

UDK, Author, Name: String;

Year, Count: Integer;

procedure AddBook(const AUDK, AAuthor, AName: String; AYear, ACount: Integer);

Begin

BooksSize:= BooksSize + 1;

with Books[BooksSize] do

Begin

UDK:= AUDK;

Author:= AAuthor;

Name:= AName;

Year:= AYear;

Count:= ACount;

end;

end;

 

procedure DeleteBook(BookIndex: Integer);

Var

i: Integer;

Begin

for i:= BookIndex to BooksSize - 1 do

Books[i]:= Books[i + 1];

BooksSize:= BooksSize - 1;

end;

 


procedure SortBooksByYear;

Var

i, j, MinYearI: Integer;

TmpBook: BookType;

Begin

for i:= 1 to BooksSize do

begin

MinYearI:= i;

for j:= i + 1 to BooksSize do

if Books[j].Year < Books[MinYearI].Year then MinYearI:= j;

if MinYearI <> i then

begin

TmpBook:= Books[MinYearI];

Books[MinYearI]:= Books[i];

Books[i]:= TmpBook;

end;

end;

end;

 

procedure PrintBooks;

Var

i: Integer;

Begin

for i:= 1 to BooksSize do

with Books[i] do

begin

WriteLn(' #', i);

WriteLn(' : ', UDK);

WriteLn(' : ', Author);

WriteLn(' : ', Name);

WriteLn(' : ', Year);

WriteLn(' : ', Count);

end;

WriteLn;

End;

 

procedure SaveBooks;

Var

i: Integer;

BooksFile: Text;

Begin

Assign(BooksFile, 'C:\Books.txt');

{$I-}

Rewrite(BooksFile);

{$I+}

if IOResult <> 0 then

begin

WriteLn(: );

WriteLn( <ENTER> ');

ReadLn;

end;

for i:= 1 to BooksSize do

with Books[i] do

begin

WriteLn(BooksFile, ' #', i);

WriteLn(BooksFile, ' : ', UDK);

WriteLn(BooksFile, ' : ', Author);

WriteLn(BooksFile, ' : ', Name);

WriteLn(BooksFile, ' : ', Year);

WriteLn(BooksFile, ' : ', Count);

end;

Close(BooksFile);

end;

Begin

Done:= False;

BooksSize:= 0;

AddBook('122.245.55', 'A. ', ' ', 1975, 5);

AddBook('122.245.56', 'A. ', '20 ', 1977, 7);

AddBook('122.245.57', '. ', ' ', 1980, 4);

AddBook('145.823.98', '.', ' -', 1982, 1);

SaveBooks;

while not Done do

begin

ClrScr;

WriteLn(' ');

WriteLn(' : ');

WriteLn(' 1 ');

WriteLn(' 2 ');

WriteLn(' 3 ');

WriteLn(' 4 - ');

Write(' : ');

ReadLn(Choice);

ClrScr;

case Choice of

1:begin

WriteLn(' ');

WriteLn;

Write(' : ');

ReadLn(UDK);

Write(' : ');

ReadLn(Author);

Write(' : ');

ReadLn(Name);

Write(' : ');

ReadLn(Year);

Write(' : ');

ReadLn(Count);

AddBook(UDK, Author, Name, Year, Count);

SaveBooks;

end;

2: begin

WriteLn(' ');

PrintBooks;

Write(' : ');

ReadLn(BookIndex);

DeleteBook(BookIndex);

SaveBooks;

end;

3: begin

WriteLn(' ');

SortBooksByYear;

PrintBooks;

WriteLn(' <ENTER> ');

ReadLn;

end;

4: Done:= True;

else

begin

WriteLn(': ');

WriteLn(' <ENTER> ');

ReadLn;

end;

end;

end;

end.


 

 

 

 

 


5





:


: 2018-11-11; !; : 203 |


:

:

, .
==> ...

1695 - | 1621 -


© 2015-2024 lektsii.org - -

: 0.099 .