- Analisis
- Inisialisasi variabel c(Celsius),r(Reamur),f(Fahrenheit),dan k(Kelvin)
- input: s (r,f,k,c)
- output: c,k,r,dan f
- Algoritma
- Deklarasi
read(s)
c -> r = c*4/5
c -> f = (c*9/5)+32
c -> k = c+273
r -> c = r*5/4
f -> c = (f-32)*5/9
k -> c = k-273
- Program C++
#include <iostream>
#include <conio.h>
using namespace std;
class suhu
{
public:
int proses();
private:
float s,f,r,k,c;
int nomer;
};
int suhu::proses(){
cout<<"\t\tKonversi Suhu"<<endl<<endl;
cout<<"1.Celsius\t2.Reamur\t3.Fahrenheit\t4.Kelvin"<<endl;
cout<<"Masukkan pilihan masukan suhu =\t"; cin>>nomer;
switch(nomer){
case 1:
cout<<"Masukkan suhu dalam Celsius =\t";cin>>s;
k=s+273;
f=(9*s/5)+32;
r=4*s/5;
cout<<"Jadi "<<s<<" Celsius = "<<endl;
cout<<r<<" Reamur"<<endl;
cout<<f<<" Fahenheit"<<endl;
cout<<k<<" Kelvin"<<endl;
break;
case 2:
cout<<"Masukkan suhu dalam Reamur =\t";cin>>s;
c=5*s/4;
k=c+273;
f=(9*c/5)+32;
cout<<"Jadi "<<s<<" Reamur = "<<endl;
cout<<c<<" Celsius"<<endl;
cout<<f<<" Fahenheit"<<endl;
cout<<k<<" Kelvin"<<endl;
break;
case 3:
cout<<"Masukkan suhu dalam Fahrenheit =\t";cin>>s;
c=(s-32)*5/9;
k=c+273;
r=4*c/5;
cout<<"Jadi "<<s<<" Fahrenheit = "<<endl;
cout<<r<<" Reamur"<<endl;
cout<<c<<" Celsius"<<endl;
cout<<k<<" Kelvin"<<endl;
break;
case 4:
cout<<"Masukkan suhu dalam Kelvin =\t";cin>>s;
c=s-273;
f=(9*c/5)+32;
r=4*c/5;
cout<<"Jadi "<<s<<" Kelvin = "<<endl;
cout<<r<<" Reamur"<<endl;
cout<<f<<" Fahenheit"<<endl;
cout<<c<<" Celsius"<<endl;
break;
default:
cout<<"Gak ada pilihan no itu Bro....."<<endl;
break;
}
}
int main(int argc, char** argv) {
suhu bilangan;
bilangan.proses();
return 0;
}
setelah di run akan muncul :
Jangan lupa koment ya....
diterima kritik dan saran anda...
trims...
Tidak ada komentar:
Posting Komentar