Pembahasan Latihan Soal Pertemuan ke 10
Haloo teman2 semua. kali ini kita akan membahas tentang latihan soal pertemuan ke 10. Langsung saja yaa hehe......
Berikut Soalnya...
Berikut Soalnya...
Nahh teman2, inputannya begini...
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
judul()
{
puts(" PENITIPAN HEWAN PELIHARAAN ");
puts(" MEAOW PET CARE ");
puts("=********************************=");
}
garis()
{
puts("===============================================================");
}
long ttlbay(long biaya, long jmltip)
{
return(biaya*jmltip);
}
long kembali(long uby, long ttlbay)
{
return(uby-ttlbay);
}
main()
{
int i, j;
long subtotal, u_bayar, u_kembali;
char lagi, nm_petugas[15], nm_pemilik[15];
struct
{
char jns_hewan[8], kd_hewan, jns_perawatan[8];
int kd_perawatan, jml_titip, biaya;
long tohar;
}
hwn[100];
awal:
subtotal=0;
clrscr();
judul();
cout<<endl;
cout<<"Nama Petugas : "; cin>>nm_petugas;
cout<<"Nama Pemilik : "; cin>>nm_pemilik;
cout<<"Jumlah data peliharaan : "; cin>>j;
cout<<endl;
for(i=1;i<=j;i++)
{
cout<<"Data ke - "<<i<<endl;
cout<<"Kode Jenis Hewan [K/H] : "; cin>>hwn[i].kd_hewan; cout<<endl;
cout<<"Kode perawatan [1/2] : "; cin>>hwn[i].kd_perawatan; cout<<endl;
if(hwn[i].kd_hewan=='K'||hwn[i].kd_hewan=='k')
{
strcpy(hwn[i].jns_hewan, "Kucing");
if(hwn[i].kd_perawatan==1)
{
strcpy(hwn[i].jns_perawatan, "LUX");
hwn[i].biaya=250000;
}
else if(hwn[i].kd_perawatan==2)
{
strcpy(hwn[i].jns_perawatan, "INTENSIF");
hwn[i].biaya=300000;
}
else
{
strcpy(hwn[i].jns_perawatan, "KODE SALAH");
hwn[i].biaya=0;
}
}
else if(hwn[i].kd_hewan=='H'||hwn[i].kd_hewan=='h')
{
strcpy(hwn[i].jns_hewan, "Hamster");
if(hwn[i].kd_perawatan==1)
{
strcpy(hwn[i].jns_perawatan, "LUX");
hwn[i].biaya=150000;
}
else if(hwn[i].kd_perawatan==2)
{
strcpy(hwn[i].jns_perawatan, "INTENSIF");
hwn[i].biaya=100000;
}
else
{
strcpy(hwn[i].jns_perawatan, "KODE SALAH");
hwn[i].biaya=0;
}
}
else
{
strcpy(hwn[i].jns_hewan, "KODE SALAH");
}
cout<<"Jumlah hewan : "; cin>>hwn[i].jml_titip;
cout<<endl;
hwn[i].tohar=ttlbay(hwn[i].biaya, hwn[i].jml_titip);
}
clrscr();
judul();
cout<<endl;
cout<<"Nama Petugas : "<<nm_petugas;
cout<<" Nama Pemilik : "<<nm_pemilik;
cout<<endl<<endl;
garis();
puts("NO Jenis Jenis Biaya Jumlah Total");
puts(" Hewan Perawatan Perawatan Hewan");
garis();
for(i=1;i<=j;i++)
{
cout<<setiosflags(ios::left)<<setw(4)<<i;
cout<<setiosflags(ios::left)<<setw(10)<<hwn[i].jns_hewan;
cout<<setiosflags(ios::left)<<setw(15)<<hwn[i].jns_perawatan;
cout<<setiosflags(ios::left)<<setw(11)<<hwn[i].biaya;
cout<<setiosflags(ios::left)<<setw(12)<<hwn[i].jml_titip;
cout<<setiosflags(ios::left)<<setw(4)<<hwn[i].tohar<<endl;
subtotal=subtotal+hwn[i].tohar;
}
garis();
cout<<" Total Bayar : "<<subtotal<<endl;
cout<<" Uang Bayar : "; cin>>u_bayar;
u_kembali=kembali(u_bayar, subtotal);
cout<<" Uang Kembali : "<<u_kembali;
cout<<endl<<endl;
cout<<"Input Data Lagi [Y/T]: ";cin>>lagi;
if(lagi=='y'||lagi=='Y')
goto awal;
else
goto akhir;
getch();
akhir:
}
Komentar
Posting Komentar