Lab 4 Mark_Roche

Dependencies:   mbed

main.cpp

Committer:
mark_roche
Date:
2022-05-11
Revision:
1:5a6e04b6795b
Parent:
0:2217986be753

File content as of revision 1:5a6e04b6795b:

//____Industry 4.0: Cyber Phys Systs-51296_______
//____Lab 4 Mark Roche_____

#include "mbed.h"
 
#define Invalid     0
#define Square      1
#define Rectangle   2
#define Circle      3
 
class Shape{
public:
    Shape(int a, int b) {
        _a = a;
        _b = b;
        _r = -1;
        _shap = typeis();
        
    }
 
    Shape(int r){
        _a = -1;
        _b = -1;
        _r = r;
        _shap = typeis();
        
 }
    
    int area(){
    int perimeter();
        float res = 0;
        switch (_shap){
            case (Square):
            case (Rectangle):
                res = _a*_b;
                break;
            case (Circle):
                res = 3.17 * _r * _r;
                break;
            default:
                res = -1;
                break;
        }
        return res;
    }
    int perimeter(){
        int res = 0;
        switch(_shap){
            case (Square):
                res = 4 * _a;
                break;
            case (Rectangle):
                res = 2 *(_a + _b);
                break;
            case (Circle):
                res = 2 * 3.17 * _r ;
                break;
            default:
                res = -1;
                break;
            }
            return res;
        }
        
        
        
        void type() {
            switch(_shap){
                case (Square):
                    printf("The Shape is a Square \r\n");
                    break;
                case (Rectangle):
                    printf("The Shape is a Rectangle \r\n");
                    break;
                case (Circle):
                    printf("The Shape is a Circle \r\n");
                    break;
                default:
                    printf("The Shape is Invalid \r\n");
                    break;
            }
    }
    
private:
    int _a;
    int _b;
    int _r;
    int _shap;
    
int typeis(){
        if(_r != 0)
            return (Circle);
        else
            if ((_a>0.0) && (_b>0.0)){
            if(_a == _b)
            return (Square);
        else
            return (Rectangle);        
    }else
            return (Invalid);
    }
};
 
int main() {
    printf("---------- Square 3X3 ---------- \r\n");
    Shape sqr(-3, 3);
    sqr.type();
    float a1 = sqr.area();
    printf("The area is %f\r\n", a1);
    float p1 = sqr.perimeter();
    printf("The perimeter is %f\r\n", p1);
    
    printf("\r\n---------- Rectangle 5X7 ---------- \r\n");
    Shape rec(5, 0);
    rec.type();
    float a2 = rec.area();
    printf("The area is %f\r\n", a2);
    float p2 = rec.perimeter();
    printf("The perimeter is %f\r\n", p2);
 
    printf("\r\n---------- Circle 6 ---------- \r\n");
    Shape cir(6);
    cir.type();
    float a3 = cir.area();
    printf("The area is %f\r\n", a3);
    float p3 = cir.perimeter();
    printf("The perimeter is %f\r\n", p3);
 
  {
}
 }