Skip to content

Instantly share code, notes, and snippets.

@edenizk
Created May 11, 2018 17:03
Show Gist options
  • Save edenizk/0a98691d4047919dac6ef9bac4b2e46f to your computer and use it in GitHub Desktop.
Save edenizk/0a98691d4047919dac6ef9bac4b2e46f to your computer and use it in GitHub Desktop.
area-perimeter calculator
#include <iostream>
#include <cmath>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
//int tri, squ, rect, rho, para, tra, pent, hex, oct;
int i, o=0, d, k;
float sum, a, b, c, z;
do{
cout<<"Choose what do you want calculate:\n1.area\n2.perimeter\n0.exit\n" ;
cin>>d;
if(d==2){
cout<<"Choose which plane figures perimeter you wanna calculate:\n";
cout<<"1.Triangel\n";
cout<<"2.Square\n";
cout<<"3.Rectanglen\n";
cout<<"4.Rhombus\n";
cout<<"5.Parallelogram\n";
cout<<"6.trapezoid\n";
cout<<"7.pentagon\n";
cout<<"8.hexagon\n";
cout<<"9.octagon\n";
cout<<"10.Exit\n";
cin>>k;
}
else if(d==1){
cout<<"Choose which plane figures area you wanna calculate:\n";
cout<<"1.Triangel\n";
cout<<"2.Square\n";
cout<<"3.Rectanglen\n";
cout<<"4.Rhombus\n";
cout<<"5.Parallelogram\n";
cout<<"6.trapezoid\n";
cout<<"7.pentagon\n";
cout<<"8.hexagon\n";
cout<<"9.octagon\n";
cout<<"10.Exit\n";
cin>>i;
}
else if (d==0){
break;
}
else{
cout<<"you are wrong"<<endl;
}
//perimeter
//Triangel
if (k==1){
cout<<"write side:";
cin>>a;
cout<<"write base:";
cin>>b;
cout<<"write other side:";
cin>>c;
sum=a+b+c;
cout<<"your Triangel perimeter is: "<<sum<<endl;
}
//square
else if (k==2){
cout<<"write one side of square:";
cin>>a;
sum=4*a;
cout<<"your square perimeter is: "<<sum<<endl;
}
//Rectanglen
else if (k==3){
cout<<"write length:";
cin>>a;
cout<<"write height:";
cin>>b;
sum=2*(a+b);
cout<<"your Rectanglen perimeter is: "<<sum<<endl;
}
//Rhombus
else if (k==4){
cout<<"write Side:";
cin>>a;
sum=4*a;
cout<<"your Rhombus perimeter is: "<<sum<<endl;
}
//Parallelogram
else if (k==5){
cout<<"write base:";
cin>>a;
cout<<"write side:";
cin>>b;
sum=2*(a+b);
cout<<"your Parallelogram perimeter is: "<<sum<<endl;
}
//trapezoid
else if(k==6){
cout<<"write Base:";
cin>>a;
cout<<"write Base:";
cin>>b;
cout<<"write Side:";
cin>>c;
cout<<"write other Side:";
cin>>z;
sum=a+b+c+z;
cout<<"your trapezoid perimeter is: "<<sum<<endl;
}
//pentagon
else if(k==7){
cout<<"write side:";
cin>>a;
sum=5*a;
cout<<"your pentagon perimeter is: "<<sum<<endl;
}
//hexagon
else if(k==8){
cout<<"write side:";
cin>>a;
sum=6*a;
cout<<"your hexagon perimeter is: "<<sum<<endl;
}
//octagon
else if(k==9){
cout<<"write side:";
cin>>a;
sum=8*a;
cout<<"your octagon perimeter is: "<<sum<<endl;
}
else if(k==10){
break;
}
else if (k>10) {
cout<<"I guess you typed wrong, type again\n";
}
//*******************************************************************************
//*******************************************************************************
//*******************************************************************************
//Triangel
if (i==1){
cout<<"write base:";
cin>>a;
cout<<"write height:";
cin>>b;
sum=0.5*a*b;
cout<<"area of "<<a<<" base and "<<b<<" height triangle is: "<<sum<<endl;
}
//square
else if (i==2){
cout<<"write one side of square:";
cin>>a;
sum=a*a;
cout<<"area of square with side "<<a<<" is: "<<sum<<endl;
}
//Rectanglen
else if (i==3){
cout<<"write length:";
cin>>a;
cout<<"write height:";
cin>>b;
sum=a*b;
cout<<"area of "<<a<<" base and "<<b<<" height Rectanglen is: "<<sum<<endl;
}
//Rhombus
else if (i==4){
cout<<"write d1:";
cin>>a;
cout<<"write d2:";
cin>>b;
sum=0.5*a*b;
cout<<"area of "<<a<<" d1 and "<<b<<" d2 Rhombus is: "<<sum<<endl;
}
//Parallelogram
else if (i==5){
cout<<"write base:";
cin>>a;
cout<<"write height:";
cin>>b;
sum=a*b;
cout<<"area of "<<a<<" base and "<<b<<" height Parallelogram is: "<<sum<<endl;
}
//trapezoid
else if(i==6){
cout<<"write Base:";
cin>>a;
cout<<"write Base:";
cin>>b;
cout<<"write height:";
cin>>c;
sum=0.5*c*(a+b);
cout<<"area of "<<a<<b<<" Base, base and "<<c<<" Trapezoid is: "<<sum<<endl;
}
//pentagon
else if(i==7){
cout<<"write side:";
cin>>a;
c=sqrt((5.0)*((5.0)+2.0*(sqrt(5.0))));
sum=(c*a*a)/4;
cout<<a<<" side pentagon is: "<<sum<<endl;
}
//hexagon
else if(i==8){
cout<<"write side:";
cin>>a;
sum=(3*sqrt(3.0)/2)*a*a;
cout<<a<<" side hexagon is: "<<sum<<endl;
}
else if(i==9){
cout<<"write side:";
cin>>a;
sum=2*(1+sqrt(2.0))*a*a;
cout<<a<<" side hexagon is: "<<sum<<endl;
}
else if(i==10){
break;
}
else if (i>9) {
cout<<"I guess you typed wrong, type again\n";
}
}while(o==0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment