1 2 2 Text File Functions q fopen

  • Slides: 138
Download presentation
1

1

2 2

2 2

Text File Functions q fopen – opens a text file. q fclose – closes

Text File Functions q fopen – opens a text file. q fclose – closes a text file. q feof – detects end-of-file marker in a file. q fscanf – reads formatted input from a file. q fprintf – prints formatted output to a file. q fgets – reads a string from a file. q fputs – prints a string to a file. q fgetc – reads a character from a file. q fputc – prints a character to a file. q fflush – empties the buffer

Practice 1

Practice 1

Practice 2

Practice 2

Practice 3

Practice 3

7 Standard Text Files Mode “w” erases, the file if it exits!

7 Standard Text Files Mode “w” erases, the file if it exits!

8 Standard Text Files

8 Standard Text Files

Read From Text File

Read From Text File

10 10

10 10

11

11

12 12

12 12

13 13

13 13

Some Applications Require More Than 24 Hours To Read A Single File! 14 14

Some Applications Require More Than 24 Hours To Read A Single File! 14 14

Text File Read Processing ØOpen File ØRead & Write To Sought Data ØRepeat! Some

Text File Read Processing ØOpen File ØRead & Write To Sought Data ØRepeat! Some Applications Require More Than 24 Hours To Read A Single File! Read Sought Data 15 Read #1 Read #2

Some Applications Require More Than 24 Hours To Read A Single File! 16

Some Applications Require More Than 24 Hours To Read A Single File! 16

Text File Change Processing ØOpen Original & Destination Files ØRead Original – Write Destination

Text File Change Processing ØOpen Original & Destination Files ØRead Original – Write Destination [up to point of change] ØWrite Change Data ØRead Original – Write Destination [remaining data] ØErase Original File & Rename Destination File Read & Write Change Data Changed Data Read & Write Change #1 17

18

18

DA File Read Processing ØOpen File ØSeek & Read Data ØRepeat! Can Often Be

DA File Read Processing ØOpen File ØSeek & Read Data ØRepeat! Can Often Be Done In Less Than 1/10 Second Hardware Dependent Sought Data 19 Read #1 Read #2

