example using the course class

Dependencies:   4DGL-uLCD-SE Course mbed SDFileSystem

Committer:
kkizirian
Date:
Mon Dec 05 01:01:16 2016 +0000
Revision:
1:f603609389d5
Parent:
0:6ced83c58574
Child:
2:84925a4bf964
removed some unnecessary stuff

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 1:f603609389d5 20 addCourseToVector(courseVec, course1);
kkizirian 1:f603609389d5 21 addCourseToVector(courseVec, course2);
kkizirian 1:f603609389d5 22 addCourseToVector(courseVec, course3);
kkizirian 1:f603609389d5 23 addCourseToVector(courseVec, course4);
kkizirian 1:f603609389d5 24 addCourseToVector(courseVec, course5);
kkizirian 0:6ced83c58574 25
kkizirian 0:6ced83c58574 26 uLCD.cls();
kkizirian 0:6ced83c58574 27 uLCD.locate(0, 1);
kkizirian 0:6ced83c58574 28 uLCD.printf("%s", courseVec[0].getDisplayString());
kkizirian 0:6ced83c58574 29 uLCD.locate(0, 2);
kkizirian 0:6ced83c58574 30 uLCD.printf("%s", courseVec[1].getDisplayString());
kkizirian 0:6ced83c58574 31 uLCD.locate(0, 3);
kkizirian 0:6ced83c58574 32 uLCD.printf("%s", courseVec[2].getDisplayString());
kkizirian 0:6ced83c58574 33 uLCD.locate(0, 4);
kkizirian 0:6ced83c58574 34 uLCD.printf("%s", courseVec[3].getDisplayString());
kkizirian 0:6ced83c58574 35 uLCD.locate(0, 5);
kkizirian 0:6ced83c58574 36 uLCD.printf("%s", courseVec[4].getDisplayString());
kkizirian 0:6ced83c58574 37 }
kkizirian 0:6ced83c58574 38
kkizirian 0:6ced83c58574 39 // this adds the paramter newCourse to the vector cVec in the correct
kkizirian 0:6ced83c58574 40 // location in the vector by time
kkizirian 0:6ced83c58574 41 int addCourseToVector(vector<Course>& cVec, Course newCourse) {
kkizirian 0:6ced83c58574 42
kkizirian 0:6ced83c58574 43 if (cVec.size() == 0) {
kkizirian 0:6ced83c58574 44 cVec.push_back(newCourse);
kkizirian 0:6ced83c58574 45 return 1;
kkizirian 0:6ced83c58574 46 }
kkizirian 0:6ced83c58574 47
kkizirian 0:6ced83c58574 48 for (int i = 0; i < cVec.size(); i++) {
kkizirian 0:6ced83c58574 49 if (cVec[i].getAMPM_toInt() < newCourse.getAMPM_toInt())
kkizirian 0:6ced83c58574 50 continue;
kkizirian 0:6ced83c58574 51 else if (newCourse.getAMPM_toInt() < cVec[i].getAMPM_toInt()) {
kkizirian 0:6ced83c58574 52 cVec.insert(cVec.begin()+i, newCourse);
kkizirian 0:6ced83c58574 53 return 1;
kkizirian 0:6ced83c58574 54 }
kkizirian 0:6ced83c58574 55 else if (cVec[i].getAMPM_toInt() == newCourse.getAMPM_toInt()) {
kkizirian 0:6ced83c58574 56 if (cVec[i].getHour() < newCourse.getHour())
kkizirian 0:6ced83c58574 57 continue;
kkizirian 0:6ced83c58574 58 else if (newCourse.getHour() < cVec[i].getHour()) {
kkizirian 0:6ced83c58574 59 cVec.insert(cVec.begin()+i, newCourse);
kkizirian 0:6ced83c58574 60 return 1;
kkizirian 0:6ced83c58574 61 }
kkizirian 0:6ced83c58574 62 else if (cVec[i].getHour() == newCourse.getHour()) {
kkizirian 0:6ced83c58574 63 if (cVec[i].getMinute() < newCourse.getMinute())
kkizirian 0:6ced83c58574 64 continue;
kkizirian 0:6ced83c58574 65 else if (newCourse.getMinute() < cVec[i].getMinute()) {
kkizirian 0:6ced83c58574 66 cVec.insert(cVec.begin()+i, newCourse);
kkizirian 0:6ced83c58574 67 return 1;
kkizirian 0:6ced83c58574 68 }
kkizirian 0:6ced83c58574 69 else if (cVec[i].getMinute() == newCourse.getMinute())
kkizirian 0:6ced83c58574 70 return 0;
kkizirian 0:6ced83c58574 71 }
kkizirian 0:6ced83c58574 72 }
kkizirian 0:6ced83c58574 73
kkizirian 0:6ced83c58574 74 if (i == (cVec.size() - 1)) {
kkizirian 0:6ced83c58574 75 cVec.push_back(newCourse);
kkizirian 0:6ced83c58574 76 return 1;
kkizirian 0:6ced83c58574 77 }
kkizirian 0:6ced83c58574 78 }
kkizirian 0:6ced83c58574 79 return 0;
kkizirian 0:6ced83c58574 80 }