Question: // DvcScheduleV1.cpp #include #include #include #include using namespace std; #include DynamicArray.h DynamicArray courses; DynamicArray sectionNum; int numCourse = 0; DynamicArray termSections; int numTermSection = 0;
//DvcScheduleV1.cpp
#include
#include
#include
#include
using namespace std;
#include "DynamicArray.h"
DynamicArray
DynamicArray
int numCourse = 0;
DynamicArray
int numTermSection = 0;
int numDuplicate = 0;
int totalCount = 0;
int findCourse(string course)
{
for (int i = 0; i
{
if (courses[i] == course) return i;
}
return -1;
}
int findTermSection(string term, string section)
{
for (int i = 0; i
{
if (termSections[i] == term + " " + section) return i;
}
return -1;
}
int main()
{
cout
cout
cout
char *token;
char buf[1000];
const char *const tab = "\t";
ifstream fin;
fin.open("dvc-schedule.txt");
if (!fin.good()) throw "I/O error";
string line;
getline(fin, line);
while (fin.good())
{
getline(fin, line);
strcpy(buf, line.c_str());
if (buf[0] == 0) continue;
totalCount++;
if (totalCount % 1000 == 0)
{
cout
cout.flush();
}
string term(strtok(buf, tab));
string section(strtok(0, tab));
string course(strtok(0, tab));
size_t i = course.find('-');
if (i>=course.length()) continue; // invalid line: no dash in course name
course=course.substr(0, i);
if (findTermSection(term, section) != -1)
{
numDuplicate++;
continue;
}
termSections[numTermSection] = term + " " + section;
numTermSection++;
int j = findCourse(course);
if (j == -1)
{
courses[numCourse] = course;
sectionNum[numCourse] = 1;
numCourse++;
}
else
{
sectionNum[j]++;
}
}
fin.close();
cout
for (int i = 0; i
{
for (int j = 0; j
{
if (courses[j] > courses[j + 1])
{
string temp = courses[j];
courses[j] = courses[j + 1];
courses[j + 1] = temp;
int temp2 = sectionNum[j];
sectionNum[j] = sectionNum[j + 1];
sectionNum[j + 1] = temp2;
}
}
}
for (int i = 0; i
{
cout
}
cout
cout
cout
return 0;
}
//DynamicArray.h
template
class DynamicArray
{
T* value;
int cap;
T dummy;
public:
DynamicArray(int cap = 2);
~DynamicArray();
DynamicArray(const DynamicArray
DynamicArray
T& operator[](int index);
T operator[](int index) const;
int capacity() const { return cap; }
void capacity(int cap);
};
template
DynamicArray
{
dummy = T();
this->cap = cap;
value = new T[cap];
for (int i = 0; i
{
value[i] = T();
}
}
template
DynamicArray
{
delete[] value;
}
template
DynamicArray
{
this->cap = original.cap;
this->value = new T[cap];
for (int i = 0; i
{
value[i] = original.value[i];
}
}
template
DynamicArray
{
if (this != &original)
{
delete[] value;
this->cap = original.cap;
this->value = new T[cap];
for (int i = 0; i
{
value[i] = original.value[i];
}
}
return *this;
}
template
T& DynamicArray
{
if (index
if (index >= cap) capacity(2 * index);
return value[index];
}
template
T DynamicArray
{
if (index = cap)
{
return dummy;
}
return value[index];
}
template
void DynamicArray
{
if (cap
{
return;
}
T* temp = new T[cap];
int limit = (cap cap) ? cap : this->cap;
for (int i = 0; i
{
temp[i] = value[i];
}
for (int i = limit; i
{
temp[i] = T();
}
delete[] value;
value = temp;
this->cap = cap;
}
#endif
Programming For Big Data [ DvcScheduleV2.cpp and StaticArray.h and/or DynamicArray.h ] Assignment 5 's runtime was too slow -- a couple of minutes or so. It's because of the duplicate-checking, with over 4 billion compares. Rewrite the duplicate-checking logic from Assignment 5, using a technique from "Techniques For Big Data, Reading" to do fewer compares (check the term first then section number for the duplicate check), and come up with the exact same results as Assignment 5 . You may use your StaticArray.h from Assignment 3 and/or your DynamicArray.h from assignments 4 , but you may not use any STL containers. Submit the H file(s) you use in your solution, even if there are no changes since your previous work. Your project will be compiled for grading using the default stack memory size of 1MB. Progress Bar Since this version is supposed to be fast, there is no longer a need for a progress bar. Include one if you wish (you may see the run time dramatically changed), or you may leave it out -- your choice. But if you do have a progress bar, do remember to "flush
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
