Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <string.h>
#define SIZE 1000
long double
long double
long double
long double
int loop=0;
SquareTank(float,float,float,float,float);
CilindricalTank(float,float,float,float);
SphereTank(float,float,float);
Spring(float,float);
int main()
{
int opt,opt1,opt2;
float density,lenght,width,height,n=10000,radius,k;
long double cotaA,cotaB,deltay,Area,sum=0,y;
while(loop==0){
printf("Aplications of definite integrals\n\n");
printf("Team\nHector Omar Torres Gutierrez\t\tA00226033\n");
printf("Ricardo Alejandro Romo Barreda\t\tA00959265\n");
printf("Rogelio Elizandro Molina Amavizca\tA01250798\n\n");
printf("Description\nIn this program you can calculate the work done of different
applications using The Fundamental Theorem of Calculus and Riemann Sum");
printf("\n\nPress any key to continue...");
getche();
system("cls");
}
counter=counter-1;
memset(name, '\0', sizeof(name));
printf("Enter the name of the fluid or the value of density(kg/m^3): ");
scanf("%s",name);
strcpy(comp, "0");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "1");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "2");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "3");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "4");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "5");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "6");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "7");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "8");
if(strncmp(name, comp, 1)==0)
z=0;
strcpy(comp, "9");
if(strncmp(name, comp, 1)==0)
z=0;
if(z==0)
density=(atof(name));
else
{
density=0;
for(j=0;j<counter;j++)
{
if(strcmp(name,a[j])==0)
{
density=value[j];
printf("Density = %f(kg/m^3)",density);
}
}
if(density==0)
{
printf("Liquid not found!\nDensity of the fluid (kg/m^3): ");
scanf("%f", &density);
}
}
printf("\nChoose the type of tank to be analysed\n\n");
printf("1. Square (or rectangular) tank\n");
printf("2. Cilindrical tank\n");
printf("3. Spherical tank\n");
printf("Enter option: ");
scanf("%d",&opt);
if(opt==1)
{
printf("\nDimensions of the tank (m): \n");
printf("Lenght (m): ");
scanf("%f",&lenght);
printf("Width (m): ");
scanf("%f",&width);
printf("Height (m): ");
scanf("%f",&height);
printf("\nSelect an option: \n");
printf("1. Pumping all the fluid from the tank\n");
printf("2. Pumping the fluid between especific heights\n");
printf("Option: ");
scanf("%d",&opt1);
if(opt1==1)
{
cotaA=0;
y=0;
cotaB=height;
deltay=(cotaB-cotaA)/n;
while(y<cotaB)
{
Area=deltay*((SquareTank(density,lenght,width,height,y)
+SquareTank(density,lenght,width,height,y+deltay))/2);
sum=sum+Area;
y=y+deltay;
}
if(sum>=1000)
printf("\nWork (KJ) : %Lf",sum/1000);
else
printf("\nWork (J) : %Lf",sum);
if(opt1==2)
{
printf("\nFrom level (m): ");
scanf("%Lf",&cotaA);
printf("To (m): ");
scanf("%Lf",&cotaB);
deltay=(cotaB-cotaA)/n;
y=cotaA;
while(y<cotaB)
{
Area=deltay*((SquareTank(density,lenght,width,height,y)
+SquareTank(density,lenght,width,height,y+deltay))/2);
sum=sum+Area;
y=y+deltay;
}
if(sum>=1000)
else
}
if(opt==2)
{
printf("\nDimensions of the tank\n");
printf("Radius of the circular base (m): ");
scanf("%f",&radius);
printf("Height (m): ");
scanf("%f",&height);
printf("\nSelect an option: \n");
printf("1. Pumping all the fluid from the tank\n");
printf("2. Pumping the fluid between especific heights\n");
printf("Option: ");
scanf("%d",&opt1);
if(opt1==1)
{
cotaA=0;
y=0;
cotaB=height;
deltay=(cotaB-cotaA)/n;
while(y<cotaB)
{
Area=deltay*((CilindricalTank(density,radius,height,y)
+CilindricalTank(density,radius,height,y+deltay))/2);
sum=sum+Area;
y=y+deltay;
}
if(sum>=1000)
else
}
if(opt1==2)
{
printf("\nFrom level (m): ");
scanf("%Lf",&cotaA);
printf("To (m): ");
scanf("%Lf",&cotaB);
deltay=(cotaB-cotaA)/n;
y=cotaA;
while(y<cotaB)
{
Area=deltay*((CilindricalTank(density,radius,height,y)
+CilindricalTank(density,radius,height,y+deltay))/2);
sum=sum+Area;
y=y+deltay;
}
if(sum>=1000)
else
}
}
if(opt==3)
{
printf("Radius of the sphere (m): ");
scanf("%f",&radius);
printf("\nSelect an option: \n");
printf("1. Pumping all the fluid from the tank\n");
printf("2. Pumping the fluid between especific heights\n");
printf("Option: ");
scanf("%d",&opt1);
if(opt1==1)
{
cotaA=0;
y=cotaA;
cotaB=radius+radius;
deltay=(cotaB-cotaA)/n;
while(y<cotaB)
{
Area=deltay*((SphereTank(density,radius,y)+SphereTank(density,radius,y+deltay))/2);
sum=sum+Area;
y=y+deltay;
}
if(sum>=1000)
else
}
if(opt1==2)
{
printf("\nFrom level (m): ");
scanf("%Lf",&cotaA);
printf("To (m): ");
scanf("%Lf",&cotaB);
deltay=(cotaB-cotaA)/n;
y=cotaA;
while(y<cotaB)
{
Area=deltay*((SphereTank(density,radius,y)+SphereTank(density,radius,y+deltay))/2);
sum=sum+Area;
y=y+deltay;
}
if(sum>=1000)
else
}
}
}
if(opt2==2)
{
printf("Spring constant (N/m): ");
scanf("%f",&k);
printf("From the point (m): ");
scanf("%Lf",&cotaA);
printf("To: ");
scanf("%Lf",&cotaB);
deltay=(cotaB-cotaA)/n;
y=cotaA;
while(y<cotaB)
{
Area=deltay*((Spring(k,y)+Spring(k,y+deltay))/2);
sum=sum+Area;
y=y+deltay;
}
if(sum>=1000)
}
long double LineDens, distance,s;
if(opt2==3)
{
printf("\n\n\n\n");
fclose(fptr);
printf("Press any key to continue..");
getche();
system("cls");
}
long double SquareTank(float density, float lenght, float width, float height, float y)
{
return((density*9.81*lenght*width*height)-(density*9.81*lenght*width*y));
}
long double CilindricalTank(float density, float radius, float height, float y)
{
return((density*9.81*radius*radius*3.141592653589793238462643)*(height-y));
}
long double SphereTank(float density, float radius, float y)
return(density*9.8*3.141592653589793238462643*(2*radius*y-(y*y))*((2*radius)-y));
}
long double Spring(float k, float y)
{
return(k*y);
}