This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DvcSchedule5b.cpp
148 lines (128 loc) · 3.45 KB
/
DvcSchedule5b.cpp
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
// Lab 5b, Applying A Data Structure To A Database Program
// Programmer: Minos Park
// Editor(s) used: Sublime Text 2
// Compiler(s) used: G++
#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>
#include <string>
#include <ctime>
#include "StaticArray.h"
using namespace std;
struct SubjectCode
{
int sectionCount;
string section;
string term;
string name;
};
int main()
{
// print my name and this assignment's title
cout << "Lab 5b, Applying A Data Structure To A Database Program";
cout << "Programmer: Minos Park\n";
cout << "Editor(s) used: Sublime Text 2\n";
cout << "Compiler(s) used: G++\n";
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
Array<SubjectCode, 200> subjectCodes;
SubjectCode tmp;
vector<string> dup(1, "");
char *token;
char buf[1000];
string line;
const char* const tab = "\t";
int progressbar = 0;
int courseCount = 0;
bool check = 0;
ifstream fin;
clock_t startTime = clock();
fin.open("dvc-schedule.txt");
if (!fin.good()) throw "I/O error";
getline(fin, line); //Eliminate first line
cout << "Progress Bar";
subjectCodes[0].sectionCount = 0;
while(fin.good())
{
if(progressbar % 1000 == 0)
{
cout << ".";
cout.flush();
}
progressbar++;
check = false;
getline(fin, line);
strcpy(buf, line.c_str());
if(buf[0] == 0) continue;
const string term(token = strtok(buf, tab));
const string section(token = strtok(0, tab));
const string course((token = strtok(0, tab))?token : "");
const string courseName(course.begin(), course.begin() + course.find('-'));
tmp.name = courseName;
tmp.section = section;
tmp.term = term;
for(int i = 0; i < dup.size(); i++)
{
if((dup[i].compare(0, term.size(), term)) == 0)
{
if((dup[i].find(',' + section, 12)) != -1 )
{
subjectCodes[0].sectionCount++;
check = true;
}
else
{
dup[i] += ',' + section;
}
break;
}
if(i + 1 == dup.size())
dup.push_back((string) term + ',' + section);
}
if(check == false)
{
for (int i = 1; i <= courseCount; i++)
{
if(subjectCodes[i].name.compare(tmp.name) == 0)
{
subjectCodes[i].sectionCount ++;
check = true;
break;
}
}
}
if(check == false)
{
courseCount++;
assert(courseCount < 200);
subjectCodes[courseCount] = tmp;
subjectCodes[courseCount].sectionCount = 1;
check = true;
}
}
cout << endl << endl;
fin.close();
cout << "Total " << courseCount << " classes" << endl << endl;
for(int i = 1; i <= courseCount; i++)
{
int temp = i;
tmp = subjectCodes[i];
for(int j = i + 1; j <= courseCount; j++)
{
if((subjectCodes[j].name.compare(tmp.name)) < 0)
{
temp = j;
tmp = subjectCodes[j];
subjectCodes[temp] = subjectCodes[i];
subjectCodes[i] = tmp;
}
}
}
for(int i = 1; i <= courseCount; i++)
cout << subjectCodes[i].name << ", " << subjectCodes[i].sectionCount << " classes" << endl;
cout << endl;
cout << "Duplicates: " << subjectCodes[0].sectionCount << endl << endl;
double elapsedSeconds = (double)(clock() - startTime) / CLOCKS_PER_SEC;
cout << "Computation Time: " << elapsedSeconds << endl;
}