SpringBoard / Mbed 2 deprecated SB_C_Classes

Dependencies:   mbed

Revision:
0:3f07a74c8248
diff -r 000000000000 -r 3f07a74c8248 Shape.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape.cpp	Thu Feb 14 12:04:39 2019 +0000
@@ -0,0 +1,59 @@
+// the .cpp file contains the implementation of the shape class
+
+
+#include "mbed.h"
+#include "Shape.h"  
+
+//shape constructor with single input parameter
+Shape::Shape(int a){
+    _a = a;
+    _b = -1;
+}
+
+
+//shape constructor with 2 input parameters, 
+//NOTE: the constructors do have a return type like the ones seen below
+Shape::Shape(int a, int b){
+    _a = a;
+    _b = b;
+}
+
+//calculates area and returns and int type result
+int Shape::getArea(){
+    //calculate area
+    
+    int res = 0;         //initialize variable to store result
+    if(_b == -1){       //check if _b is -1
+        res = _a * _a;
+    }else{
+        res = _a * _b;
+    }
+    return res;
+}
+
+
+//calculates perimeter and returns and int type result
+int Shape::getPerim(){
+    //calculate perimeter    
+    int res = 0;
+    if(_b == -1){   //check if _b is -1
+        res = 4 * _a;
+    }else{
+        res = 2*(_a + _b);
+    }
+    return res;
+}
+
+
+//prints information and does not return anything 'void'
+void Shape::printInfo(){
+    //print information   
+    if(_b == -1){   //check if _b is -1
+        printf("*** this is a square !\n");
+    }else{
+        printf("*** this is a rectangle!\n");
+    }
+    printf(" Area : %d \n", getArea());
+    printf(" Perimeter : %d \n", getPerim());
+}
+