1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
// CIS225C1-8SampleReview.cpp : main project file.
//
/*
Open Input File
IF Input File Not Found THEN
MSG “Unable to locate File”
Return with error code -1
ENDIF
Open Output File
First_Record = True
Current_Semester = NULL
Current_Course = NULL
While NOT InputFile.EOF (End Of File)
Read Line
Call ExtractFields
IF First_Record THEN
Current_Semester = SemesterCode
Current_Course = CourseID
(note that First_Record must be set to False after printing the detail line… You need to
keep track of the first row in each semester and first course detail line for control break suppression)
ENDIF
IF current_Course <> CourseID THEN
Call CourseFooter
ENDIF
IF Current_Semester <> SemesterCode THEN
Call SemesterFooter
ENDIF
Call DetailLine
WEND
Call CourseFooter
Call SemesterFooter
RETURN
*/
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
/*
need to define input/output fileds
*/
/* ifstream inFile;
ofstream outFile; */
void extractFields(string inputLine, string &semesterCourseIDSection, string &semesterCode, string &courseID, string §ion, string &instructor, string &dow, string &time, string &building, string &room);
void reportHeader(ofstream &outFile);
void courseFooter(string currentCourse, bool &courseSupress);
void semesterFooter(string currentSemester, bool &semesterSupress);
void detailLine(string inputLine, string semesterCourseIDSection, string semesterCode, string courseID, string section, string instructor, string dow, string time, string building, string room, ofstream &outFile);
int main()
{
bool firstRecord = true;
bool semesterSupress = false;
bool courseSupress = false;
string name;
string inputLine;
string currentSemester;
string currentCourse;
string semesterCourseIDSection;
string semesterCode;
string courseID;
string section;
string instructor;
string dow;
string time;
string building;
string room;
ifstream inFile;
ofstream outFile;
//Open Input File
inFile.open("CIS225HW1DA.txt");
/*
IF Input File Not Found THEN
MSG “Unable to locate File”
Return with error code -1
ENDIF
*/
if (!inFile)
{
cout << "Input file does not exist. Program terminates." << endl;
system("pause");
return 1;
}
// Open Output File
outFile.open("Ch1-8_ReviewOutputX.txt");
// Print the report header
reportHeader(outFile);
// While NOT InputFile.EOF (End Of File)
while (inFile)
{
// Read Line
getline(inFile, inputLine);
// Call ExtractFields
extractFields(inputLine, semesterCourseIDSection, semesterCode, courseID, section, instructor, dow, time, building, room);
/*
IF First_Record THEN
Current_Semester = SemesterCode
Current_Course = CourseID
(note that First_Record must be set to False after printing the detail line… You need to
keep track of the first row in each semester and first course detail line for control break suppression)
ENDIF
*/
if (firstRecord)
{
}
/*
IF current_Course <> CourseID THEN
Call CourseFooter
ENDIF
*/
if (currentCourse != courseID)
{
courseFooter(currentCourse, courseSupress);
}
/*
IF Current_Semester <> SemesterCode THEN
Call SemesterFooter
ENDIF
*/
if (currentSemester != semesterCode)
{
semesterFooter(currentSemester, semesterSupress);
}
/*
Call DetailLine
*/
detailLine(inputLine, semesterCourseIDSection, semesterCode, courseID, section, instructor, dow, time, building, room, outFile);
}
system("pause");
inFile.close();
outFile.close();
return 0;
}
void extractFields(string inputLine, string &semesterCourseIDSection, string &semesterCode, string &courseID, string §ion, string &instructor, string &dow, string &time, string &building, string &room)
{
// this is the starting point of the data used in each line.
// this ignores the first section of data
int index = inputLine.find('|');
int count;
string fieldData;
// loops through each of the next 8 sections of the data line
// each section is place into a different variable
for (count = 1; count <= 8; count++)
{
fieldData = (inputLine.substr(index+1, inputLine.find('|',index+1)-index-1));
switch (count)
{
case 1:
semesterCode = fieldData;
break;
case 2:
courseID = fieldData;
break;
case 3:
section = fieldData;
break;
case 4:
instructor = fieldData;
break;
case 5:
dow = fieldData;
break;
case 6:
time = fieldData;
break;
case 7:
if (fieldData == "" && semesterCode != "")
{
building = "Online";
}
else
{
building = fieldData;
break;
}
case 8:
room = fieldData;
break;
default:
cout<<"Error, bad input, quitting\n";
break;
}
// sets the index of the line for the next section of data
index = inputLine.find('|',index+1);
}
return;
}
void reportHeader(ofstream &outFile)
{
string headerLine1 = " Your Home Town College [2012] ";
string headerLine2 = " CIS225-70 Course Schedule Listing [xxxx]";
outFile << headerLine1 << endl;
outFile << headerLine2 << endl;
return;
}
void courseFooter(string currentCourse, bool &courseSupress)
{
courseSupress = false;
return;
}
void semesterFooter(string currentSemester, bool &semesterSupress)
{
semesterSupress = false;
return;
}
void detailLine(string inputLine, string semesterCourseIDSection, string semesterCode, string courseID, string section, string instructor, string dow, string time, string building, string room, ofstream &outFile)
{
/*
void printCourseData(ofstream &outfile, string Section,string Instructor, string DOW, string Time, string Room, string Building)
//Output all the other data
//Section
outfile.width(11); outfile << left << Section;
//Instructor
outfile.width(14); outfile << left << Instructor;
//DOW
if(DOW == "-------"){
outfile.width(10); outfile << left << "";
}else {
outfile.width(10); outfile << left << DOW;
}
//Time
if(Time == "00:00a-00:00a"){
outfile.width(16); outfile << left << "";
}else {
outfile.width(16); outfile << left << Time;
}
//Room
outfile.width(9); outfile << left << Room;
//Building
if(Building == ""){
outfile.width(10); outfile << left << "Online";
}else {
outfile.width(10); outfile << left << Building;
}
*/
//outFile << inputLine;
outFile << courseID << " | " << section << " | " << instructor << endl;
return;
}
|