题意:给出了3个H,D,T分别为湿度,露点,温度三个量,给出了3个量之间的公式,给出其中的两个量的值,然后按照公式将另外一个量的值给求出来,并按照标准格式输入输出
思路:耐心的将各个公式转化好,纯属是一道考验耐心和细心程度的题目。分为6种情况,用switch分开
心得体会:1.由于要输出一位的小数,所以学到了c++中用来控制输出几位小数的函数setprecision
2.switch的优点在这一题中有较好的体现,理解加深
源代码(256K,0MS)
C++语言:
#include<iostream>
#include<math.h>
#include<iomanip>
using
namespace
std;
int
main()
{
char
t
,
d
,
h;
//T代表的是temperature,H代表的是humidex,D代表的是dewpoint
double
a
, b;
double
e
,
h1;
double
temperature
,
humidex
,
dewpoint;
while (
cin
>>
t
&&
t
!=
'E')
{
cin
>>
a
>>
h
>>b;
switch(
t)
{
case
'T'
:
switch(
h)
{
case
'D'
:
e
=
6.11
*
exp (
5417.7530
* ( (
1
/
273.16)
- (
1
/ (b
+
273.16) ) ) );
h1
= (
0.5555)
* (
e
-
10.0);
humidex
=
a
+
h1;
cout
<<
fixed
<<
setprecision(
1)
<<
"T "
<<
a
<<
" D "
<<b
<<
" H "
<<
humidex
<<
endl;
break;
case
'H'
:
h1
=b
-
a;
e
=
h1
/
0.5555
+
10.0;
dewpoint
=
1
/ (
1
/
273.16
-
log(
e
/
6.11)
/
5417.7530 )
-
273.16;
cout
<<
fixed
<<
setprecision(
1)
<<
"T "
<<
a
<<
" D "
<<
dewpoint
<<
" H "
<<b
<<
endl;
break;
}
break;
case
'D'
:
switch(
h)
{
case
'T'
:
e
=
6.11
*
exp (
5417.7530
* ( (
1
/
273.16)
- (
1
/ (
a
+
273.16) ) ) );
h1
= (
0.5555)
* (
e
-
10.0);
humidex
=b
+
h1;
cout
<<
fixed
<<
setprecision(
1)
<<
"T "
<<b
<<
" D "
<<
a
<<
" H "
<<
humidex
<<
endl;
break;
case
'H'
:
e
=
6.11
*
exp (
5417.7530
* ( (
1
/
273.16)
- (
1
/ (
a
+
273.16) ) ) );
h1
= (
0.5555)
* (
e
-
10.0);
temperature
=b
-
h1;
cout
<<
fixed
<<
setprecision(
1)
<<
"T "
<<
temperature
<<
" D "
<<
a
<<
" H "
<<b
<<
endl;
break;
}
break;
case
'H'
:
switch(
h)
{
case
'T'
:
h1
=
a
-b;
e
=
h1
/
0.5555
+
10.0;
dewpoint
=
1
/ (
1
/
273.16
-
log(
e
/
6.11)
/
5417.7530 )
-
273.16;
cout
<<
fixed
<<
setprecision(
1)
<<
"T "
<<b
<<
" D "
<<
dewpoint
<<
" H "
<<
a
<<
endl;
break;
case
'D'
:
e
=
6.11
*
exp (
5417.7530
* ( (
1
/
273.16)
- (
1
/ (b
+
273.16) ) ) );
h1
= (
0.5555)
* (
e
-
10.0);
temperature
=
a
-
h1;
cout
<<
fixed
<<
setprecision(
1)
<<
"T "
<<
temperature
<<
" D "
<<b
<<
" H "
<<
a
<<
endl;
break;
}
break;
}
}
return
0;
}