Advertisement
Icekilla

Untitled

Oct 24th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4.  
  5. int area_rectang(int base, int height);
  6. int perim_rectang(int base, int height);
  7. int area_triang(int base, int height);
  8. int perim_triang(int side1,int side2,int side3);
  9. int area_circ(int ratio);
  10. int perim_circ(int ratio);
  11. int perim_paral(int base, int height);
  12. int area_cyl(int ratio, int height);
  13. int volum_cyl(int ratio, int height);
  14. int area_sphere(int ratio);
  15. int volum_sphere(int ratio);
  16. int area_prism(int lenght,int depth,int height);
  17. int volum_prism(int lenght, int depth,int height);
  18. int area_cone(int ratio, int height);
  19. int volum_cone(int ratio, int height);
  20.  
  21.  
  22. int main()
  23. {
  24.     int opc1=0, opt2=0;
  25.     int base,height,ratio,lenght,side1,side2,side3,depth;
  26.  
  27.     printf("Geocalc 1.0\n\n");
  28.  
  29.     do{
  30.     fflush(stdin);
  31.     system("cls");
  32.     printf("Selecciona la figura con la que deseas trabajar:\n\n");
  33.     printf("1) Cuadrado o rectangulo\n2) Triangulo\n3) Circulo\n4) Paralelogramo\n5) Cilindro\n6) Esfera\n7) Prisma rectangular\n8) Cono circular\n");
  34.     scanf("%i",&opc1);
  35.  
  36.     system("cls");
  37.  
  38.     if((opc1>=1)&&(opc1<=8))
  39.      {
  40.      switch(opc1)
  41.      {
  42.  
  43.      /* Rectangle figure*/
  44.      case 1: {printf("\nInserta la medida de la base\n");
  45.               scanf("%d",&base);
  46.               printf("\nInserta la medida de la altura\n");
  47.               scanf("%d",&height);
  48.               printf("\n\nArea: %d\nPerimetro: %d\n\n",area_rectang(base,height), perim_rectang(base,height));
  49.               break;}
  50.  
  51.     /*Triangle*/
  52.      case 2: {scanf("%d",&base);
  53.               printf("\nInserta la medida de la altura\n");
  54.               scanf("%d",&height);
  55.               printf("\nInserta la medida de los tres lados\n");
  56.               scanf("%d%d%d",&side1,&side2,&side3);
  57.               printf("\n\nArea: %d\nPerimetro: %d\n\n",area_triang(base,height),perim_triang(side1,side2,side3));
  58.               break;}
  59.  
  60.      /*Circle*/
  61.      case 3: {printf("\nInserta el radio\n");
  62.               scanf("%d",&ratio);
  63.               printf("\n\nArea: %d\nPerimetro: %d\n\n",area_circ(ratio),perim_circ(ratio));
  64.               break;}
  65.  
  66.      /*Paralelogram*/
  67.      case 4: {printf("\nInserte la base\n");
  68.               scanf("%d",&base);
  69.               printf("\nInserte la altura\n");
  70.               scanf("%d",&height);
  71.               printf("\n\nArea: %d\nPerimetro: %d\n\n",area_rectang(base,height),perim_paral(base,height));
  72.               break;}
  73.      /*Cylinder*/
  74.      case 5: {printf("\nInserte el radio\n");
  75.               scanf("%d",&ratio);
  76.               printf("\nInserte la altura\n");
  77.               scanf("%d",&height);
  78.               printf("\n\nArea: %d\nVolumen: %d\n\n",area_cyl(ratio, height),volum_cyl(ratio,height));
  79.               break;}
  80.  
  81.      /*Sphere*/
  82.      case 6: {printf("\n\nInserte el radio\n");
  83.               scanf("%d",&ratio);
  84.               printf("\n\nArea: %d\nVolumen: %d\n\n",area_sphere(ratio),volum_sphere(ratio));
  85.               break;}
  86.  
  87.      /*Rectangular prism*/
  88.      case 7: {printf("\n\nInserte la longitud\n");
  89.               scanf("%d",&lenght);
  90.               printf("\nInserte la profundidad\n");
  91.               scanf("%d",&depth);
  92.               printf("\nInserte la altura\n");
  93.               scanf("%d",&height);
  94.               printf("\n\nArea: %d\nVolume: %d\n\n",area_prism(lenght,depth,height),volum_prism(lenght,depth,height));
  95.               break;}
  96.  
  97.      /*Circular cone*/
  98.      case 8: {printf("\n\nInserte el radio\n");
  99.               scanf("%d",&ratio);
  100.               printf("\nInserte la altura\n");
  101.               scanf("%d",&height);
  102.               printf("\n\nArea: %d\nVolumen: %d\n\n",area_cone(ratio,height),volum_cone(ratio,height));
  103.               break;}
  104.  
  105.      default: break;}
  106.      }
  107.     else {
  108.           printf("Opcion incorrecta");
  109.          }
  110.     printf("\n\nDesea realizar otra operacion?  1) Si  2)No\n");
  111.     getchar();
  112.     scanf("%i",&opt2);
  113.     }while(opt2==1);
  114.     return 0;
  115. }
  116.  
  117. //Functions
  118. /*Area of rectangle*/
  119. int area_rectang(int base, int height)
  120. {
  121.   return (base*height);
  122. }
  123.  
  124. /*Perimeter of rectangle*/
  125. int perim_rectang(int base, int height)
  126. {
  127.   return (2*(base+height));
  128. }
  129.  
  130. /*Area of triangle*/
  131. int area_triang(int base, int height)
  132. {
  133.   return (base*height)/2;
  134. }
  135.  
  136. /*Perimeter of triangle*/
  137. int perim_triang(int side1,int side2,int side3)
  138. {
  139.   return (side1+side2+side3);
  140. }
  141.  
  142. /*Area of circle*/
  143. int area_circ(int ratio)
  144. {
  145.   return M_PI*ratio*ratio;
  146. }
  147.  
  148. /*Perimeter of Circle*/
  149. int perim_circ(int ratio)
  150. {
  151.   return 2*M_PI*ratio;
  152. }
  153.  
  154.  
  155. /*Perimeter of Paralelogram*/
  156. int perim_paral(int base, int height)
  157. {
  158.   return (2*base)+(2*height);
  159. }
  160.  
  161. /*Area of cylinder*/
  162. int area_cyl(int ratio, int height)
  163. {
  164.   return 2*M_PI*ratio*(ratio+height);
  165. }
  166.  
  167. /*Volume of cylinder*/
  168. int volum_cyl(int ratio, int height)
  169. {
  170.   return M_PI*ratio*ratio*height;
  171. }
  172.  
  173. /*Area of sphere*/
  174. int area_sphere(int ratio)
  175. {
  176.   return 4*M_PI*ratio*ratio;
  177. }
  178.  
  179. /*volume of sphere*/
  180. int volum_sphere(int ratio)
  181. {
  182.   return (4/3)*M_PI*pow(ratio,3);
  183. }
  184.  
  185. /*Area of rectangular prism*/
  186. int area_prism(int lenght,int depth,int height)
  187. {
  188.   return 2*(lenght*depth)+2*(depth*height)+2*(height*lenght);
  189. }
  190.  
  191. /*Volume of rectangular prism*/
  192. int volum_prism(int lenght, int depth, int height)
  193. {
  194.   return lenght*depth*height;
  195. }
  196.  
  197. /*Area of cone*/
  198. int area_cone(int ratio, int height)
  199. {
  200.   return M_PI*pow(ratio,2)*sqrt(pow(height,2)+pow(ratio,2));
  201. }
  202.  
  203. /*Volume of cone*/
  204. int volum_cone(int ratio, int height)
  205. {
  206.   return (M_PI*pow(ratio,2)*height)/3;
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement