-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Course Class, modified makefile, fixing all the coredumps cause…
…d by GradePage. tested all Page-GradePage-Course classes, all works!
- Loading branch information
Showing
7 changed files
with
257 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "Course.h" | ||
|
||
Course::Course(int serial, string name, string type, double points, double hours, double grade, string additions) | ||
{ | ||
this->serialNum = serial; | ||
this->name = name; | ||
this->type = type; | ||
this->points = points; | ||
this->hours = hours; | ||
this->grade = grade; | ||
this->additions = additions; | ||
} | ||
|
||
Course::~Course() | ||
{ | ||
|
||
} | ||
|
||
void Course::printCourse() | ||
{ | ||
cout << "===== Course =====" << endl; | ||
cout << "serial: " << this->serialNum <<endl; | ||
cout << "name: " << this->name <<endl; | ||
cout << "type: " << this->type <<endl; | ||
cout << "points: " << this->points <<endl; | ||
cout << "hours: " << this->hours <<endl; | ||
cout << "grade: " << this->grade <<endl; | ||
cout << "additions: " << this->additions <<endl; | ||
cout <<endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef COURSE_H | ||
#define COURSE_H | ||
|
||
#include <string> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
/** | ||
* A simple Course Class to contain all the Course Args, | ||
* and printing them if needed. | ||
*/ | ||
class Course{ | ||
|
||
public: | ||
Course(int serial, string name, string type, double points, double hours, double grade, string additions); | ||
~Course(); | ||
void printCourse(); | ||
int getSerialNum(){return this->serialNum;} | ||
string getName(){return this->name;} | ||
string getType(){return this->type;} | ||
double getPoints(){return this->points;} | ||
double getHours(){return this->hours;} | ||
double getGrade(){return this->grade;} | ||
string getAddidtions(){return this->additions;} | ||
private: | ||
int serialNum; | ||
string name; | ||
string type; | ||
double points; | ||
double hours; | ||
double grade; | ||
string additions; | ||
}; | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,162 @@ | ||
#include "GradePage.h" | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
GradePage::GradePage(string& html) : Page(html) | ||
{ | ||
cout << "bulding GradePage..." << endl; | ||
genList(); | ||
rowSize = 6; | ||
colSize = courses.size(); | ||
cout << "finished building the GradePage" << endl; | ||
} | ||
|
||
/** | ||
* DeConstructor | ||
*/ | ||
GradePage::~GradePage() | ||
{ | ||
cout << "killing GradePage..." <<endl; | ||
courses.~list(); | ||
lines.~vector(); | ||
courseArgs.~vector(); | ||
} | ||
|
||
list<COURSE*> GradePage::getList() | ||
/** | ||
* Returns the linked list of courses | ||
*/ | ||
list<Course*> GradePage::getList() | ||
{ | ||
return this->courses; | ||
} | ||
|
||
/** | ||
* this method is the only way to get a new obj instence of this class. | ||
* for more details see the header file. | ||
* | ||
* @param html - a string with the HTML code | ||
* @return GradePage* - returns a NEW object of a GradePage | ||
*/ | ||
GradePage* GradePage::createGradeClass(string& html) | ||
{ | ||
try | ||
try //the creation of Page.cpp can throw an exception | ||
{ | ||
GradePage* newInstence = new GradePage(html); | ||
return newInstence; | ||
}catch(int err) | ||
{ | ||
cout << "ERROR: in GradePage@createGradeClass func. number " << err <<endl; | ||
cout << "ERROR: in GradePage @ createGradeClass func. number " << err <<endl; | ||
} return nullptr; | ||
} | ||
|
||
/** | ||
* this method will create a linked list of all the courses and there | ||
* details that are needed. | ||
*/ | ||
void GradePage::genList() | ||
{ | ||
string name, type, numbers; //numbers = temp text to convert to double | ||
double points, hours, grade; | ||
int i=0, temp; //indexes | ||
|
||
while(text[i] != '>') | ||
i++; | ||
i++; | ||
//Actual line with content | ||
runLine: | ||
if(text[i] == '>') | ||
i++; | ||
if(text[i] == '\t' && text[i+1] == '\t') | ||
bool first = true; // a boolean to make sure we are not getting the HTML title of the menu. | ||
tokenToLines(); //tokening the text into lines. | ||
for(string str : lines) // and then tokening every line into args for a single course. and adding it to list. | ||
{ | ||
i++; | ||
goto runLine; | ||
tokenToCourseArgs(str, first); | ||
} | ||
i++; | ||
//getting name of course; | ||
temp = i+1; | ||
temp = goToNextArg(temp); | ||
if(!isMoreToList(temp)) | ||
return; | ||
name = text.substr(i, temp); | ||
//getting type of course; | ||
i = temp+1; | ||
temp = goToNextArg(temp); | ||
if(!isMoreToList(temp)) | ||
return; | ||
type = text.substr(i, temp); | ||
//getting points | ||
i = temp+1; | ||
temp = goToNextArg(temp); | ||
if(!isMoreToList(temp)) | ||
return; | ||
numbers = text.substr(i, temp); | ||
points = atof(numbers.c_str()); | ||
//getting hours | ||
i = temp+1; | ||
temp = goToNextArg(temp); | ||
if(!isMoreToList(temp)) | ||
return; | ||
numbers = text.substr(i, temp); | ||
hours = atof(numbers.c_str()); | ||
//getting grade | ||
i = temp+1; | ||
temp = goToNextArg(temp); | ||
if(!isMoreToList(temp)) | ||
return; | ||
numbers = text.substr(i, temp); | ||
grade = atof(numbers.c_str()); | ||
|
||
//adding to list! | ||
Course c = {name, type, points, hours, grade}; | ||
|
||
courses.push_back(&c); | ||
|
||
while(text[i] != '\n') | ||
i++; | ||
i++; | ||
if(!isMoreToList(i)) | ||
return; | ||
goto runLine; | ||
} | ||
|
||
/** | ||
* Using strtok function to cut the Page.cpp text into lines and storing them into a vector. | ||
*/ | ||
void GradePage::tokenToLines() | ||
{ | ||
char *tok; | ||
char* textToTok = strdup(text.c_str()); | ||
tok = strtok(textToTok, "\n"); | ||
while(tok != NULL) | ||
{ | ||
lines.push_back(string(tok)); | ||
tok = strtok(NULL, "\n"); | ||
} | ||
free(textToTok); //cleaning memory | ||
free(tok); // cleaning memory | ||
} | ||
|
||
int GradePage::goToNextArg(int index) | ||
/** | ||
* this method gets a line of text and cutting it into args via strtok with '\t' as a separator. | ||
* pushing all the args into a vector, and if there are 8 args, this line actualy contains a course. | ||
* so we send it forward to linkCourse method. | ||
* at the end, clearing the vector for the next line to come in. | ||
* | ||
* @param line - is the line string to chop | ||
* @param first - a boolean to make sure not to get the title of the HTML table... | ||
*/ | ||
void GradePage::tokenToCourseArgs(string& line, bool& first) | ||
{ | ||
while(text[index] != '\t') | ||
index++; | ||
return index; | ||
char* tok; | ||
char* cLine = strdup(line.c_str()); | ||
tok = strtok(cLine, "\t"); | ||
while(tok != NULL) | ||
{ | ||
courseArgs.push_back(string(tok)); | ||
tok=strtok(NULL, "\t"); | ||
} | ||
if(courseArgs.size() == 8) | ||
{ if(first) | ||
first = false; | ||
else | ||
linkCourse(); | ||
} | ||
free(tok); | ||
free(cLine); | ||
courseArgs.clear(); | ||
} | ||
|
||
/** | ||
* this method will build all the variables we neet to build a Course Obj. | ||
* build it, and link it to the courses list. | ||
*/ | ||
void GradePage::linkCourse() | ||
{ | ||
int serial; | ||
string name, type, additions; | ||
double points, hours, grade; | ||
char* temp; | ||
|
||
additions = courseArgs.back(); | ||
courseArgs.pop_back(); | ||
|
||
temp = strdup(courseArgs.back().c_str()); | ||
grade = atof(temp); | ||
courseArgs.pop_back(); | ||
|
||
temp = strdup(courseArgs.back().c_str()); | ||
hours = atof(temp); | ||
courseArgs.pop_back(); | ||
|
||
temp = strdup(courseArgs.back().c_str()); | ||
points = atof(temp); | ||
courseArgs.pop_back(); | ||
|
||
type = courseArgs.back(); | ||
courseArgs.pop_back(); | ||
|
||
name = courseArgs.back(); | ||
courseArgs.pop_back(); | ||
|
||
temp = strdup(courseArgs.back().c_str()); | ||
serial = atoi(temp); | ||
courseArgs.pop_back(); | ||
|
||
//Now to add to the linked list | ||
Course* c = new Course(serial, name, type, points, hours, grade, additions); | ||
courses.push_back(c); | ||
} | ||
|
||
bool GradePage::isMoreToList(int index) | ||
/** | ||
* Uses the printCourse function in the Course class | ||
* to print the list of courses. | ||
*/ | ||
void GradePage::printCourses() | ||
{ | ||
if(index > text.length()-1) | ||
return false; | ||
return true; | ||
for(Course* c : courses) | ||
c->printCourse(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.