Program Hitung konversi Suhu
/**Latihan Bab9 no3**/
/* Created by: Ipah Hanifah */#include<iostream.h>#include<conio.h>
#include<stdio.h>
int hitung(int f);
double hitung(double f);
float hitung(float f);
main()
{
int c;
double d;
float f;
clrscr();
cout<<"Konversi Fahrenheit ke Celcius \n\n";
cout<<"Masukkan Nilai Fahrenheit : "; cin>>f;
cout<<"\nPemanggilan tipe data double "<<endl;
cout<<f;
cout<< " = " <<hitung(f)<<" C"<<endl;
cout<<"Pemanggilan tipe data float "<<endl;
cout<<f;
cout<< " = " <<hitung(f)<<" C"<<endl;
cout<<"Pemanggilan tipe data integer "<<endl;
cout<<f;
cout<< " = " <<hitung(c)<<" C"<<endl;
getch();
}
int hitung(int f)
{
return((f - 32)*5 / 9);
}
float hitung(float f)
{
return((f - 32)*5 / 9 );
}
double hitung(double f)
{
return((f - 32)*5 / 9 );
}
Output:
- Program Hitung Sewa Buku Perpustakaan
/**Latihan Bab9 no3**/
/* Created by: Ipah Hanifah */#include<iostream.h>
#include<conio.h>
#include<stdio.h>
garis()
{
cout<<"--------------------------------\n";
}
int tarif(char kd)
{
if((kd=='C')||(kd=='c'))
{
return (500);
}
else if((kd=='K')||(kd=='k'))
{
return (700);
}
else
{
return (1000);
}
}
char *jenis(char kd)
{
if((kd=='C')||(kd=='c'))
{
return ("Cerpen");
}
else if((kd=='K')||(kd=='k'))
{
return ("Komik");
}
else
{
return ("Novel");
}
}
int bayar(int bp, int hrg)
{
return(bp*hrg);
}
main()
{
char nm[15],kd,*jb;
int bp;
int hrg;
clrscr();
cout<<" Perpustakaan Kecil - kecilan "<<endl;
garis();
cout<<" Nama Penyewa Buku : "; gets(nm);
cout<<" Kode Buku [C/K/N] : "; cin>>kd;
cout<<" Banyak Pinjam : "; cin>>bp;
garis();
cout<<" \n Tarif Sewa : Rp. "<<tarif(kd)<<endl;
cout<<" Jenis Buku : "<<jenis(kd)<<endl<<endl;
cout<<" Penyewa dengan nama "<<nm<<endl;
hrg=tarif(kd);
cout<<" Jumlah yang harus dibayar sebesar Rp. "<<bayar(hrg,bp)<<endl;
getch();
}
Output:
No comments:
Post a Comment