garapane asisten bung . .
penggunaan array dalam struct,
sueremm . .
source code :
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
//membuat struct
struct tanggal{
int hari, bln, thn;
};
struct dataPerpus{
char mahasiswa[30], nim[10], kodeBuku[3][5];
char judul[3][30], pengarang[3][30], penerbit[3][30];
};
//pemberian objek pada tiap-tiap struct
struct tanggal pjm, bck, jt;
struct dataPerpus dt;
main(){
int byk;
cout<<"\n ==================================";
cout<<"\n PROGRAM PERPUSTAKAAN";
cout<<"\n by: Rian Afriyadi";
cout<<"\n ==================================";
cout<<"\n\n Nama Mahasiswa\t: "; gets(dt.mahasiswa);
cout<<" NIM\t\t: "; cin>>dt.nim;
while(1){
cout<<"\n Banyak peminjaman buku: "; cin>>byk;
if(byk>3){
cout<<"\n --- MAXIMAL PEMINJAMAN 3 BUKU ---";
}else{
break;
}
}
//input data buku
cout<<"\n ----------------------------------";
cout<<"\n INPUT DATA PEMINJAMAN BUKU";
cout<<"\n ----------------------------------";
for(int a=1; a<=byk; a++){
cout<<"\n Data Buku ke "<<a;
cout<<"\n Kode Buku\t: "; cin>>dt.kodeBuku[a];
cout<<" Judul Buku\t: "; gets(dt.judul[a]);
cout<<" Pengarang\t: "; gets(dt.pengarang[a]);
cout<<" Penerbit\t: "; gets(dt.penerbit[a]);
cout<<" ..................................";
}
//input tanggal peminjaman
cout<<"\n Tanggal Pinjam: \n";
while(1){
cout<<" Tanggal [1 - 30]\t: "; cin>>pjm.hari;
if(pjm.hari<=0||pjm.hari>30){
cout<<" ERROR...!\n";
}else{break;}
}
while(1){
cout<<" Bulan [1 - 12]\t\t: "; cin>>pjm.bln;
if(pjm.bln<=0||pjm.bln>12){
cout<<" ERROR...!\n";
}else{break;}
}
while(1){
cout<<" Tahun [yyyy]\t\t: "; cin>>pjm.thn;
if(pjm.thn<=0){
cout<<" ERROR...!\n";
}else{break;}
}
//input tanggal pengembalian
cout<<"\n\n Tanggal Kembali: \n";
while(1){
cout<<" Tanggal [1 - 30]\t: "; cin>>bck.hari;
if(bck.hari<=0||bck.hari>30){
cout<<" ERROR...!\n";
}else{break;}
}
while(1){
cout<<" Bulan [1 - 12]\t\t: "; cin>>bck.bln;
if(bck.bln<=0||bck.bln>12){
cout<<" ERROR...!\n";
}else{break;}
}
while(1){
cout<<" Tahun [yyyy]\t\t: "; cin>>bck.thn;
if(bck.thn<=0){
cout<<" ERROR...!\n";
}else{break;}
}
//proses perhitungan denda
int lamaPinjam = (bck.hari-pjm.hari)+((bck.bln-pjm.bln)*30)+((bck.thn-pjm.thn)*360);
int terlambat = lamaPinjam - 7;
int denda=0;
if(lamaPinjam>7){
denda = terlambat *100*byk;
}
//perhitungan jatuh tempo pengembalian
jt.hari = pjm.hari+7;
jt.bln = pjm.bln+(jt.hari/31);
jt.thn = pjm.thn+(jt.bln/13);
if(jt.hari>30){
jt.hari-=30;
}
if(jt.bln>12){
jt.bln-=12;
}
cout<<"\n -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-";
cout<<"\n\n\n ----------------------------------";
cout<<"\n OUTPUT PEMINJAMAN";
cout<<"\n ----------------------------------";
cout<<"\n Nama\t: "<<dt.mahasiswa;
cout<<"\n NIM\t: "<<dt.nim;
cout<<"\n Data Buku Yang dipinjam:";
cout<<"\n = = = = = = = = = = = = = = = = = =";
for(int a=1; a<=byk; a++){
cout<<"\n Data Buku ke "<<a;
cout<<"\n Kode Buku\t: "<<dt.kodeBuku[a];
cout<<"\n Judul Buku\t: "<<dt.judul[a];
cout<<"\n Pengarang\t: "<<dt.pengarang[a];
cout<<"\n Penerbit\t: "<<dt.penerbit[a];
cout<<"\n ..................................";
}
cout<<"\n\n Tanggal Pinjam : "<<pjm.hari<<" - "<<pjm.bln<<" - "<<pjm.thn;
cout<<"\n Tanggal Kembali : "<<bck.hari<<" - "<<bck.bln<<" - "<<bck.thn;
cout<<"\n Tanggal Jatuh tempo: "<<jt.hari<<" - "<<jt.bln<<" - "<<jt.thn;
cout<<"\n Lama Peminjaman : "<<lamaPinjam<<" hari";
cout<<"\n Lama Keterlambatan : "<<terlambat<<" hari";
cout<<"\n Denda : Rp."<<denda;
cout<<"\n ==================================";
getch();
}
0 komentar:
Posting Komentar