Question: I need help in the duplicate section. You need an array which stores the section and the term. First a for loop that goes through
I need help in the duplicate section. You need an array which stores the section and the term. First a for loop that goes through the loop and checks if there as same entry as before if we do we break and get out of the loop. the an if statement if we didn't find any thing same we append the term and section to the array and if we found something we simply increment the counter and use countinue function. I have the code just need help in the duplicate section.
// Programmers Name :
// Programmers Id: 1
#define _CRT_SECURE_NO_WARNINGS
// C++ libraries code block
#include
#include
#include
using namespace std;
// C libraries code block
#include
#include "MyDynamicArray.h"
/*struct Subjects
{
string SubjectName;
int count;
};*/
int main( )
{
cout << "Programmers Name: Muhammad Bokhari" << endl;
cout << "Programmers id: 1633547" << endl;
// for parsing the inputfile
char* token;
char buf[1000];
const char* const tab = "\t";
MyDynamicArray
MyDynamicArray
MyDynamicArray
int n = 0;
int m = 0;
int duplicates = 0;
// 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('-'));
const string Dup = term + section;
// Duplicate check-----------------------------------------------------------------
//for loop search for term+section match
// if its not found, append to array
// if its found, its a dup, (1)count it, (2) countinue
// Counting------------------------------------------------------------------------
// find Subjectcode in string array if it exsists
int i=0;
for ( i=0; i < n; i++)
{
if(a[i] == subjectCode)
break;
}
// if it deos not exsis, copy subject code to index n in string array
if(i == n)
{
a[n] = subjectCode;
b[n]++;
n++;
}
// add one to value at index in int array
else
b[i]++;
}
fin.close( );
//Sorting-----------------------------------------------------------------------------
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (a[j] < a[i])
{
swap(a[j], a[i]);
swap(b[j],b[i]);
}
for (int i = 0; i< n; i++)
cout << a[i] << ", " << b[i]<< " sections." << endl;
for (int i = 0; i < m; i++)
cout << dupCheck[i] << endl;
cout << duplicates << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
