Código (cpp) [Seleccionar]
#include<iostream.h>
#include<fstream.h>
#include<math.h>
int main()
{
double h,f,pi,bm,ac,A,B,Ma,densidad,Vmolar,R,T,P,P2,Q,D,th,Z1,Z2,Z3,v,u,xr1,xr2,xr3,xi2,xi3,g,y,mayor,sumacomposiciones;
int i,j,n,k;
R=10.737;
pi=3.141592;
cout<<"Presion:";
cin>>P;
cout<<endl;
cout<<"Temperatura:";
cin>>T;
cout<<endl;
fstream entrada,salida,salida2;
entrada.open("datos.txt",ios::in);
entrada>>n;
cout<<"filas: "<<n<<endl<<endl;
entrada>>k;
cout<<"columnas: "<<k<<endl<<endl;
double Dat[n][k];
cout<<endl<<"***************Datos******************"<<endl<<endl;
for(i=0;i<n;i=i+1)
{
for(j=0;j<k;j=j+1)
{
entrada>>Dat[i][j];
cout<<Dat[i][j]<<" ";
}
cout<<endl;
}
entrada.close();
sumacomposiciones=0.0;
for(i=0;i<n;i=i+1)
{
sumacomposiciones=sumacomposiciones+Dat[i][0];
}
salida.open("calculos.txt",ios::out);
salida2.open("resultados.txt",ios::out);
if(sumacomposiciones==1.0)
{
cout<<endl<<"***************Vector a***************"<<endl<<endl;
salida<<endl<<"***************Vector a***************"<<endl<<endl;
double a[i];
for(i=0;i<n;i=i+1)
{
a[i]=0.45724*((pow((R*Dat[i][2]),2))/Dat[i][3]);
cout<<a[i]<<" ";
salida<<a[i]<<" ";
}
cout<<endl;
salida<<endl;
cout<<endl<<"***************************************"<<endl;
salida<<endl<<"***************************************"<<endl;
cout<<endl<<"***************Vector b***************"<<endl<<endl;
salida<<endl<<"***************Vector b***************"<<endl<<endl;
double b[i];
for(i=0;i<n;i=i+1)
{
b[i]=0.07780*((R*Dat[i][2])/Dat[i][3]);
cout<<b[i]<<" ";
salida<<b[i]<<" ";
}
cout<<endl;
salida<<endl;
cout<<endl<<"***************************************"<<endl;
salida<<endl<<"***************************************"<<endl;
cout<<endl<<"***************Vector m***************"<<endl<<endl;
salida<<endl<<"***************Vector m***************"<<endl<<endl;
double m[i];
for(i=0;i<n;i=i+1)
{
m[i]=0.3746+1.5423*Dat[i][4]-0.2699*pow(Dat[i][4],2);
cout<<m[i]<<" ";
salida<<m[i]<<" ";
}
cout<<endl;
salida<<endl;
cout<<endl<<"***************************************"<<endl;
salida<<endl<<"***************************************"<<endl;
cout<<endl<<"***************Vector alfa***************"<<endl<<endl;
salida<<endl<<"***************Vector alfa***************"<<endl<<endl;
double alfa[i];
for(i=0;i<n;i=i+1)
{
alfa=pow((1+m[i]*(1-pow((T/Dat[i][2]),0.5))),2);
cout<<alfa[i]<<" ";
salida<<alfa[i]<<" ";
}
cout<<endl;
salida<<endl;
cout<<endl<<"***************************************"<<endl;
salida<<endl<<"***************************************"<<endl;
cout<<endl;
salida<<endl;
bm=0.0;
for(i=0;i<n;i=i+1)
{
bm=bm+Dat[i][0]*b[i];
}
cout<<"bm=";cout<<bm<<endl<<endl;
salida<<"bm=";salida<<bm<<endl<<endl;
ac=0.0;
for(i=0;i<n;i=i+1)
{
for(j=0;j<n;j=j+1)
{
ac=ac+Dat[i][0]*Dat[j][0]*pow(a[i]*a[j]*alfa[i]*alfa[j],0.5);
}
}
cout<<"ac=";cout<<ac<<endl<<endl;
salida<<"ac=";salida<<ac<<endl<<endl;
A=(ac*P)/(pow(R*T,2));
cout<<"A=";cout<<A<<endl<<endl;
B=(bm*P)/(R*T);
cout<<"B=";cout<<B<<endl<<endl;
P2=(3*(A-3*pow(B,2)-2*B)-pow((B-1),2))/3;
cout<<"P2=";cout<<P2<<endl<<endl;
Q=(2*pow(B-1,3)-9*(B-1)*(A-3*pow(B,2)-2*B)+27*-1*(A*B-pow(B,2)-pow(B,3)))/27;
cout<<"Q=";cout<<Q<<endl<<endl;
D=pow(P2/3,3)+pow(Q/2,2);
cout<<"D=";cout<<D<<endl<<endl;
f=-Q/2;
g=pow(D,0.5);
h=fabs(f+g);
u=pow(h,1.0/3.0);
y=fabs(f-g);
v=pow(y,1.0/3.0);
Ma=0.0;
for(i=0;i<n;i=i+1)
{
Ma=Ma+(Dat[i][0]*Dat[i][1]);
}
cout<<"Ma="<<cout<<Ma<<endl<<endl;
salida2<<P<<endl<<endl;
salida2<<T<<endl<<endl;
if(D<=0.0)
{
th=acos(-Q/(2.0*pow(pow(fabs(P2),3.0)/27.0,0.5)));
Z1=(2.0*pow(fabs(P2)/3.0,0.5)*cos(th/3.0))-((B-1.0)/3.0);
Z2=(-2.0*pow(fabs(P2)/3.0,0.5)*cos(th+pi/3.0))-((B-1.0)/3.0);
Z3=(-2.0*pow(fabs(P2)/3.0,0.5)*cos(th-pi/3.0))-((B-1.0)/3.0);
cout<<"Z1="<<cout<<Z1<<endl<<endl;
cout<<"Z2="<<cout<<Z2<<endl<<endl;
cout<<"Z3="<<cout<<Z3<<endl<<endl;
if(Z3>Z1 and Z3>Z2)
{
mayor=Z3;
}
else
{
if(Z1>Z2 and Z1>Z3)
{
mayor=Z1;
}
}
if(Z2>Z3 and Z2>Z1)
{
mayor=Z2;
}
cout<<"Zg="<<cout<<mayor<<endl<<endl;
salida2<<"Zg="<<cout<<mayor<<endl<<endl;
densidad=(P*Ma)/(mayor*R*T);
Vmolar=(mayor*R*T)/P;
cout<<endl<<"***************Resultados***************"<<endl<<endl;
salida2<<endl<<"***************Resultados***************"<<endl<<endl;
cout<<"densidad="<<cout<<densidad<<endl<<endl;
salida2<<"densidad="<<salida2<<densidad<<endl<<endl;
cout<<"Volumen molar="<<cout<<Vmolar<<endl<<endl;
salida2<<"Volumen molar="<<salida2<<Vmolar<<endl<<endl;
}
else
{
xr1=(u+v)-((B-1.0)/3.0);
xr2=-1.0*((u+v)/2.0)-((B-1.0)/3.0);
xr3=-1.0*((u+v)/2.0)-((B-1.0)/3.0);
xi2=(pow(3.0,0.5)*(u-v))/2.0;
xi3=-1*(pow(3.0,0.5)*(u-v))/2.0;
cout<<"Z1="<<cout<<xr1<<endl<<endl;
cout<<"Z2="<<cout<<xr2<<" + "<<xi2<<" i "<<endl<<endl;
cout<<"Z3="<<cout<<xr3<<" + "<<xi3<<" i "<<endl<<endl;
if(xr1>xr2 and xr1>xr3)
{
mayor=xr1;
cout<<"Zg="<<cout<<xr1<<endl<<endl;
salida2<<"Zg="<<salida2<<xr1<<endl<<endl;
densidad=(P*Ma)/(xr1*R*T);
Vmolar=(xr1*R*T)/P;
cout<<endl<<"***************Resultados***************"<<endl<<endl;
salida2<<endl<<"***************Resultados***************"<<endl<<endl;
cout<<"densidad="<<cout<<densidad<<endl<<endl;
salida2<<"densidad="<<salida2<<densidad<<endl<<endl;
cout<<"Volumen molar="<<cout<<Vmolar<<endl<<endl;
salida2<<"Volumen molar="<<salida2<<Vmolar<<endl<<endl;
}
else
{
if(xr2>xr1 and xr2>xr3)
{
mayor=xr2;
cout<<"Zg="<<cout<<xr2<<" + "<<xi2<<" i "<<endl<<endl;
salida2<<"Zg="<<salida2<<xr2<<" + "<<xi2<<" i "<<endl<<endl;
densidad=(P*Ma)/(xr2*R*T);
Vmolar=(xr2*R*T)/P;
cout<<endl<<"***************Resultados***************"<<endl<<endl;
salida2<<endl<<"***************Resultados***************"<<endl<<endl;
cout<<"densidad="<<cout<<densidad<<" + "<<xi2<<" i "<<endl<<endl;
salida2<<"densidad="<<cout<<densidad<<" + "<<xi2<<" i "<<endl<<endl;
cout<<"Volumen molar="<<cout<<Vmolar<<" + "<<xi2<<" i "<<endl<<endl;
salida2<<"Volumen molar="<<cout<<Vmolar<<" + "<<xi2<<" i "<<endl<<endl;
}
}
if(xr3>xr2 and xr3>xr1)
{
mayor=xr3;
cout<<"Zg="<<cout<<xr3<<" + "<<xi3<<" i "<<endl<<endl;
salida2<<"Zg="<<cout<<xr3<<" + "<<xi3<<" i "<<endl<<endl;
densidad=(P*Ma)/(xr3*R*T);
Vmolar=(xr3*R*T)/P;
cout<<endl<<"***************Resultados***************"<<endl<<endl;
salida2<<endl<<"***************Resultados***************"<<endl<<endl;
cout<<"densidad="<<cout<<densidad<<" + "<<xi3<<" i "<<endl<<endl;
salida2<<"densidad="<<cout<<densidad<<" + "<<xi3<<" i "<<endl<<endl;
cout<<"Volumen molar="<<cout<<Vmolar<<" + "<<xi3<<" i "<<endl<<endl;
salida2<<"Volumen molar="<<cout<<Vmolar<<" + "<<xi3<<" i "<<endl<<endl;
}
}
}
else
{
cout<<endl;
cout<<"Suma de las composiciones es diferente a 1, no es valido:"<<endl;
}
salida.close();
salida2.close();
cout<<endl;
system ("pause");
return 0;
}
Desde Ma para abajo en el programa las respuestas me salen acompañadas del 0x4463c4