Mark Roche
/
LAB_4_MR
Lab 4 Mark Roche
Revision 0:2217986be753, committed 2022-05-11
- Comitter:
- mark_roche
- Date:
- Wed May 11 17:27:20 2022 +0000
- Commit message:
- Lab 4 Mark Roche
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 11 17:27:20 2022 +0000 @@ -0,0 +1,128 @@ +#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); + + { +} + } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed May 11 17:27:20 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file