این با توجه به قانون گاز ایده آل کار می کند. اگر سوالی در نحوه استفاده از آن بود، حتما بپرسید.
سورس:
#include <iostream>
#include <conio.h>
using namespace std;
main()
{
int a=0,b=0;
double r=0,p=0,n=0,v=0,t=0,h=0;
cout<<"Ideal gas law"<<endl;
cout<<"By: Bardia Irajian"<<endl;
cout<<"bardiadata.blogsky.com"<<endl;
cout<<"PV=nRT"<<endl;
cout<<"Select your R unit:"<<endl;
cout<<"1.L*atm/(K*mol)"<<endl;
cout<<"2.m3*Pa/(K*mol)"<<endl;
cin>>a;
if(a==1) r=0.08205736;
if(a==2) r=8.3144621;
cout<<"Select your unknown:"<<endl;
cout<<"1.P"<<endl;
cout<<"2.V"<<endl;
cout<<"3.n"<<endl;
cout<<"4.T"<<endl;
cin>>b;
if(b!=1)
{
cout<<"Pressure: ";
cin>>p;
}
if(b!=2)
{
cout<<"Volume: ";
cin>>v;
}
if(b!=3)
{
cout<<"Mol: ";
cin>>n;
}
if(b!=4)
{
cout<<"Temperature: ";
cin>>t;
}
//Solve
if(b==1) h=n*r*t/v;
if(b==2) h=n*r*t/p;
if(b==3) h=p*v/(r*t);
if(b==4) h=p*v/(n*r);
cout<<"Answer: "<<h<<endl;
cout<<"bardiadata.blogsky.com"<<endl;
getch();
}