Question
I need help with displaying the dupe count and the section count is slightly off. StaticArray.h: #ifndef StaticArray_h #define StaticArray_h //temepelate and class template class
I need help with displaying the dupe count and the section count is slightly off.
StaticArray.h:
#ifndef StaticArray_h #define StaticArray_h //temepelate and class templateclass StaticArray { T values[CAP];//T datatypr CAP compasity T dummy; //member functions public: StaticArray(); int capacity() const {return CAP;} T operator[](int) const;//getter T& operator[](int);//setter }; template StaticArray ::StaticArray() { for (int index = 0; index T StaticArray ::operator[](int index) const { if (index = CAP) return T(); // a copy return values[index]; // a copy } template T& StaticArray ::operator[](int index) { if (index = CAP) return dummy; // a mutable reference return values[index]; // a mutable reference } #endif
DynamicArray.h:
#ifndef DynamicArray_h #define DynamicArray_h
#include using namespace std;
template class DynamicArray { T* values; int cap; T dummy = T();
public: DynamicArray(int=2); // default consturctor DynamicArray(const DynamicArray&); // copy constructor ~DynamicArray() {delete [] values;} DynamicArray& operator=(const DynamicArray&); // assignment int capacity() const {return cap;} T operator[ ](int) const; //GETTER T& operator[ ](int); //SETTER void capacity(int); };
template DynamicArray::DynamicArray(int cap) { this->cap = cap; values = new T[cap]; for (int i = 0; i
template DynamicArray::DynamicArray(const DynamicArray& original) { cap = original.cap; values = new T[cap]; for (int i = 0; i
template T& DynamicArray::operator[](int index) { if (index = cap) capacity(2 * index); return values[index]; }
template DynamicArray& DynamicArray::operator=(const DynamicArray& original) { if (this != &original) { delete [ ] values; cap = original.cap; values = new T[cap]; for (int i = 0; i
template T DynamicArray::operator[](int index) const { if (index = cap) { return 0; } return values[index]; }
template void DynamicArray::capacity(int cap) { T* temp = new T[cap]; int limit = (cap cap ? cap : this->cap) ;
for (int i = 0; i
for (int i = limit; i
delete [ ] values; values = temp; this->cap = cap; }
#endif
Main cpp so far:
#define _CRT_SECURE_NO_WARNINGS #include "DynamicArray.h" #include "StaticArray.h" #include
struct subject { string subjectCode; int count; };
struct SectionForTerm { string term; int numberOfSectionsSeen; DynamicArray
int main() {
StaticArray
char* token; char buf[1000]; const char* const tab = "\t";
int count = 0; int dupe = 0; int numberOfTerm = 0; int subjectIndex = 0; ifstream fin; fin.open("schoolrecord.txt"); try { if (!fin.good()) cout
while (fin.good()) { string line; getline(fin, line); strcpy(buf, line.c_str());
if (buf[0] == 0) continue; //parse the line const string term(token = strtok(buf, tab)); const string section((token = strtok(0, tab)) ? token : ""); const string course((token = strtok(0, tab)) ? token : ""); const string instructor((token = strtok(0, tab)) ? token : ""); const string whenWhere((token = strtok(0, tab)) ? token : ""); if (course.find('-') == string::npos) continue; // invalid line: no dash in course name
const string subjectCode(course.begin(), course.begin() + course.find('-')); string classCode = term + "." + section;
//dupe check //check the term int i = 0, j = 0; bool d_check = false; for(i = 0; i
if(j == alreadySeen[i].numberOfSectionsSeen) { alreadySeen[i].seenSectionNumber[j] = section; alreadySeen[i].numberOfSectionsSeen++; } } //duplicate, skip the rest codes and go to the beginning of the while if(d_check) { continue; }
//finding subjectCode int s = 0; for(s = 0; s
if(s == subjectIndex) { //add student object subjectCount[subjectIndex++] = {subjectCode, 1}; } count++; } //alphabet sort cout
for (int i = 0; i subjectCount[j].subjectCode) { DynamicArray
for (int i = 0; i
schoolrecord.txt:
Fall 2021 1041 ADJUS-120 McLeran NOT AVAILABLE Fall 2021 1063 ADJUS-120 Noonan NOT AVAILABLE Fall 2021 1081 ADJUS-120 Weaver NOT AVAILABLE Fall 2021 5407 ADJUS-120 Sinsel NOT AVAILABLE Fall 2021 5408 ADJUS-120 Morrissey NOT AVAILABLE Fall 2021 5445 ADJUS-120 Morrissey NOT AVAILABLE Fall 2021 8445 ADJUS-120 Gibson NOT AVAILABLE Fall 2021 1051 ADJUS-121 Morrissey NOT AVAILABLE Fall 2021 1053 ADJUS-121 Lehman NOT AVAILABLE Fall 2021 5206 ADJUS-121 Sinsel NOT AVAILABLE Fall 2021 5404 ADJUS-121 Sinsel NOT AVAILABLE Fall 2021 9003 ADJUS-121 Ogunlana NOT AVAILABLE Fall 2021 1045 ADJUS-122 Morrissey NOT AVAILABLE Fall 2021 5401 ADJUS-122 Morrissey NOT AVAILABLE Fall 2021 8455 ADJUS-124 Harrison NOT AVAILABLE Fall 2021 1344 ADJUS-125 Martin NOT AVAILABLE Fall 2021 1059 ADJUS-130 Jordan NOT AVAILABLE Fall 2021 5231 ADJUS-130 Jordan NOT AVAILABLE Fall 2021 5370 ADJUS-130 Morrissey NOT AVAILABLE Fall 2021 5379 ADJUS-139 Verbis NOT AVAILABLE Fall 2021 1905 ADJUS-203 Kimmel-Lake NOT AVAILABLE Fall 2021 1908 ADJUS-206 Gloekler NOT AVAILABLE Fall 2021 5403 ADJUS-221 Sinsel NOT AVAILABLE Fall 2021 1073 ADJUS-222 Gloekler NOT AVAILABLE Fall 2021 5410 ADJUS-222 Morrissey NOT AVAILABLE Fall 2021 1076 ADJUS-230 Harrison NOT AVAILABLE Fall 2021 1283 ADJUS-260 Lehman NOT AVAILABLE Fall 2021 8162 ADJUS-270 Godinez NOT AVAILABLE Fall 2021 5505 ADJUS-280 Morrissey NOT AVAILABLE Fall 2021 8450 ADJUS-284 Weaver NOT AVAILABLE Fall 2021 7181 ADJUS-295 Greenberg NOT AVAILABLE Fall 2021 7182 ADJUS-296 Greenberg NOT AVAILABLE Fall 2021 2357 ADJUS-298 Morrissey NOT AVAILABLE Fall 2021 3974 ADJUS-299 Morrissey NOT AVAILABLE Fall 2021 8517 ADS-102 Duerrmeier NOT AVAILABLE Fall 2021 8530 ADS-152 Ignatowski NOT AVAILABLE Fall 2021 8290 ADS-154 Ignatowski NOT AVAILABLE Fall 2021 8350 ADS-168 Mickles NOT AVAILABLE Fall 2021 5684 ADS-171 Peterson NOT AVAILABLE Fall 2021 5685 ADS-172 Peterson NOT AVAILABLE Fall 2021 1172 ANTHR-115 Johnson NOT AVAILABLE Fall 2021 2655 ANTHR-115 Johnson NOT AVAILABLE Fall 2021 5135 ANTHR-115 Johnson NOT AVAILABLE
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 and/or your You may not use any STL containers. The default stack memory size is 1MBStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started