Test instructions
Know three variables to ask for one remaining variable. where r is the known constant = 8.314. Where v,t must be greater than 0. If there is a contradiction, output error. If an indeterminate condition occurs, the output undefined. It's a clever idea.
1#include <iostream>2#include <string.h>3#include <iomanip>4#include <algorithm>5 using namespacestd;6 DoubleR =8.314;7 inta[5];8 Chars1[Ten],s2[Ten];9 intInitCharstr[Ten])Ten { One if(str[0]=='P')return 1; A Else if(str[0]=='V')return 2; - Else if(str[0]=='N')return 3; - Else if(str[0]=='T')return 4; the } - voidf () - { - if(a[1]==0&& a[3]==0) cout<<"undefined"<<Endl; + Else if(a[1]==0&& a[3]!=0) - { + if(a[2]==-1) cout<<"Error"<<Endl; A if(a[3]==-1) cout<<"n = 0"<<Endl; at if(a[4]==-1) cout<<"Error"<<Endl; - } - Else if(a[1]!=0&& a[3]==0) - { - if(a[1]==-1) cout<<"p = 0"<<Endl; - if(a[2]==-1) cout<<"Error"<<Endl; in if(a[4]==-1) cout<<"Error"<<Endl; - } to Else if(a[1]!=0&& a[3]!=0) + { - if(a[1]==-1) cout<<"p ="<<setiosflags (iOS::fixed) <<setprecision (6) << (Double) a[3]*a[4]*r/a[2]<<Endl; the if(a[2]==-1) cout<<"V ="<<setiosflags (iOS::fixed) <<setprecision (6) << (Double) a[3]*a[4]*r/a[1]<<Endl; * if(a[3]==-1) cout<<"n ="<<setiosflags (iOS::fixed) <<setprecision (6) << (Double) a[1]*a[2]/(r*a[4]) <<Endl; $ if(a[4]==-1) Panax Notoginsengcout<<"T ="<<setiosflags (iOS::fixed) <<setprecision (6) << (Double) a[1]*a[2]/(r*a[3]) <<Endl; - } the + } A intMain () the { + - intx; $ intT; $ while(cin>>s1>>s2>>t) - { -memset (a,-1,sizeof(a)); thex =init (s1); -A[X] =T;WuyiCin>>s1>>s2>>T; thex =init (s1); -A[X] =T; WuCin>>s1>>s2>>T; -x =init (s1); AboutA[X] =T; $ f (); - } - return 0; -}
View Code
C + + reserved decimals
#include <iomanip>
cout<< "p =" <<setiosflags (ios::fixed) <<setprecision (6) << (double) a[3]*a[4]*r/a[2]<< Endl; (reserved six digits)
URAL 1823 Ideal Gas