17
Area & Volume Calculator Description The main objective of this assignment is to design a program that can calculate the area and the volume of certain particular shape. The selected shape that the program should consist of is as below: In mathematics the area of a plane figure refers to the number of square units the figure covers. The area is the inside shape or space measured in square units. No Area Formula 1. Rectangle Area = Length x Width 2. Square Area = Length x Length 3. Triangle Area = ½ x Base x Height 4. Circle Area = π x Radius² Volume is measured in "cubic" units. No Volume Formula 1. Rectangular Solid Volume = Length x Width x Height 2. Cube Volume = Lenght³ 3. Cones Volume = 1/3 x π x Radius² x Height 4. Sphere Volume = 4/3 x π x Radius³ 1

Area & Volume Calculator

Embed Size (px)

DESCRIPTION

C Programming

Citation preview

Area & Volume Calculator Description

The main objective of this assignment is to design a program that can calculate the area and the volume of certain particular shape. The selected shape that the program should consist of is as below:In mathematics the area of a plane figure refers to the number of square units the figure covers. The area is the inside shape or space measured in square units.

NoAreaFormula

1.RectangleArea = Length x Width

2.SquareArea = Length x Length

3.TriangleArea = x Base x Height

4.CircleArea = x Radius

Volume is measured in "cubic" units. NoVolumeFormula

1.Rectangular SolidVolume = Length x Width x Height

2.CubeVolume = Lenght

3.ConesVolume = 1/3 x x Radius x Height

4.SphereVolume = 4/3 x x Radius

5.CylinderVolume = x Radius x Height

Black Book Design for AreaNo ShapeBlack BookC-Programing Code

1.Rectangle

Rec_Area = L W

B.BArea

L Rec_AreaW

Int Rec_Area (Int L , Int W){ Int Area ; Area= L * W ; Return Area ;}

2.Square

Sq_Area = L L

B.BAREA

LSq_Area

Int Sq_Area (Int L){ Int Area ; Area= L * L ; Return Area ;}

3.Triangle

Tri_Area = B H

B.BAREA

BTri_Area HInt Tri_Area (Int B , Int H){ Int Area ; Area= 0.5 * B * H ; Return Area ;}

4.Circle

Cir_Area = r

B.BAREA

rCir_AreaInt Cir_Area (Int r){ Int Area ; Area= 3.142 * r * r ; Return Area ;}

Black Book Design for VolumeNo ShapeBlack BookC-Programing Code

1.Rectangle Solid

Rec_Area = L W

B.BVol

LRec_VolW

Int Rec_Area (Int L , Int W){ Int Vol ; Vol= L * W ; Return Vol ;}

2.Cube

Cb_vol = L L L

B.BVol

LCb_Vol

Int Cb_vol (Int L){ Int Vol ; Vol= L * L * L ; Return Vol ;}

3.Cone

Con_Vol =

1/3 r H

B.BVol

rCon_Vol HInt Con_Vol (Int r , Int H){ Int Vol ; Vol= 0.33 *3.14 * r * r * H ; Return Vol ;}

4.Sphere

Sp_Vol = 4/3 r

B.BVol

rSp_VolInt Sp_Vol (Int r){ Int Vol ; Vol=1.33 * 3.14 * r * r *r ; Return Vol ;}

5.

Cylinder

Cy_Vol = r H

B.BVol

rCy_Vol HInt Cy_Vol (Int r, Int H){ Int Vol ; Vol = 3.14 * r * r *H ; Return Vol ;}

Flow Chart of the ProgramStart Program

Select Area or Volume Calculator

Shape Selection

VolumeRectangle Solid, Cube Cone, Sphere, CylinderAreaRectangle, Square, Triangle, Circle

Read data: ,r , H, L, B

r

Calculate Area or volume

Print Area or Print volume

Start program again or Terminate Program

C- Programming CodesA program to calculate the volume or area of geometry shapes

#include int main (){ int choice11; int choice22; int terminate = 1;

while( terminate == 1) { printf("Please enter\n 1 for volume\n 2 for area\n User choice : "); scanf("%d", & choice11);

if( choice11 == 1) {printf("\n\nPlease select the shape of volume: Enter: \n1 - Rectangular Solid; \n2 - Cube; \n3 - Cone; \n4 - Sphere; \n5- Cylinder; : \n\n"); scanf("%d",&choice22);

if (choice22== 4) { printf("\nShape selected: Sphere");

printf("\nEnter the radius:"); float r; scanf("%f",&r); float vol=(4.0*3.14*r*r*r)/ 3.0;

printf("\nThe Volume of Sphere: %f\n\n", vol); } else if(choice22== 1) { printf("\nShape selected: Rectangular solid");

printf("\nEnter the Length:"); float l; scanf("%f",&l);

printf("\nEnter the Width:"); float w; scanf("%f",&w);

printf("\nEnter the Height:"); float h; scanf("%f",&h); float vol = l*w*h;

printf("\nThe volume of Rectangular solid: %f\n\n", vol); } else if(choice22== 2) { printf("\nShape selected: Cube "); printf("\nEnter the side Length: "); float l; scanf("%f",&l); float vol = l*l*l; printf("\nThe Volume of Cube: %f\n\n", vol); } else if(choice22== 3) { printf("\nShape selected: Cone"); printf("\nEnter the Radius: "); float r; scanf("%f", &r); printf("\nEnter the Height: "); float h; scanf("%f", &h); float vol = (1.0*3.14*r*r*h)/ 3.0; printf("\nThe Volume of Cone: %f\n\n", vol); } else if(choice22== 5) { printf("\nShape selected: Cylinder"); printf("\nEnter the Radius:"); float r; scanf("%f",&r); printf("\nEnter the Height:"); float h; scanf("%f",&h); float vol = 3.142*r*r*h; printf("\nthe volume of Cylinder: %f\n\n", vol); }

} if (choice11 == 2) { printf("\n\nPlease select the shape of Area: Enter \n6 - Rectangle; \n7 - Square ; \n8 - Triangle; \n9 - Circle : \n\n"); scanf("%d",&choice22);

if (choice22== 9) { printf("\nShape selected: Circle "); printf("\nEnter the radius:"); float r; scanf("%f",&r); float Area = 3.14*r*r; printf("\nThe Area of Circle: %f\n\n", Area); } else if(choice22== 6) { printf("\nShape selected: Rectangle "); printf("\nEnter the Length:"); float l; scanf("%f",&l); printf("\nEnter the Width:"); float w; scanf("%f",&w); float Area = l*w; printf("\nThe Area of Rectangle: %f\n\n", Area); } else if(choice22== 7) { printf("\nShape selected: Square"); printf("\nEnter the side Length: "); float l; scanf("%f",&l); float Area = l*l; printf("\nThe Area of Square: %f\n\n", Area); } else if(choice22== 8) { printf("\nShape selected: Triangle"); printf("\nEnter the Base: "); float b; scanf("%f", &b); printf("\nEnter the Height: "); float h; scanf("%f", &h); float Area = (1*b*h)/2; printf("\nThe Area of Triangle: %f\n\n", Area); } }

printf("Enter 1 to run the program or 2 to terminate: \n"); scanf("%d",&terminate); } return 0;}

Calculation Test (AREA)Rectangle Area Area = Length x Width

Square Area Area = Length x Length

Triangle Area = x Base x Height

Circle Area = x radius

Calculation Test (VOLUME)Rectangular solid Vol = Length x Width x Height

Cube Vol = Length

Cones Vol = 1/3 x x radius x Height

Sphere Vol = 4/3 x x radius

Cylinder Vol = x radius x Height

Run Program again or terminate

1