Temperature conversion: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: changed the output to include (any) comments from the input. -- ~~~~ |
No edit summary |
||
Line 138: | Line 138: | ||
return 0; |
return 0; |
||
}</lang> |
}</lang> |
||
=={{header|C++}}== |
|||
<lang cpp> |
|||
#include <iostream> |
|||
#include <iomanip> |
|||
//-------------------------------------------------------------------------------------------------- |
|||
using namespace std; |
|||
//-------------------------------------------------------------------------------------------------- |
|||
class converter |
|||
{ |
|||
public: |
|||
converter() : KTRank( 5.0f / 9.0f ), KTC( 273.15f ), KTF( 1.8f ), KTRe( 4.0f / 5.0f ), |
|||
KTDel( 3.0f / 2.0f ), KTNew( 33.0f / 100.0f ), KTRom( 21.0f / 40.0f ) {} |
|||
void convert( float kelvien ) |
|||
{ |
|||
float cel = kelvien - KTC, |
|||
fah = cel * KTF + 32.0f, |
|||
rnk = kelvien / KTRank, |
|||
rea = cel * KTRe, |
|||
del = ( 100.0f - cel ) * KTDel, |
|||
net = cel * KTNew, |
|||
rom = cel * KTRom + 7.5f; |
|||
cout << endl << left |
|||
<< "TEMPERATURES:" << endl |
|||
<< "===============" << endl << setw( 13 ) |
|||
<< "CELCIOS:" << cel << endl << setw( 13 ) |
|||
<< "DELISLE:" << del << endl << setw( 13 ) |
|||
<< "FAHRENHEIT:" << fah << endl << setw( 13 ) |
|||
<< "KELVIN:" << kelvien << endl << setw( 13 ) |
|||
<< "NEWTON:" << net << endl << setw( 13 ) |
|||
<< "RANKINE:" << rnk << endl << setw( 13 ) |
|||
<< "REAUMUR:" << rea << endl << setw( 13 ) |
|||
<< "ROMER:" << rom << endl << endl << endl; |
|||
} |
|||
private: |
|||
const float KTRank, KTC, KTF, KTRe, KTDel, KTNew, KTRom; |
|||
}; |
|||
//-------------------------------------------------------------------------------------------------- |
|||
int main( int argc, char* argv[] ) |
|||
{ |
|||
converter con; |
|||
float k; |
|||
while( true ) |
|||
{ |
|||
cout << "Enter the temperature in Kelvin to convert: "; |
|||
cin >> k; |
|||
con.convert( k ); |
|||
system( "pause" ); |
|||
system( "cls" ); |
|||
} |
|||
return 0; |
|||
} |
|||
//-------------------------------------------------------------------------------------------------- |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
Enter the temperature in Kelvin to convert: 373.15 |
|||
TEMPERATURES: |
|||
=============== |
|||
CELCIOS: 100 |
|||
DELISLE: 0 |
|||
FAHRENHEIT: 212 |
|||
KELVIN: 373.15 |
|||
NEWTON: 33 |
|||
RANKINE: 671.67 |
|||
REAUMUR: 80 |
|||
ROMER: 60 |
|||
</pre> |
|||
=={{header|D}}== |
=={{header|D}}== |