Program ini adalah program untuk konversisuhu (c_f ,c_k)celcius-fahrenheit-kelvin, (f_c, f_k)fahrenheit-cekcius-kelvin,(k_c, k_f) kelvin-celcius-fahrenheit, denganmemilihsuhuawaldaricelcius, fahrenheitatau kelvin.
Algoritma :
Ø Pilihkonverter :
1. Celcius
2. Fahrenheit
3. Kelvin
Ø Hitung :
//daricelciuskefahrenheit
float converter::c_fahrenheit(){
suhuakhir = (suhuawal*1.8+32);
returnsuhuakhir;
}
//daricelciuske kelvin
float converter::c_kelvin(){
suhuakhir = (suhuawal+273.15);
returnsuhuakhir;
}
//darifahrenheitke kelvin
float converter::f_kelvin(){
suhuakhir = (suhuawal-32)/(1.8+273.5);
returnsuhuakhir;
}
//darifahrenheitkecelcius
float converter::f_celcius(){
suhuakhir = (suhuawal-32)/1.8;
returnsuhuakhir;
}
//dari kelvinkecelcius
float converter::k_celcius(){
suhuakhir = (suhuawal-273.15);
returnsuhuakhir;
}
//dari kelvinkefahrenheit
float converter::k_fahrenheit(){
suhuakhir = (suhuawal-273.15)*1.8+32;
returnsuhuakhir;
}
Ø Hasil :
Ø //Celcius
Ø cout<<"suhuawalcelcius : "; cin>>suhuawal;
cout<< "\n = " <<c_fahrenheit()<< " Fahrenheit";
cout<< "\n = " <<c_kelvin()<< " Kelvin"<<endl;
Ø //Fahrenheit
Ø cout<<"suhuawal Fahrenheit : "; cin>>suhuawal;
cout<< "\n = " <<f_celcius()<< " Celcius";
cout<< "\n = " <<f_kelvin()<< " Kelvin"<<endl;
Ø //Kelvin
cout<<"suhuawal Kelvin : "; cin>>suhuawal;
cout<< "\n = " <<k_fahrenheit()<< " Fahrenheit";
cout<< "\n = " <<k_celcius()<< " Celcius"<<endl;
PROGRAM C++
#include<iostream.h>
#include<stdlib>
using namespace std;
class converter{
public:
converter();
float input();
floatc_fahrenheit();
floatc_kelvin();
floatf_celcius();
floatf_kelvin();
floatk_celcius();
floatk_fahrenheit();
private:
floatsuhuawal;
floatsuhuakhir;
};
converter::converter(){
int a;
cout<<"I*****************************I"<<endl;
cout<<"I Converter TermometerSuhu I"<<endl;
cout<<"I*****************************I"<<endl;
cout<<"1 Celcius"<<endl;
cout<<"2 Fahrenheit"<<endl;
cout<<"3 Kelvin"<<endl;
cout<<"4 Exit"<<endl;
MyLabel:
cout<<"Masukkanpilihansuhu : "; cin>>a;
switch(a){
case 1 :
cout<<"suhuawalcelcius : ";
cin>>suhuawal;
cout<< "\n = " <<c_fahrenheit()<< " Fahrenheit";
cout<< "\n = " <<c_kelvin()<< " Kelvin"<<endl;
gotoMyLabel;
break;
case 2 :
cout<<"suhuawal Fahrenheit : ";
cin>>suhuawal;
cout<< "\n = " <<f_celcius()<< " Celcius";
cout<< "\n = " <<f_kelvin()<< " Kelvin"<<endl;
gotoMyLabel;
break;
case 3 :
cout<<"suhuawal Kelvin : ";
cin>>suhuawal;
cout<< "\n = " <<k_fahrenheit()<< " Fahrenheit";
cout<< "\n = " <<k_celcius()<< " Celcius"<<endl;
gotoMyLabel;
break;
case 4 : exit(0);break;
default :cout<<"Maafhanyadapatmemasukkan 1-3"<<endl;
gotoMyLabel;
break;
}
}
float converter::c_fahrenheit(){
suhuakhir = (suhuawal*1.8+32);
returnsuhuakhir;
}
float converter::c_kelvin(){
suhuakhir = (suhuawal+273.15);
returnsuhuakhir;
}
float converter::f_kelvin(){
suhuakhir = (suhuawal-32)/(1.8+273.5);
returnsuhuakhir;
}
float converter::f_celcius(){
suhuakhir = (suhuawal-32)/1.8;
returnsuhuakhir;
}
float converter::k_celcius(){
suhuakhir = (suhuawal-273.15);
returnsuhuakhir;
}
float converter::k_fahrenheit(){
suhuakhir = (suhuawal-273.15)*1.8+32;
returnsuhuakhir;
}
int main(){
converter x;
return 0;
}