example using the course class

Dependencies:   4DGL-uLCD-SE Course mbed SDFileSystem

Committer:
kkizirian
Date:
Mon Dec 05 00:37:41 2016 +0000
Revision:
0:6ced83c58574
Child:
1:f603609389d5
Example using the Course class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kkizirian 0:6ced83c58574 1 #include "mbed.h"
kkizirian 0:6ced83c58574 2 #include "Course.h"
kkizirian 0:6ced83c58574 3 #include <string>
kkizirian 0:6ced83c58574 4 #include <vector>
kkizirian 0:6ced83c58574 5 #include "uLCD_4DGL.h"
kkizirian 0:6ced83c58574 6
kkizirian 0:6ced83c58574 7 uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
kkizirian 0:6ced83c58574 8 vector<Course> courseVec;
kkizirian 0:6ced83c58574 9 int addCourseToVector(vector<Course>& cVec, Course newCourse);
kkizirian 0:6ced83c58574 10
kkizirian 0:6ced83c58574 11 int main() {
kkizirian 0:6ced83c58574 12 Course course1("HWY", 6, 5, "PM");
kkizirian 0:6ced83c58574 13 Course course2("LVE", 8, 10, "AM");
kkizirian 0:6ced83c58574 14 Course course3("CLH", 8, 25, "AM");
kkizirian 0:6ced83c58574 15 Course course4("KLS", 8, 15, "AM");
kkizirian 0:6ced83c58574 16 Course course5("LVE", 2, 30, "PM");
kkizirian 0:6ced83c58574 17
kkizirian 0:6ced83c58574 18 int test = 0;
kkizirian 0:6ced83c58574 19
kkizirian 0:6ced83c58574 20 test = addCourseToVector(courseVec, course1);
kkizirian 0:6ced83c58574 21 if (test == 0)
kkizirian 0:6ced83c58574 22 uLCD.printf("good");
kkizirian 0:6ced83c58574 23 test = addCourseToVector(courseVec, course2);
kkizirian 0:6ced83c58574 24 if (test == 0)
kkizirian 0:6ced83c58574 25 uLCD.printf("good");
kkizirian 0:6ced83c58574 26 test = addCourseToVector(courseVec, course3);
kkizirian 0:6ced83c58574 27 if (test == 0)
kkizirian 0:6ced83c58574 28 uLCD.printf("good");
kkizirian 0:6ced83c58574 29 test = addCourseToVector(courseVec, course4);
kkizirian 0:6ced83c58574 30 if (test == 0)
kkizirian 0:6ced83c58574 31 uLCD.printf("good");
kkizirian 0:6ced83c58574 32 test = addCourseToVector(courseVec, course5);
kkizirian 0:6ced83c58574 33 if (test == 0)
kkizirian 0:6ced83c58574 34 uLCD.printf("good");
kkizirian 0:6ced83c58574 35
kkizirian 0:6ced83c58574 36 uLCD.cls();
kkizirian 0:6ced83c58574 37 uLCD.locate(0, 1);
kkizirian 0:6ced83c58574 38 uLCD.printf("%s", courseVec[0].getDisplayString());
kkizirian 0:6ced83c58574 39 uLCD.locate(0, 2);
kkizirian 0:6ced83c58574 40 uLCD.printf("%s", courseVec[1].getDisplayString());
kkizirian 0:6ced83c58574 41 uLCD.locate(0, 3);
kkizirian 0:6ced83c58574 42 uLCD.printf("%s", courseVec[2].getDisplayString());
kkizirian 0:6ced83c58574 43 uLCD.locate(0, 4);
kkizirian 0:6ced83c58574 44 uLCD.printf("%s", courseVec[3].getDisplayString());
kkizirian 0:6ced83c58574 45 uLCD.locate(0, 5);
kkizirian 0:6ced83c58574 46 uLCD.printf("%s", courseVec[4].getDisplayString());
kkizirian 0:6ced83c58574 47 }
kkizirian 0:6ced83c58574 48
kkizirian 0:6ced83c58574 49 // this adds the paramter newCourse to the vector cVec in the correct
kkizirian 0:6ced83c58574 50 // location in the vector by time
kkizirian 0:6ced83c58574 51 int addCourseToVector(vector<Course>& cVec, Course newCourse) {
kkizirian 0:6ced83c58574 52
kkizirian 0:6ced83c58574 53 if (cVec.size() == 0) {
kkizirian 0:6ced83c58574 54 cVec.push_back(newCourse);
kkizirian 0:6ced83c58574 55 return 1;
kkizirian 0:6ced83c58574 56 }
kkizirian 0:6ced83c58574 57
kkizirian 0:6ced83c58574 58 for (int i = 0; i < cVec.size(); i++) {
kkizirian 0:6ced83c58574 59 if (cVec[i].getAMPM_toInt() < newCourse.getAMPM_toInt())
kkizirian 0:6ced83c58574 60 continue;
kkizirian 0:6ced83c58574 61 else if (newCourse.getAMPM_toInt() < cVec[i].getAMPM_toInt()) {
kkizirian 0:6ced83c58574 62 cVec.insert(cVec.begin()+i, newCourse);
kkizirian 0:6ced83c58574 63 return 1;
kkizirian 0:6ced83c58574 64 }
kkizirian 0:6ced83c58574 65 else if (cVec[i].getAMPM_toInt() == newCourse.getAMPM_toInt()) {
kkizirian 0:6ced83c58574 66 if (cVec[i].getHour() < newCourse.getHour())
kkizirian 0:6ced83c58574 67 continue;
kkizirian 0:6ced83c58574 68 else if (newCourse.getHour() < cVec[i].getHour()) {
kkizirian 0:6ced83c58574 69 cVec.insert(cVec.begin()+i, newCourse);
kkizirian 0:6ced83c58574 70 return 1;
kkizirian 0:6ced83c58574 71 }
kkizirian 0:6ced83c58574 72 else if (cVec[i].getHour() == newCourse.getHour()) {
kkizirian 0:6ced83c58574 73 if (cVec[i].getMinute() < newCourse.getMinute())
kkizirian 0:6ced83c58574 74 continue;
kkizirian 0:6ced83c58574 75 else if (newCourse.getMinute() < cVec[i].getMinute()) {
kkizirian 0:6ced83c58574 76 cVec.insert(cVec.begin()+i, newCourse);
kkizirian 0:6ced83c58574 77 return 1;
kkizirian 0:6ced83c58574 78 }
kkizirian 0:6ced83c58574 79 else if (cVec[i].getMinute() == newCourse.getMinute())
kkizirian 0:6ced83c58574 80 return 0;
kkizirian 0:6ced83c58574 81 }
kkizirian 0:6ced83c58574 82 }
kkizirian 0:6ced83c58574 83
kkizirian 0:6ced83c58574 84 if (i == (cVec.size() - 1)) {
kkizirian 0:6ced83c58574 85 cVec.push_back(newCourse);
kkizirian 0:6ced83c58574 86 return 1;
kkizirian 0:6ced83c58574 87 }
kkizirian 0:6ced83c58574 88 }
kkizirian 0:6ced83c58574 89 return 0;
kkizirian 0:6ced83c58574 90 }