example using the course class

Dependencies:   4DGL-uLCD-SE Course mbed SDFileSystem

Revision:
3:4984f0a32f32
Parent:
2:84925a4bf964
Child:
4:d4a652a577a0
--- a/main.cpp	Mon Dec 05 01:03:19 2016 +0000
+++ b/main.cpp	Mon Dec 05 02:50:59 2016 +0000
@@ -14,24 +14,25 @@
     Course course3("CLH", 8, 25, "AM");
     Course course4("KLS", 8, 15, "AM");
     Course course5("LVE", 2, 30, "PM");
-    
-    addCourseToVector(courseVec, course1);
-    addCourseToVector(courseVec, course2);
-    addCourseToVector(courseVec, course3);
-    addCourseToVector(courseVec, course4);
-    addCourseToVector(courseVec, course5);
-    
+    Course course6("CLH", 2, 30, "PM");
+    Course course7("CLH", 8, 15, "PM");
+
+    int test = 0;    
+    test = addCourseToVector(courseVec, course1);
+    test = addCourseToVector(courseVec, course2);
+    test = addCourseToVector(courseVec, course3);
+    test = addCourseToVector(courseVec, course4);
+    test = addCourseToVector(courseVec, course5);
+    test = addCourseToVector(courseVec, course6);
+    if (test == 0)
+        uLCD.printf("uh oh!");
+    test = addCourseToVector(courseVec, course7);
+
     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());
+    for (int i = 0; i < courseVec.size(); i++) {
+        uLCD.locate(0, i);
+        uLCD.printf("%s", courseVec[i].getDisplayString());
+    }
 }
 
 // this adds the paramter newCourse to the vector cVec in the correct
@@ -39,6 +40,8 @@
 // unsuccessful
 int addCourseToVector(vector<Course>& cVec, Course newCourse) {
 
+    int numIterations = 0;
+
     if (cVec.size() == 0) {
         cVec.push_back(newCourse);
         return 1;
@@ -69,11 +72,12 @@
                     return 0;
             }
         }
-
-        if (i == (cVec.size() - 1)) {
-            cVec.push_back(newCourse);
-            return 1;
-        }
     }
+    
+    if (numIterations == cVec.size()) {
+        cVec.push_back(newCourse);
+        return 1;
+    }
+    
     return 0;
 }