example using the course class

Dependencies:   4DGL-uLCD-SE Course mbed SDFileSystem

Revision:
0:6ced83c58574
Child:
1:f603609389d5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 05 00:37:41 2016 +0000
@@ -0,0 +1,90 @@
+#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;
+    
+    test = addCourseToVector(courseVec, course1);
+    if (test == 0)
+        uLCD.printf("good");
+    test = addCourseToVector(courseVec, course2);
+    if (test == 0)
+        uLCD.printf("good");
+    test = addCourseToVector(courseVec, course3);
+    if (test == 0)
+        uLCD.printf("good");
+    test = addCourseToVector(courseVec, course4);
+    if (test == 0)
+        uLCD.printf("good");
+    test = addCourseToVector(courseVec, course5);
+    if (test == 0)
+        uLCD.printf("good");
+    
+    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;
+}