Selasa, 20 April 2010

Konversi Suhu C++

Pada smester 2 ini, pada mata kuliah Algoritma Pemrograman saya mendapatkan suatu tugas membuat program sederhana menggunakan bahasa C.. Dosen ini menyuruh membuat program terstruktur yang nantinya akan dikirimkan ke alamat emailnya.
Berikut Saya share contoh program sederhana yang berhasil saya buat, mudah-mudahan dapat membantu teman-teman dalam memahami pemrograman menggunakan bahasa C.
/*Program Aplikasi Konverter Suhu..
Universitas Gunadarma*/

#include
#include


//Pendeklarasian Fungsi2
void Celwal(void);
void Kelwal(void);
void Fahwal(void);
void Ranwal(void);
void Delwal(void);
void Newwal(void);
void Reawal(void);
void Romwal(void);
void Menu(void);


//Pendeklarasian nilai variabel secara Global
float c,k,f,ra,d,n,re,ro;
int A;
char Ulang;

//Awal Program(Fungsi Utama)
void main()
{
do
{
clrscr();
Menu();
cin>>A;
cout<<'\n'<<'\n';
switch(A)
{
case 1 : Celwal();
break;
case 2 : Kelwal();
break;
case 3 : Fahwal();
break;
case 4 : Ranwal();
break;
case 5 : Delwal();
break;
case 6 : Newwal();
break;
case 7 : Reawal();
break;
case 8 : Romwal();
break;
default:
{cout<<"Kode Yang Anda Masukkan Salah\n" ;
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;}
}}
while (Ulang=='Y'|| Ulang=='y');
getch();
}//akhir program(fungsi) utama


//isi dari fungsi2 yang telah diklarasikan
void Menu(void)
{
clrscr();
cout<<"###############################################\n";
cout<<"# Selamat Datang Di Program Konversi Suhu #\n";
cout<<"###############################################\n";
cout<<'\n';
cout<<"Pilih Suhu Yang Akan Anda Input :"<<"\n";
cout<<"1. Celcius" <<"\n";
cout<<"2. Kelvin" <<"\n";
cout<<"3. Fahrenheit" <<"\n";
cout<<"4. Rankine" <<'\n';
cout<<"5. Delisle" <<'\n';
cout<<"6. Newton" <<'\n';
cout<<"7. Réaumur " <<'\n';
cout<<"8. Rømer" <<'\n';
cout<<"Input Kode Suhu Yang Akan Anda Pilih [ 1-8 ] = ";
}

void Celwal(void)
{
clrscr();
cout<<"Anda Memilih Suhu Awal Celcius\n ";
cout<<'\n';
cout<<"Masukkan Suhu Awal : ";
cin>>c;
cout<<'\n';
k = c+273.15;
f = (c*1.8)+32;
ra = c*1.8+491.67;
d = (100-c)*1,5;
n = c*33/100;
re = c*0,8;
ro = c*21/40+7,5;
cout<<"Kelvin :"<<<'\n';
cout<<"Fahrenheit :"<<<'\n';
cout<<"Rankine :"<<<'\n';
cout<<"Delisle :"<<<'\n';
cout<<"Newton :"<<<'\n';
cout<<"Réaumur :"<<<'\n';
cout<<"Rømer :"<<<'\n';
cout<<'\n';
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;
}

void Kelwal(void)
{
clrscr();
cout<<"Anda Memilih Suhu Awal Kelvin\n ";
cout<<'\n';
cout<<"Masukkan Suhu Awal : ";
cin>>k;
cout<<'\n';
c = k-273.15;
f = (k*1.8)-459.67;
ra = k*1.8;
d = (373.15-k)*1.5;
n = (k-273.15)*33/100;
re = (k-273.15)*0.8;
ro = (k-273.15)*21/40+7.5;
cout<<"Celcius :"<<<'\n';
cout<<"Fahrenheit :"<<<'\n';
cout<<"Rankine :"<<<'\n';
cout<<"Delisle :"<<<'\n';
cout<<"Newton :"<<<'\n';
cout<<"Réaumur :"<<<'\n';
cout<<"Rømer :"<<<'\n';
cout<<'\n';
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;
}

void Fahwal(void)
{
clrscr();
cout<<"Anda Memilih Suhu Awal Fahrenheit\n ";
cout<<'\n';
cout<<"Masukkan Suhu Awal : ";
cin>>f;
cout<<'\n';
k = (f + 459.67) / 1.8;
c = (f - 32) / 1.8;
ra = f + 459,67;
d = (212 - f) * 5/6;
n = (f - 32) * 11/60;
re = (f - 32) / 2,25;
ro = (f - 32) * 7/24 + 7,5;
cout<<"Celcius :"<<<'\n';
cout<<"Kelvin :"<<<'\n';
cout<<"Rankine :"<<<'\n';
cout<<"Delisle :"<<<'\n';
cout<<"Newton :"<<<'\n';
cout<<"Réaumur :"<<<'\n';
cout<<"Rømer :"<<<'\n';
cout<<'\n';
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;
}

