-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoothill_EBookEntry.cpp
More file actions
159 lines (117 loc) · 4.22 KB
/
Foothill_EBookEntry.cpp
File metadata and controls
159 lines (117 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Main file for EBookEntry project. See Read Me file for details
// CIS 15C, Foothill College, Michael Loceff, creator
#include <iostream>
using namespace std;
#include "EBookEntry.h"
#include "Foothill_Sort.h"
// for timing our algorithms
#include <time.h>
// ----------- prototypes -------------
void displayOneEBook(EBookEntry book);
// --------------- main ---------------
int main()
{
int k, arraySize;
// how we read the data from files
EBookEntryReader bookInput("catalog-short4.txt");
// how we test the success of the read:
if (bookInput.readError())
{
cout << "couldn't open " << bookInput.getFileName() << " for input.\n";
exit(1);
}
cout << bookInput.getFileName() << endl;
cout << bookInput.getNumBooks() << endl;
// create an array of objects for our own use:
arraySize = bookInput.getNumBooks();
EBookEntry *bookArray = new EBookEntry[arraySize];
for (k = 0; k < arraySize; k++)
bookArray[k] = bookInput[k];
// display first 50 books (only) unsorted
for (int k = 0; k < 50; k++)
displayOneEBook(bookArray[k]);
cout << endl << "Sorting ... " << endl;
// how we time our algorithms -------------------------
clock_t startTime, stopTime;
startTime = clock();
// sort (only half since there are thousands and this is slow)
EBookEntry::setSortType(EBookEntry::SORT_BY_CREATOR);
arraySort(bookArray, arraySize/2);
cout << endl << " Sorted! " << endl << endl ;
// how we determine the time elapsed -------------------
stopTime = clock();
// display first 50 books (only) sorted
for (int k = 0; k < 50; k++)
displayOneEBook(bookArray[k]);
// report the elapsed time
cout << "\nAlgorithm Elapsed Time: "
<< (double)(stopTime - startTime)/(double)CLOCKS_PER_SEC
<< " seconds." << endl << endl;
delete[] bookArray;
return 0;
}
void displayOneEBook(EBookEntry book)
{
cout << " # "<< book.getETextNum() << " ---------------" << endl;
cout << " \"" << book.getTitle() <<"\"" << endl;
cout << " by " << book.getCreator() << endl;
cout << " re: " << book.getSubject() << endl << endl;
}
/* --------------- Tail End of Run ----------------
# 28352 ---------------
"The Children's LongfellowTold in Prose"
by Hayman, Doris
re: American poetry -- Adaptations
# 28304 ---------------
"Harper's Young People, January 13, 1880An Illustrated Weekly"
by Various
re: Children's periodicals, American
# 28322 ---------------
"Pioneer Surgery in KentuckyA Sketch"
by Yandell, David Wendel, 1826-1898
re: Surgeons -- Kentucky
# 30160 ---------------
"Christ, Christianity and the Bible"
by Haldeman, Isaac Massey, 1845-1933
re: Jesus Christ -- Divinity
Sorting ...
Sorted!
# 28351 ---------------
"Dick and His Cat and Other Tales"
by (no data found)
re: Animals -- Juvenile fiction
# 28257 ---------------
"The Story of the Great War, Volume I (of 8)Introductions; Special Articles;
Causes of War; Diplomatic and State Papers"
by (no data found)
re: World War, 1914-1918
---------------- [ snip ] ---------------
# 9506 ---------------
"Georgian Poetry 1913-15"
by (no data found)
re: (no data found)
# 29265 ---------------
"The Story of the Great War, Volume III (of 8)History of the European War fro
m Official Sources"
by (no data found)
re: World War, 1914-1918
# 30109 ---------------
"The Russian Garlandbeing Russian Folk Tales"
by (no data found)
re: Tales -- Russia
# 28282 ---------------
"Egyptian LiteratureComprising Egyptian tales, hymns, litanies, invocations,
the Book of the Dead, and cuneiform writings"
by (no data found)
re: Egyptian literature -- Translations into English
# 28907 ---------------
"Book of Philemon"
by (no data found)
re: Bible. N.T. Epistles of Paul
# 28094 ---------------
"Mediaeval Tales"
by (no data found)
re: Literature, Medieval -- Translations into English
Algorithm Elapsed Time: 2.86 seconds.
Press any key to continue . . .
-------------------------------- */