example using the course class
Dependencies: 4DGL-uLCD-SE Course mbed SDFileSystem
main.cpp
- Committer:
- kkizirian
- Date:
- 2016-12-05
- Revision:
- 1:f603609389d5
- Parent:
- 0:6ced83c58574
- Child:
- 2:84925a4bf964
File content as of revision 1:f603609389d5:
#include "mbed.h" #include "Course.h" #include <string> #include <vector> #include "uLCD_4DGL.h" uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; vector<Course> courseVec; int addCourseToVector(vector<Course>& cVec, Course newCourse); int main() { Course course1("HWY", 6, 5, "PM"); Course course2("LVE", 8, 10, "AM"); Course course3("CLH", 8, 25, "AM"); Course course4("KLS", 8, 15, "AM"); Course course5("LVE", 2, 30, "PM"); int test = 0; addCourseToVector(courseVec, course1); addCourseToVector(courseVec, course2); addCourseToVector(courseVec, course3); addCourseToVector(courseVec, course4); addCourseToVector(courseVec, course5); uLCD.cls(); uLCD.locate(0, 1); uLCD.printf("%s", courseVec[0].getDisplayString()); uLCD.locate(0, 2); uLCD.printf("%s", courseVec[1].getDisplayString()); uLCD.locate(0, 3); uLCD.printf("%s", courseVec[2].getDisplayString()); uLCD.locate(0, 4); uLCD.printf("%s", courseVec[3].getDisplayString()); uLCD.locate(0, 5); uLCD.printf("%s", courseVec[4].getDisplayString()); } // this adds the paramter newCourse to the vector cVec in the correct // location in the vector by time int addCourseToVector(vector<Course>& cVec, Course newCourse) { if (cVec.size() == 0) { cVec.push_back(newCourse); return 1; } for (int i = 0; i < cVec.size(); i++) { if (cVec[i].getAMPM_toInt() < newCourse.getAMPM_toInt()) continue; else if (newCourse.getAMPM_toInt() < cVec[i].getAMPM_toInt()) { cVec.insert(cVec.begin()+i, newCourse); return 1; } else if (cVec[i].getAMPM_toInt() == newCourse.getAMPM_toInt()) { if (cVec[i].getHour() < newCourse.getHour()) continue; else if (newCourse.getHour() < cVec[i].getHour()) { cVec.insert(cVec.begin()+i, newCourse); return 1; } else if (cVec[i].getHour() == newCourse.getHour()) { if (cVec[i].getMinute() < newCourse.getMinute()) continue; else if (newCourse.getMinute() < cVec[i].getMinute()) { cVec.insert(cVec.begin()+i, newCourse); return 1; } else if (cVec[i].getMinute() == newCourse.getMinute()) return 0; } } if (i == (cVec.size() - 1)) { cVec.push_back(newCourse); return 1; } } return 0; }