DA Change Processing ØOpen Original ØRead Original – Write Destination [up to point of

DA Change Processing ØOpen Original ØRead Original – Write Destination [up to point of change] ØWrite Change Data Read Make Change Data Write Change #1

21

21

22

22

Text Files The Choice Is Yours! Direct Access Files 23

Text Files The Choice Is Yours! Direct Access Files 23

24 24

24 24

Create Three New Direct Access File Ptrs Create File Close File Execute This Program?

Create Three New Direct Access File Ptrs Create File Close File Execute This Program? 25

What Happened As A Result Of Executing This Program? Three Files Were Created? Where?

What Happened As A Result Of Executing This Program? Three Files Were Created? Where? Find Them! 26

How Big Are The Files? How Do You Know? Right Mouse Click on the

How Big Are The Files? How Do You Know? Right Mouse Click on the file and select Properties! 27

Dir ls 28

Dir ls 28

29 Dir Wild Cards * Dir *. fil ls *. fil 29

29 Dir Wild Cards * Dir *. fil ls *. fil 29

30 About fopen Student. Fil = fopen("Student. Fil", "wb+"); Opening a file in the

30 About fopen Student. Fil = fopen("Student. Fil", "wb+"); Opening a file in the wb+ mode checks to see if there is a file by the name Student. Fil: If so, it erases the contents & positions the read/write pointer at the beginning of the empty file If not, it creates the file & positions the read/write pointer at the beginning of the empty file 30

fopen Modes Direct Access Files DAF’s

fopen Modes Direct Access Files DAF’s

32 About fclose(Student. Fil); • All files are buffered. • The buffer size can

32 About fclose(Student. Fil); • All files are buffered. • The buffer size can be set by the operating system and or the programming language. • To reduce wear and tear on the hard drives, most operating systems write information to a buffer – when the buffer is full, it is dumped to disk. • When a file is closed, the information, remaining in the buffer, is written to disk and the file allocation table is updated to reflect changes in the file. • Failure to close a file can result in lost information. 32

33 33

33 33

34 About fseek(File. Ptr, No. Bytes, SEEK_SET); SEEK_SET is a constant representing the beginning

34 About fseek(File. Ptr, No. Bytes, SEEK_SET); SEEK_SET is a constant representing the beginning of the file. SEEK_END is a constant representing the end of the file. fseek(Student. Fil, 4 * sizeof(Student), SEEK_SET); The size of each Student record is 36 Bytes. Move the Read-Write Pointer 4 * 36 = 144 bytes from the beginning of the file referenced by the Student. Fil ptr. Valid Records To Seek Are 0 – N+1 34

fseek Examples fseek(Student. Fil, 0 * sizeof(Student), SEEK_SET); fseek(Student. Fil, 0, SEEK_SET); Move the

fseek Examples fseek(Student. Fil, 0 * sizeof(Student), SEEK_SET); fseek(Student. Fil, 0, SEEK_SET); Move the Read-Write Pointer to the beginning of the file [First Record] fseek(Student. Fil, (N+1) * sizeof(Student), SEEK_SET); fseek(Student. Fil, 0 * sizeof(Student), SEEK_END); fseek(Student. Fil, 0, SEEK_END); Move the Read-Write Pointer to the end of the file [EOF Marker] – to append a new record.

36 36

36 36

About fwrite(&Info, Info. Size(byes), # records, fp); fwrite(&New. Student, sizeof(Student), (long)1, Student. Fil); Write

About fwrite(&Info, Info. Size(byes), # records, fp); fwrite(&New. Student, sizeof(Student), (long)1, Student. Fil); Write the 1 record of information referenced by New. Student, whose size is 36 Bytes, to the current Read-Write Location of the Student. Fil. Students[20] fwrite(&Students, sizeof(Student), (long)20, Student. Fil); Write the 20 records of information referenced by array Students to the current Read-Write Location of the Student. Fil. FWRITE can be used to write a single record or a block of records. 37

fwrite Examples Suppose the Output Buffer holds only two records. Student Local. Year; fseek(Student.

fwrite Examples Suppose the Output Buffer holds only two records. Student Local. Year; fseek(Student. Fil, 3 * sizeof(Student), SEEK_SET); fwrite(&Local. Year, sizeof(Student), (long)1, Student. Fil); The information is actually written to the buffer – when the buffer is full or location is changed, it is written to disk. The buffer size can be set 0 to force immediate writes! 38

39 39

39 39

Review -Valid Writes For A File With 3 Records Replace Record 0 fseek(Student. Fil,

Review -Valid Writes For A File With 3 Records Replace Record 0 fseek(Student. Fil, 0 * sizeof(Student), SEEK_SET); fwrite(&New. Student, sizeof(Student), (long)1, Student. Fil); Replace Record 1 fseek(Student. Fil, 1 * sizeof(Student), SEEK_SET); fwrite(&New. Student, sizeof(Student), (long)1, Student. Fil); Replace Record 2 fseek(Student. Fil, 2 * sizeof(Student), SEEK_SET); fwrite(&New. Student, sizeof(Student), (long)1, Student. Fil); Append/Add New Record 3 fseek(Student. Fil, 3 * sizeof(Student), SEEK_SET); fwrite(&New. Student, sizeof(Student), (long)1, Student. Fil); 40

Change To Compile The Program! 41

Change To Compile The Program! 41

Did It Do Anything? How Do You Know? Yes It Did Something! The File

Did It Do Anything? How Do You Know? Yes It Did Something! The File Is 4 Bytes Bigger Than It Was. Did It Do The Right Thing? How Do You Know? We Don’t’! How Could You Know? Read The File? 42

43 43

43 43

Create File – Open To Read Or Write File Ptrs Open An Existing File

Create File – Open To Read Or Write File Ptrs Open An Existing File To Read Or Write Execute This Program? 44

45 45

45 45

About fseek(File. Ptr, No. Bytes, SEEK_SET); SEEK_SET is a constant representing the beginning of

About fseek(File. Ptr, No. Bytes, SEEK_SET); SEEK_SET is a constant representing the beginning of the file. SEEK_END is a constant representing the end of the file. Can Do – Have Already Done! fseek(Student. Fil, 4 * sizeof(Student), SEEK_SET); The size of each Student record is 36 Bytes. Move the Read-Write Pointer 4 * 36 = 144 bytes from the beginning of the file referenced by the Student. Fil ptr. 46

47 47

47 47

About fead fread(&Info, Info. Size(byes), # records, fp); fread(&New. Student, sizeof(Student), (long)1, Student. Fil);

About fead fread(&Info, Info. Size(byes), # records, fp); fread(&New. Student, sizeof(Student), (long)1, Student. Fil); Read the 1 36 -byte record of information, pointed to by the current Read-Write Pointer of the Student. Fil, into the New. Student container. Students[20] fread(&Students, sizeof(Student), (long)20, Student. Fil); Read twenty 36 -byte records of information, pointed to by the current Read-Write Pointer of the Student. Fil, into array Students. FREAD can be used to write a single record or a block of records. 48

Suppose the Input Buffer holds only two records. Student Local. Year; fseek(Student. Fil, 2

Suppose the Input Buffer holds only two records. Student Local. Year; fseek(Student. Fil, 2 * sizeof(Student), SEEK_SET); fread(&Local. Year, sizeof(Student), (long)1, Student. Fil); Note that both Record 2 and Record 3 are in the Input Buffer. If the program logic were to need to read either of these records, they would be retrieved from the buffer as opposed to reading them from disk Much Faster [Nanosecond vs. Millisecond] 49

50 50

50 50

Valid Reads For A File With 3 Records Read Record 0 fseek(Student. Fil, 0

Valid Reads For A File With 3 Records Read Record 0 fseek(Student. Fil, 0 * sizeof(Student), SEEK_SET); fread(&New. Student, sizeof(Student), (long)1, Student. Fil); Read Record 1 fseek(Student. Fil, 1 * sizeof(Student), SEEK_SET); fread(&New. Student, sizeof(Student), (long)1, Student. Fil); Read Record 2 fseek(Student. Fil, 2 * sizeof(Student), SEEK_SET); fread(&New. Student, sizeof(Student), (long)1, Student. Fil); 51

Change To Compile The Program! 52

Change To Compile The Program! 52

Did It Do The Right Thing? Absolutely! But Will It Work For Multiple Records?

Did It Do The Right Thing? Absolutely! But Will It Work For Multiple Records? 53

Change Compile The Program! 54

Change Compile The Program! 54

Wonder What The File Looks Like With A Text Editor? 55

Wonder What The File Looks Like With A Text Editor? 55

Binary Files Provide Some Additional Security In That They Are Less Readable Than Text

Binary Files Provide Some Additional Security In That They Are Less Readable Than Text Files 56

Did It Do The Right Thing? Absolutely! But Does rb+ Really Allow Reads &

Did It Do The Right Thing? Absolutely! But Does rb+ Really Allow Reads & Writes? 57

Add This To The Program Compile The Program! 58

Add This To The Program Compile The Program! 58

Will This Really Work With Class Datatypes? 59

Will This Really Work With Class Datatypes? 59

60

60

Change To + + Compile The Program! 61

Change To + + Compile The Program! 61

Works For One Student More Extensive Auto Testing! 62

Works For One Student More Extensive Auto Testing! 62

One 36 -Byte Record

One 36 -Byte Record

Change To Compile The Program! 64

Change To Compile The Program! 64

65

65

Eight 36 -Byte Records

Eight 36 -Byte Records

67 67

67 67

Open An Existing Direct Access File FILE * Auto. Fil, * Student. Fil; Student.

Open An Existing Direct Access File FILE * Auto. Fil, * Student. Fil; Student. Fil = fopen("Student. Fil", "rb+"); Auto. Fil = fopen("Auto. Fil", "rb+"); 68

Open A New Direct Access File & Write A Record To Record 0 And

Open A New Direct Access File & Write A Record To Record 0 And A Record To Record 1 FILE * Student. Fil; Student New. Student; Student. Fil = fopen("Student. Fil", "rb+"); if (New. Student. Get()) fwrite(&New. Student, sizeof(Student), (long)1, Student. Fil); fclose(Student. Fil); 69

Open A Existing Access File Student. Fil (Has Two Records) & Add A Third

Open A Existing Access File Student. Fil (Has Two Records) & Add A Third Record` FILE * Student. Fil; Student New. Student; Move To Record 2 Third Record 0, 1, 2 Student. Fil = fopen("Student. Fil", "rb+"); fseek(Student. Fil, 2 * sizeof(Student), SEEK_SET); if (New. Student. Get()) fwrite(&New. Student, sizeof(Student), (long)1, Student. Fil); fclose(Student. Fil); 70

Open A Existing Access File Student. Fil (Has Three Records) Display All 3 Records

Open A Existing Access File Student. Fil (Has Three Records) Display All 3 Records In Reverse Order int Counter; FILE * Student. Fil; Student New. Student; Student. Fil = fopen("Student. Fil", "rb+"); Move To Record 2, 1, 0 Respectively for (Counter = 2; Counter >= 0; Counter --) { fseek(Student. Fil, Counter * sizeof(Student), SEEK_SET); fread(&New. Student, sizeof(Student), (long)1, Student. Fil); New. Student. Display(); } fclose(Student. Fil); 71

Replace Record 3 [Fourth Record] With New. Student; FILE * Student. Fil; Student. Fil

Replace Record 3 [Fourth Record] With New. Student; FILE * Student. Fil; Student. Fil = fopen("Student. Fil", "rb+"); if (New. Student. Get() == VALID) fwrite(&New. Student, sizeof(Student), (long)3, Student. Fil); fclose(Student. Fil); 72

73 73

73 73

Generic File. Length Function long int Filelength (FILE * File. Ptr, long int No.

Generic File. Length Function long int Filelength (FILE * File. Ptr, long int No. Bytes. Per. Record) { Belongs in Utilities. cpp long int Bytes; fseek (File. Ptr, 0 L, SEEK_END); Update It Now! Bytes = ftell (File. Ptr); return (Bytes / No. Bytes. Per. Record); } int Counter; FILE Test It Now! * Student. Fil; No. Records = File. Length(Student. Fil, sizeof(Student)); 74

Belongs in Utilities. hpp Generic Write. Record ///////////////////////////////////////// Update//It Now! ///////////////////////////////////////// // // Write.

Belongs in Utilities. hpp Generic Write. Record ///////////////////////////////////////// Update//It Now! ///////////////////////////////////////// // // Write. Record // // // Purpose : Write the direct access record Record. No from file *fp from container Info. No error checking yet! // // // Written By : Dr. Thomas E. Hicks Environment : Windows 2000 // Compiler : Visual C++ // // Date : XX/XX/XX ////////////////////////////////////////////////////////////////////////////////// template <class Info. Type> bool Write. Record(Info. Type *Info, long int Record. No, FILE *fp) { fseek(fp, Record. No * sizeof(Info. Type), SEEK_SET); fwrite(Info, (long)sizeof(Info. Type), 1 L, fp); return (SUCCESSFUL); } 75

Test Generic Write. Record Student New. Student; FILE Test It Now! * Student. Fil;

Test Generic Write. Record Student New. Student; FILE Test It Now! * Student. Fil; long int Counter = 0; Student. Fil = fopen("Student. Fil", "wb+"); while (New. Student. Get() == VALID) fwrite(&New. Student, sizeof(Student), Counter++, Student. Fil); fclose(Student. Fil); Not A Great Solution – Does Not Trap Errors 76 Never Returns UNSUCCESSFUL – See Chapter 11!

Belongs in Utilities. hpp Generic Read. Record Update It Now! ////////////////////////////////////////////////////////////////////////////////// // Read. Record

Belongs in Utilities. hpp Generic Read. Record Update It Now! ////////////////////////////////////////////////////////////////////////////////// // Read. Record // // // Purpose : Read the direct access record Record. No from file *fp into container Info. No error checking yet! // // // Written By : Dr. Thomas E. Hicks Environment : Windows 2000 // Compiler : Visual C++ // // Date : XX/XX/XX ////////////////////////////////////////////////////////////////////////////////// template <class Info. Type> bool Read. Record(Info. Type *Info, long int Record. No, FILE *fp) { fseek(fp, Record. No * sizeof(Info. Type), SEEK_SET); fread(Info, (long)sizeof(Info. Type), 1 L, fp); return (SUCCESSFUL); } 77

Test Generic Read. Record File Exists From Test Of Write. Record Student Test It

Test Generic Read. Record File Exists From Test Of Write. Record Student Test It Now! New. Student; FILE * Student. Fil; long int Counter, No. Records; Student. Fil = fopen("Student. Fil", "rb+"); No. Records = File. Length(Student. Fil, sizeof(Student)); for (Counter = No. Records - 1; Counter >=0; Counter --) if (Read. Record(&New. Student, Counter, Student. Fil)) New. Student. Display(); fclose(Student. Fil); Not A Great Solution – Does Not Trap Errors 78 Never Returns UNSUCCESSFUL – See Chapter 11!

79 Sequential Search

79 Sequential Search

80 Example On Computer A Suppose We Read Through Al The Records Once Record

80 Example On Computer A Suppose We Read Through Al The Records Once Record Size = 20, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec # Records R/W = ______ /sec 100. 01 1 = ----100 Reciprocal = 100/1 = 100 . 33 33 = ----100 Reciprocal = 100/33 = 3

81 Computer A - Sequential Search Text Files Or Direct Access Files Record Quantity

81 Computer A - Sequential Search Text Files Or Direct Access Files Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Un-Ordered List - Sequential Search (Worst) *. 01 = 1, 000 sec = 16. 67 min # R/W = 100, 000 _________________ Un-Ordered List - Sequential Search (Avr) *. 01 = 500 sec = 8. 33 min # R/W = 50, 000 _________________ Search Time Would Be About This For Both Text Files & Direct Access Files

82 Binary Search

82 Binary Search

83 Computer A – Binary Search Sorted Data Ordered/Sorted Direct Access Files “Ordered List”

83 Computer A – Binary Search Sorted Data Ordered/Sorted Direct Access Files “Ordered List” Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Ordered List – Binary Search (Worst) # R/W ~= log 2 (N) ~= log 2 (100, 000) = ?

On Exam/Quiz, You May Calculate Log 2 (N)

On Exam/Quiz, You May Calculate Log 2 (N)

1 1 2 2 3 4 4 8 5 16 6 32 7 64

1 1 2 2 3 4 4 8 5 16 6 32 7 64 8 128 9 256 10 1, 024 11 2, 048 12 4, 096 13 8, 192 14 16, 384 15 32, 768 16 65, 536 If There Are N Nodes At This Level Of A Complete Tree, There Are N-1 Nodes Above This Level Ball Park = ~16

86 Computer A Search 1 Record Ordered/Sorted Direct Access Files “Ordered List” Record Quantity

86 Computer A Search 1 Record Ordered/Sorted Direct Access Files “Ordered List” Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Worst Case: Sorted Read ~Log 2(100, 000) Records ~16. 6 sec

87 Computer A Search 1 Record Ordered/Sorted Direct Access Files “Ordered List” Record Quantity

87 Computer A Search 1 Record Ordered/Sorted Direct Access Files “Ordered List” Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Average Case: Sorted Read ~Log 2(100, 000)-1 Records ~16. 6 – 15. 6 sec -1? ?

To Compute Binary Exact? 88 Avr Search = Randomly Search Each Element Once 1

To Compute Binary Exact? 88 Avr Search = Randomly Search Each Element Once 1 2 2 3 2. 8 Log 2(15)=____ 3 3 3 = 1 = 4 = 12 Total Searches = 17 Avr Search = 17/7 = 2. 43

To Compute Binary Exact? 89 Avr Search = Randomly Search Each Element Once 3.

To Compute Binary Exact? 89 Avr Search = Randomly Search Each Element Once 3. 9 Log 2(15)=____ 1 2 2 3 4 3 3 4 4 4 1 = 4 = 12 3 4 = 32 Total Searches = 49 Avr Search = 49/15 = 3. 27

90 To Compute Binary Exact? Avr Search = Randomly Search Each Element Once 4.

90 To Compute Binary Exact? Avr Search = Randomly Search Each Element Once 4. 9 Log 2(31)=____ = 1 = 4 = 12 = 32 = 80 Total Searches = 129 Avr Search = 129/31 = 4. 16

91 Complete Binary Tree or Binary Search Worst Search Log 2(N) Reads Ave Search

91 Complete Binary Tree or Binary Search Worst Search Log 2(N) Reads Ave Search Log 2(N)-1 Reads

92 Edit/Change 1 Record (Don’t Know Location)

92 Edit/Change 1 Record (Don’t Know Location)

93 Computer A Edit/Change 1 Record Text Files Record Quantity = 100, 000 Bytes

93 Computer A Edit/Change 1 Record Text Files Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Any Case: Read All Records – Write All Records 200, 000 *. 01 = 1, 000 sec = 33. 33 min # R/W = _________________

94 Computer A Edit/Change 1 Record Unsorted/Unordered Direct Access Files “Unordered List” Record Quantity

94 Computer A Edit/Change 1 Record Unsorted/Unordered Direct Access Files “Unordered List” Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Worst Case: Not Sorted Read All Records & Write 1 100, 001 *. 01 = 1, 000. 01 sec = 16. 67 min Avr Case: Not Sorted Read Half Records & Write 1 50, 001 *. 01 = 500. 01 sec = 8. 33 min

95 Computer A Edit/Change 1 Record Ordered/Sorted Direct Access Files “Ordered List” Record Quantity

95 Computer A Edit/Change 1 Record Ordered/Sorted Direct Access Files “Ordered List” Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Worst Case: Not Sorted Read ~Log 2(100, 000) Records & Write 1 ~16. 6 + 1 = ~. 176 sec Avr Case: Not Sorted Read ~Log 2(100, 000)-1 Records & Write 1 ~16. 6 -1 +1 = ~. 166 sec

96 Computer A Summary – Edit/Change Record Quantity = 100, 000 Bytes Avr Read/Write

96 Computer A Summary – Edit/Change Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Text Files: Read All Records – Write All Records 200, 000 *. 01 = 1, 000 sec = 33. 33 min # R/W = _________________ Direct Access Files Worst Case: Not Sorted Read ~Log 2(100, 000) Records & Write 1 ~16. 6 + 1 = ~. 176 sec

97 Edit/Change 1 Record (Know Location)

97 Edit/Change 1 Record (Know Location)

98 Computer A Edit/Change 1 Record Ordered Or Unordered Direct Access Files Record Quantity

98 Computer A Edit/Change 1 Record Ordered Or Unordered Direct Access Files Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec Worst Case = Average Case : Sorted Or Not Sorted Read 1 Record & Write 1 Record 2 *. 01 =. 02 sec Update Record 0 Read 1 Record & Write 1 Record 4 *. 01 =. 04 sec

99 Bubble Sort To Do A Sort Accurately, We Would Have To Analyze Each

99 Bubble Sort To Do A Sort Accurately, We Would Have To Analyze Each Sort Algorithm In Depth! Even Though It Is At Best Approximate, We Are Going To Simply Use The Order Of Magnitude

100 Computer A Order N 2 Sort Files Must Be Sorted To Use The

100 Computer A Order N 2 Sort Files Must Be Sorted To Use The Binary Search N 2 Is Rough Approximation – Might Be N 2 Reads + Exchanges Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec N 2 = N * N = 100, 000 x. 01 = 100, 000. 00 secs = 1666, 666. 67 mins = 27, 777. 78 hrs = 1, 157. 41 days = 3. 17 yrs Almost All N 2 Sorts Of Random Data Would Be Worse Than This

101 Computer A Order N Log 2 N Sort Files Must Be Sorted To

101 Computer A Order N Log 2 N Sort Files Must Be Sorted To Use The Binary Search N Log 2 N Is Rough Approximation Might Be N Log 2 N Reads + Exchanges Record Quantity = 100, 000 Bytes Avr Read/Write Time = 20, 000 Byte Record =. 01 Sec 100, 000 x Log 2(100, 000) x. 01 = 16, 610. 00 secs = 276. 83 mins = 4. 61 hrs Almost All N 2 Sorts Of Random Data Would Be Worse Than This

102 Add New Record

102 Add New Record

Computer A Add New Record Unordered List Record Quantity = 100, 000 Bytes Avr

Computer A Add New Record Unordered List Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec New Data Average Case: Write New Record =. 01 Sec Update Record 0 =. 02 Sec =. 03 sec Worst Case: Write New Record =. 01 Sec Update Record 0 =. 02 Sec =. 03 sec

Computer A Add New Record (Avr Case) Ordered List - A Record Quantity =

Computer A Add New Record (Avr Case) Ordered List - A Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 20 45 Read 28 22 15 11 8 104

Computer A Add New Record (Avr Case) Ordered List - B Record Quantity =

Computer A Add New Record (Avr Case) Ordered List - B Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 20 Write 28 22 15 11 8 105

Computer A Add New Record (Avr Case) Ordered List - C Record Quantity =

Computer A Add New Record (Avr Case) Ordered List - C Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 28 20 Read 22 15 11 8 106

Computer A Add New Record (Avr Case) Ordered List - D Record Quantity =

Computer A Add New Record (Avr Case) Ordered List - D Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 20 28 Write 22 15 11 8 107

Computer A Add New Record (Avr Case) Ordered List - E Record Quantity =

Computer A Add New Record (Avr Case) Ordered List - E Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 20 28 22 Read 15 11 8 108

Computer A Add New Record (Avr Case) Ordered List - F Record Quantity =

Computer A Add New Record (Avr Case) Ordered List - F Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 20 28 22 Write 15 11 8 109

Computer A Add New Record (Avr Case) Ordered List - G Record Quantity =

Computer A Add New Record (Avr Case) Ordered List - G Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 20 28 22 15 Read 11 8 110

Computer A Add New Record (Avr Case) Ordered List - H Record Quantity =

Computer A Add New Record (Avr Case) Ordered List - H Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 Read N/2 + 1 Records 28 Write N/2 + 1 Records 22 Update = 1 Write 1 Read 20 Write 15 11 8 Average Case: N + 4 100, 004 *. 01 = 1, 000. 04 sec 111

Computer A Add New Record (Worst Case) Ordered List - H Record Quantity =

Computer A Add New Record (Worst Case) Ordered List - H Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 Read N Records 28 Write 1 Record 22 Update = 1 Write 1 Read 15 11 8 3 Worst Case: Read N + 1 & 2 Write N + 3 = 100, 003 *. 01 = 1, 000. 03 sec 112

113 Delete (Know Location)

113 Delete (Know Location)

Computer A Delete Record Unordered List Record Quantity = 100, 000 Bytes Avr Read/Write

Computer A Delete Record Unordered List Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 45 28 22 20 15 11 8 Read

Computer A Delete Record Unordered List Record Quantity = 100, 000 Bytes Avr Read/Write

Computer A Delete Record Unordered List Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec Write 28 22 45 15 11 8 If We Did Not Know Location Would Have To Add Search Time Avr = Worst Case: Read 1 & 1 Write Update 1 R & 1 W 2 R + 2 W = 4 *. 01 =. 04 sec

Computer A Delete A Record (Avr Case) Ordered List - A Record Quantity =

Computer A Delete A Record (Avr Case) Ordered List - A Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 50 45 28 22 Delete 15 11 8 116

Computer A Delete A Record (Avr Case) Ordered List - B Record Quantity =

Computer A Delete A Record (Avr Case) Ordered List - B Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 50 45 28 Read 15 11 8 117

Computer A Delete A Record (Avr Case) Ordered List - C Record Quantity =

Computer A Delete A Record (Avr Case) Ordered List - C Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 50 45 28 Write 15 11 8 118

Computer A Delete A Record (Avr Case) Ordered List - D Record Quantity =

Computer A Delete A Record (Avr Case) Ordered List - D Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 50 45 Read 28 15 11 8 119

Computer A Delete A Record (Avr Case) Ordered List - E Record Quantity =

Computer A Delete A Record (Avr Case) Ordered List - E Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 50 45 Write 28 15 11 8 120

Computer A Delete A Record (Avr Case) Ordered List - F Record Quantity =

Computer A Delete A Record (Avr Case) Ordered List - F Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec 50 Read 45 28 15 11 8 121

Computer A Delete A Record (Avr Case) Ordered List - G Record Quantity =

Computer A Delete A Record (Avr Case) Ordered List - G Record Quantity = 100, 000 Bytes Avr Read/Write Time =. 01 Sec Write 50 45 28 15 11 8 If We Did Not Know Location Would Have To Add Search Time Avr Case: Read N/2 & Write N/2 Update 1 R & 1 W N + 2 = 100, 002 *. 01 = 1, 000. 02 sec 122

123

123

Find The Executable: It Will Be In The Debug Folder!

Find The Executable: It Will Be In The Debug Folder!

Yours Will Often Be Called Project. exe

Yours Will Often Be Called Project. exe

You Can Configure The Project To Call The Executable Other Things: ? ? .

You Can Configure The Project To Call The Executable Other Things: ? ? . exe

How Can We Execute/Launch The Program? Using The Mouse Double-Click 127

How Can We Execute/Launch The Program? Using The Mouse Double-Click 127

We Can Also Launch Compiled Applications From The Command Line – Start The Command

We Can Also Launch Compiled Applications From The Command Line – Start The Command Line 128

I Copy The Location Of The Executable To The Clipboard

I Copy The Location Of The Executable To The Clipboard

Enter cd Right Mouse Click & Select Paste Then Enter The Name Of The

Enter cd Right Mouse Click & Select Paste Then Enter The Name Of The Executable & Hit Return!

There are. NET applications, that won’t run this way; This will work for all

There are. NET applications, that won’t run this way; This will work for all of our Windows Apps!

132

132

While We Are Here, How Does One Send The Output To A Text File,

While We Are Here, How Does One Send The Output To A Text File, Called Output. txt? If Your Program Requires That You Hit The Carriage Return To Continue, You Will Have To Do So! (All Prompts Will Go To The File!) If Your Program Requires That You Enter Data, You Will Have To Do So Without Seeing The Prompts! (All Prompts Will Go To The File!) 133

Open The Debug Folder! 134

Open The Debug Folder! 134

135

135

Auto. obj is Re-compiled When • Auto. hpp or Auto. cpp is altered or

Auto. obj is Re-compiled When • Auto. hpp or Auto. cpp is altered or Compile • Rebuild All! Linker Links the Obj files to form Executable! Successful Compilation Of Auto. hpp & Auto. cpp Creates Auto. obj 136

# include "Utilities. hpp" # include "Student. hpp" # include "Auto. hpp" # include

# include "Utilities. hpp" # include "Student. hpp" # include "Auto. hpp" # include "Part. hpp" There will be one obj file for each hpp/cpp set and one for Main 137

138

138