void Ranwal(void)
{
clrscr();
cout<<"Anda Memilih Suhu Awal Rankine\n ";
cout<<'\n';
cout<<"Masukkan Suhu Awal : ";
cin>>ra;
cout<<'\n';
k = ra / 1.8;
c = ra / 1.8 + 273.15;
f = ra - 459.67;
d = (671.67 -ra ) * 5/6;
n = (ra - 491.67) * 11/60;
re = (ra / 1,8 + 273.15) * 0.8;
ro = (ra - 491.67) * 7/24 + 7.5;
cout<<"Celcius :"<<<'\n';
cout<<"Kelvin :"<<<'\n';
cout<<"Fahrenheit :"<<<'\n';
cout<<"Delisle :"<<<'\n';
cout<<"Newton :"<<<'\n';
cout<<"Réaumur :"<<<'\n';
cout<<"Rømer :"<<<'\n';
cout<<'\n';
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;
}

void Delwal(void)
{
clrscr();
cout<<"Anda Memilih Suhu Awal Delisle\n ";
cout<<'\n';
cout<<"Masukkan Suhu Awal : ";
cin>>d;
cout<<'\n';
k = 373.15 - d * 2/3;
c = 100 - d * 2/3;
f = 212 - d * 1.2;
ra = 671.67 - d * 1.2;
n = 33 - d * 0.22;
re = 80 - d * 8/15;
ro = 60 - d * 0.35;
cout<<"Celcius :"<<<'\n';
cout<<"Kelvin :"<<<'\n';
cout<<"Fahrenheit :"<<<'\n';
cout<<"Rankine :"<<<'\n';
cout<<"Newton :"<<<'\n';
cout<<"Réaumur :"<<<'\n';
cout<<"Rømer :"<<<'\n';
cout<<'\n';
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;
}

void Newwal(void)
{
clrscr();
cout<<"Anda Memilih Suhu Awal Newton\n ";
cout<<'\n';
cout<<"Masukkan Suhu Awal : ";
cin>>n;
cout<<'\n';
k = n * 100/33 + 273.15;
c = n * 100/33;
f = n * 60/11 + 32;
ra = n * 60/11 + 491.67;
d = (33 - n) * 50/11;
re = n * 80/33;
ro = n * 35/22 + 7.5;
cout<<"Celcius :"<<<'\n';
cout<<"Kelvin :"<<<'\n';
cout<<"Fahrenheit :"<<<'\n';
cout<<"Rankine :"<<<'\n';
cout<<"Delisle :"<<<'\n';
cout<<"Réaumur :"<<<'\n';
cout<<"Rømer :"<<<'\n';
cout<<'\n';
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;
}

void Reawal(void)
{
clrscr();
cout<<"Anda Memilih Suhu Awal Réaumur\n ";
cout<<'\n';
cout<<"Masukkan Suhu Awal : ";
cin>>re;
cout<<'\n';
k = re / 0.8 + 273.15;
c = re / 0.8;
f = re * 2.25 + 32;
ra = re * 2.25 + 491.67;
d = (80 - re) * 1.875;
n = re * 33/80;
ro = re * 21/32 + 7.5;
cout<<"Celcius :"<<<'\n';
cout<<"Kelvin :"<<<'\n';
cout<<"Fahrenheit :"<<<'\n';
cout<<"Rankine :"<<<'\n';
cout<<"Delisle :"<<<'\n';
cout<<"Newton :"<<<'\n';
cout<<"Rømer :"<<<'\n';
cout<<'\n';
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;
}

void Romwal(void)
{
clrscr();
cout<<"Anda Memilih Suhu Awal Rømer\n ";
cout<<'\n';
cout<<"Masukkan Suhu Awal : ";
cin>>ro;
cout<<'\n';
k = (ro - 7,5) * 40/21 + 273.15;
c = (ro - 7,5) * 40/21;
f = (ro - 7,5) * 24/7 + 32;
ra = (ro - 7,5) * 24/7 + 491.67;
d = (60 - ro) * 20/7;
n = (ro - 7,5) * 22/35;
re = (ro - 7,5) * 32/21;
cout<<"Celcius :"<<<'\n';
cout<<"Kelvin :"<<<'\n';
cout<<"Fahrenheit :"<<<'\n';
cout<<"Rankine :"<<<'\n';
cout<<"Delisle :"<<<'\n';
cout<<"Newton :"<<<'\n';
cout<<"Réaumur :"<<<'\n';
cout<<'\n';
cout<<"Apakah Anda Ingin Kembali? [Y/T] : ";
cin>>Ulang;
}


Tidak ada komentar:

Posting Komentar