Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 125 additions & 22 deletions CPP019_CalculateArea_Exercise.cpp
Original file line number Diff line number Diff line change
@@ -1,96 +1,199 @@
/**
* Author: Tridib Samanta
* Created: 15.01.2020
**/

#include<iostream>

#define PI 3.14

using namespace std;

void initMenu();


void menu();

void menuDecision(int);

double areaCircle(double);

double areaSquare(double);

double areaRectangle(double,double);

double areaTriangle(double,double);

bool check_for_positive(double);



int main() {



int choice;

char cont;



do {
//system("cls");
initMenu();

menu();

cin>>choice;



menuDecision(choice);



cout<<"Do you want to continue ? (Y/N)"<<endl;

cin>>cont;

} while(cont=='Y'||cont=='y');



return 0;

}

void initMenu() {
cout<<"Select from the options :"<<endl;
cout<<"1.Circle"<<endl;
cout<<"2.Square"<<endl;
cout<<"3.Rectangle"<<endl;
cout<<"4.Triangle"<<endl;


void menu() {
cout << "____MENU____" << endl;

cout<<"1. Circle\n2. Square\n3. Rectangle\n4. Triangle"<<endl;
cout<<"Enter your choice: ";

}



void menuDecision(int ch) {

double r,a,b,h;

switch(ch) {

case 1:

cout<<"Enter the radius : "<<endl;

cin>>r;
areaCircle(r);
if(check_for_positive(r)){
cout << "Cannot find area for zero and negative." << endl;
}else{

areaCircle(r);
}

break;

case 2:

cout<<"Enter a side of the square : "<<endl;

cin>>a;
areaSquare(a);
if(check_for_positive(a)){
cout << "Cannot find area for zero and negative." << endl;
}else{

areaSquare(a);
}

break;

case 3:
cout<<"Enter the width and height of the rectangle : "<<endl;
cin>>a>>b;
areaRectangle(a,b);

cout<<"Enter the width of Rectangle: ";
cin >> a;
cout<<"Enter the height of Rectangle: ";
cin >> b;
if(check_for_positive(a)||check_for_positive(b)){
cout << "Cannot find area for zero and negative." << endl;
}else{

areaRectangle(a,b);
}

break;

case 4:
cout<<"Enter the base and height of the triangle : "<<endl;
cin>>a>>h;
areaTriangle(a,h);

cout<<"Enter the base of the triangle : ";

cin>>a;
cout<<"Enter the height of triangle: ";
cin >> h;
if(check_for_positive(a)||check_for_positive(h)){
cout << "Cannot find area for zero and negative." << endl;
}else{

areaTriangle(a,h);
}

break;

default:

cout<<"Wrong choice !"<<endl;

}

}



double areaCircle(double r) {

double result = PI *r *r;

cout<<"The area of the circle is : "<<result<<endl;

return result;

}



double areaSquare(double a) {

double result = a* a;

cout<<"The area of the Square is : "<<result<<endl;

return result;

}



double areaRectangle(double a,double b) {

double result = a* b;

cout<<"The area of the Rectangle is : "<<result<<endl;

return result;

}



double areaTriangle(double a,double h) {

double result = (1/2.0)*a*h;

cout<<"The area of the Triangle is : "<<result<<endl;

return result;

}

bool check_for_positive(double numb){
if(numb==0||numb<0){
return true;
}
return false;
}