(c++)Read and parse the flat file, schedule.txt, lineby line, and find the term , section number ,...
Question:
(c++)Read and parse the flat file, schedule.txt, lineby line, and find the term,section number,course,instructor,schedule, andsubject information.
[Part 1]
Copy and paste the first couple hundred lines into another textfile. Include a count variable to count how manylines read in. Display the classCode(term+ section) and course parsed from eachline, and the total number of lines processed. Make sure thesubjectCode is processed from thecourse string correctly.
[Part 2]
After complete part 1, use the original schedule.txt. Displaythe total number of lines processed.
Submission: The source file (LabExercise4.cpp) and sampleoutput
Given code:
#define _CRT_SECURE_NO_WARNINGS#include#include #include using namespace std;#include // for strtok and strcpyint main(){ // for parsing the inputfile char* token; char buf[1000]; const char* const tab = "t"; // open the input file ifstream fin; fin.open("dvc-schedule.txt"); if (!fin.good()) cout << "I/O error. File can't find!"; // read the input file while (fin.good()) { // read the line 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)) ? 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('-')); // if I get this far, then it's a valid record cout << term << '|' << section << '|' << course << '|' << instructor << '|' << whenWhere << '|' << subjectCode << endl; } fin.close();}
==================================================
schedule.txt(there are 85917 lines)?
term section course instructor whenWhereSpring 2016 1236 MATH-142 Abaalhareth MTWTH 3:00-3:50pm MA-251Spring 2016 8104 MATH-142 Abaalhareth MTWTH 4:00-4:50pm L-143Fall 2015 8240 MATH-121 Abaalhareth W 4:00-6:50pm MA-251Fall 2015 8296 MATH-192 Abaalhareth TTH 7:00-9:50pm L-102B 9/08-12/17Spring 2005 1022 MATH-110 Abadia MTWTHF 9:00-9:50am MA-240Summer 2005 1050 MATH-110 Abadia MTWTH 8:00-11:40am LHS-212 6/21-7/28Summer 2010 1176 MATH-075 Abadia MTWTH 8:15-11:05am LA-207 6/14-7/22Summer 2008 1176 MATH-075 Abadia MTWTHMTW 8:15-11:15am LA-207 6/16-7/24Summer 2009 1176 MATH-075 Abadia MTWTHMW 8:15-11:15am LA-207 6/22-7/30Summer 2007 1176 MATH-075 Abadia MTWTHMTW 8:15-11:15am LA-207 6/18-7/26Spring 2005 2273 MATH-080K Abadia MW 1:00-2:50pm MA-107 1/18-1/30Spring 2008 8025 MATH-114 Abadia M 7:00-9:50pm MA-108Fall 2006 8066 MATH-080C Abadia MW 4:00-6:50pm MA-249 9/06-11/06Spring 2010 8111 MATH-075SP Abadia TTH 6:00-9:15pm LC-200CSpring 2010 8114 MATH-110SP Abadia TTH 6:00-9:15pm LC-200CSpring 2010 8116 MATH-120SP Abadia TTH 6:00-9:15pm LC-200CSpring 2008 8171 MATH-110 Abadia TTH 7:00-9:15pm MA-250Spring 2009 8171 MATH-110 Abadia TTH 7:00-9:15pm MA-250Spring 2007 8172 MATH-075 Abadia TTH 7:00-7:30pm LC-205Spring 2006 8172 MATH-075 Abadia TTH 7:00-7:30pm LC-205Spring 2005 8210 MATH-080K Abadia SSU 12:00-3:50pm MA-108 3/04-3/05Spring 2010 8221 MATH-050 Abadia TTH 6:00-9:15pm LC-200CSpring 2010 8222 MATH-051 Abadia TTH 6:00-9:15pm LC-200CSpring 2010 8223 MATH-052 Abadia TTH 6:00-9:15pm LC-200CFall 2007 8235 MATH-075 Abadia TTH 7:00-9:20pm MA-109 8/16-12/16Fall 2008 8235 MATH-075 Abadia TTH 7:00-9:20pm MA-241Fall 2006 8235 MATH-075 Abadia TTH 7:00-7:30pm LC-206Fall 2009 8235 MATH-075 Abadia TTH 6:00-6:50pm LA-112Fall 2010 8513 MATH-075SP Abadia TTH 6:00-9:15pm LC-200C==================================================================output sample
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill