Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

At the end is the description of what needs to be done Here is the dvc schedule txt file https://drive.google.com/file/d/17weioi3-jPHxYNZFOY4lKsKCs8dZZZHj/view here is the code for

At the end is the description of what needs to be done

Here is the dvc schedule txt file

https://drive.google.com/file/d/17weioi3-jPHxYNZFOY4lKsKCs8dZZZHj/view

here is the code for parsing

#define _CRT_SECURE_NO_WARNINGS

// C++ libraries code block

#include

#include

#include

using namespace std;

// C libraries code block

#include // for strtok and strcpy

#include "MyDynamicArray.h"

int main( )

{

int count = 0;

// for parsing the inputfile

char* token;

char buf[1000];

const char* const tab = "\t";

MyDynamicArray a;

MyDynamicArray b;

MyDynamicArray DuplicateCheck;

// open the input file

ifstream fin;

fin.open("dvc-schedule.txt");

if (!fin.good( )) throw "I/O error";

// read the input file

while (fin.good( ))

{

// cout flush

if ( count++ == 1000) {cout << '.'; cout.flush( ); count == 0;}

// PARSING----------------------------------

string line;

getline(fin, line);

strcpy(buf, line.c_str( ));

if (buf[0] == 0) continue; // skip blank lines

// parse the line

const string term(token = strtok(buf, tab));

const string section(token = strtok(0, tab));

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('-'));

// if I get this far, then it's a valid record

// cout << subjectCode << endl;

//DUPLICATE CHECKING -------------------------

// for loop search for tem-section

//if not found, append to array

// if found, it's is a duplicate, 1) count it ,2) countinue

//COUNTING -----------------------------------

}

fin.close( );

//sort array(s)

// for loop to ouput string/int pairs ENGL 100;

}

This is my header file

#ifndef MyDynamicArray_h

#define MyDynamicArray_h

#include

template

class MyDynamicArray

{

V* values;

int cap;

V dummy;

public:

MyDynamicArray(int cap = 2); // Constructor

~MyDynamicArray(){delete [] values;} // destructor

MyDynamicArray(const MyDynamicArray&); // Copy Constructor

MyDynamicArray& operator=(const MyDynamicArray&); // Assignment Operator

void capacity(int);

int capacity() const {return cap;};

V& operator[](int); // a setter

V operator[](int) const;// a getter

};

template

MyDynamicArray::MyDynamicArray(int cap)

{

this->cap = cap;

values = new V[cap];

for (int i=0; i < cap ; i++)

values[i] = V();

}

template

MyDynamicArray::MyDynamicArray(const MyDynamicArray& original)

{

cap = original.cap;

values = new V[cap];

for (int i=0; i < cap; i++)

values[i]=original.values[i];

dummy = original.dummy;

}

template

MyDynamicArray& MyDynamicArray::operator=(const MyDynamicArray&original)

{

if(this!= &original)

{

delete [ ] values;

cap = original.cap;

values = new V[cap];

for(int i = 0; i < cap; i++)

values[i] = original.values[i];

dummy = original.dummy;

}

return *this;

}

template

void MyDynamicArray::capacity(int cap)

{

V* temp = new V[cap];

int limit = min(cap, this->cap);

for (int i = 0; i < limit; i++)

temp[i] = values[i];

for (int i = limit; i < cap; i++)

temp[i] = V();

delete [] values;

values = temp;

this->cap = cap;

}

template

V& MyDynamicArray::operator[](int index)

{

if (index < 0)

return dummy;

if (index >= cap)

capacity(2* index);

return values[index];

}

template

V MyDynamicArray::operator[](int index) const

{

if (index < 0)

return dummy;

return values[index];

}

#endif

In this lab you will have your first experience with manipulating big data. The data is extracted from the DVC database of all class sections offered at DVC since the Fall 2001 semester. Your program is to list all of the subject codes (like COMSC, MATH, PHYS, etc), and include for each subject code the count of classes (e.g., MATH, 4514 classes).

Requirements. Write a C++ console app to read and parse the 80,000 line dvc-schedule.txt (Links to an external site.)Links to an external site. text file, and find each subject code in the file. Output each code to the console screen, in alphabetical order, with the number of classes offered under that code. Use your own MyDynamicArray template from Lab Assignment 5. Do NOT use any STL containers, and do NOT modify or resubmit your lab 5 H-file except to make corrections.

NOTE: The dvc-schedule.txt file is expected to be in the working folder. In command line compiling, that's the same folder as the CPP and H files. In IDEs, you'll have to figure out for your IDE and project where is the working folder. Do notsubmit work that has a path designation in the file-open statement.

Note -- the dvc-schedule.txt file may contain duplicate entries. The combination of a term and section number is supposed to be unique. A duplicate entry is when the same term and section number pair appear in more than one record. Do NOT count duplicates -- skip them. That means to count a duplicate entry only once, ignoring all others. You'll need some way to track what's been counted so that you don't count the same section for the same semester more than once. When you are done processing the input file, output HOW MANY DUPLICATES you found and skipped in the input file. Check that number with your classmates, because you should all come up with the same number. You may use the Q&A section of this module for that.

You can expect the runtime to be several minutes. So that you don't stare at a blinking cursor while you wait for results, add a "progress bar". To do so, count the number of lines read from the file. For every 1000 lines read, output a dot -- like this:

if (count++ == 1000) {cout << '.'; cout.flush( ); count == 0;} // initialize count somewhere 

No endl. You need cout.flush( ); to force output out of the output buffer and onto the console. After the EOF loop ends, output an endl, so that your output starts on a line after the line of dots. Or use some other method of indicating progress, as you prefer, but whatever you do, do not forget to flush! Don't get this sent back for redo simply for forgetting this!

Be careful! Don't just accept whatever counts that your program gives you. Make sure that your program gives the right answers for the input file used. Try using a much shortened version of the TXT file, for which you know exactly what to expect. Also try loading the TXT file into Excel -- sort the data in column A, and count for yourself to verify the results of your app

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

Students also viewed these Databases questions

Question

Does it avoid use of underlining?

Answered: 1 week ago