Sequence Diagram Peminjaman Buku
Sequence Diagram Pengembalian Buku
Class Diagram
Code Implementasi
by : Andreas Galang A (5114100153)#include<iostream> #include<stdlib.h> using namespace std; int n,n1; int i; int inc=0; int inc1=0; class book { public: int bookcode; char bookname[20]; char authorname[20]; int bookprice; int status; public: void addbook() { status=1; cout<<"\t\t\t TAMBAH BUKU"<<endl<<endl; inc++; bookcode=100+inc; cout<<"\n\tKode Buku :"<<bookcode<<endl; cout<<"\n\tNama Buku :"; cin>>bookname; cout<<"\n\tPenulis :"; cin>>authorname; cout<<"\n\tHarga :"; cin>>bookprice; } void display_book() { cout<<bookcode<<"\t\t"<<bookname<<"\t\t"<<authorname<<"\t\t"<<"\t\t"<<bookprice<<endl; } void book_status() { if(status==1) { cout<<"\t\tID Buku:"<<bookcode<<"\t\tStatus:Available"<<endl; } else { cout<<"\t\tID Buku:"<<bookcode<<"\t\tStatus:Issued"<<endl; } } }; book b[10]; class member { public: int borrower_id; char studname[20]; int bookcount; public: void addstud() { cout<<"\t\tTambah Peminjam"<<endl; cout<<endl; inc1++; borrower_id=100+inc1; cout<<"\t\tID Peminjam :"<<borrower_id<<endl; cout<<"\t\tNama :"; cin>>studname; cout<<endl; bookcount=2; cout<<"\t\tMaximum Buku:"<<bookcount<<endl<<endl; } void dispstud() { cout<<"\t"<<borrower_id<<"\t\t"<<studname<<endl; } };member s[10]; class transaksi { public: int day,month,year; int day2,month2,year2; int iday,imon,iyear; int rday,rmon,ryear; int eday,emon,eyear; int yr1,yr2,m1,m2,d1,d2,mons1,mons2,mons,days,yrs,sum,j; int loop; int fine; public: void isdatecalc() { cout<<"\t\thari:"; cin>>day; cout<<"\t\tbulan:"; cin>>month; cout<<"\t\ttahun:"; cin>>year; day2=day; month2=month; year2=year; day2=day2+20; if(((month2==1)||(month2==3)||(month2==5)||(month2==7)||(month2==8)||(month2==10)||(month2==12))&&((day2>31))) { day2=day2-31; month2=month2+1; if(month2==13) { year2++; month2=1; } } else if(((month2==4)||(month2==6)||(month2==9)||(month2==11))&&((day2>30))) { day2-=30; month2++; } else if(((year2%4==0)||(year2%400==0))&&(day2>29)&&(month==2)) { day2-=29; month2++; } else if(((year2%4!=0)||(year2%100!=0)||(year2%400!=0))&&(day2>28)&&(month2==2)) { day2-=28; month2++; } cout<<endl; } void isdate() { iday=day; imon=month; iyear=year; cout<<"\t\tTanggal pinjam:"<<iday<<"/"<<imon<<"/"<<iyear; cout<<endl; } void retdate() { rday=day2; rmon=month2; ryear=year2; cout<<"\t\tTanggal kembali:"<<rday<<"/"<<rmon<<"/"<<ryear<<endl; cout<<endl; } void edatecalc() { eday=rday; emon=rmon; eyear=ryear; eday=eday+20; if(((emon==1)||(emon==3)||(emon==5)||(emon==7)||(emon==8)||(emon==10)||(emon==12))&&((eday>31))) { eday=eday-31; emon=emon+1; if(emon==13) { eyear++; emon=1; } } else if(((emon==4)||(emon==6)||(emon==9)||(emon==11))&&((eday>30))) { eday-=30; emon++; } else if(((eyear%4==0)||(eyear%100==0)||(eyear%400==0))&&(eday>29)&&(emon==2)) { eday-=29; emon++; } else if(((eyear%4!=0)||(eyear%100!=0)||(eyear%400!=0))&&(eday>28)&&(emon==2)) { eday-=28; emon++; } cout<<endl; cout<<endl; cout<<"\t\tperpanjang tanggal kembali:"<<eday<<"/"<<emon<<"/"<<eyear<<endl; } void finecalc(){ int mon[]={31,28,31,30,31,30,31,31,30,31,30,31}; loop=365; sum=0; d1=rday; m1=rmon; yr1=ryear; cout<<endl; cout<<"\t\ttanggal kembali: "<<d1<<"/"<<m1<<"/"<<yr1<<endl; cout<<endl; cout<<"\t\tmasukkan tanggak kembali.."<<endl; cout<<endl; cout<<"\t\thari:"; cin>>d2; cout<<endl; cout<<"\t\tbulan:"; cin>>m2; cout<<endl; cout<<"\t\ttahun:"; cin>>yr2; cout<<endl; days=d2-d1; yrs=yr2-yr1; if(m2>=m1) { mons=m1-m2; mons2=abs(mons); } else { mons=m2-m1; mons2=abs(mons); } sum=yrs*loop+mons+days+mons2; if(m2>m1) { j=m1; } else { j=m2; } if(mons2!=0) { for(i=0;i<mons2;i++) { sum=sum+mon[j]; j++; } } cout<<endl; cout<<"\t\ttanggal kembali:"<<d2<<"/"<<m2<<"/"<<yr2<<endl; cout<<endl; fine=(sum+mons)*1; if((yr1%4==0)||(yr1%400==0)&&(m1==2)) { fine=fine+1; } cout<<"\t\t\tJumlah denda"<<fine<<endl; } }; transaksi is; int main() { int option,i; char ch2,ch3,ch4; int sbookcode,sstudid; int flag,flag1,pos,spos,ipos; int sflag,stpos; int book_id,borrower_id; int rbookcode,rstudid; int rflag1,rflag2; int rpos1,rpos2,l; do { cout<<"\t\t\tLIBRARY MANAGEMENT SYSTEM"<<endl<<endl; cout<<"\t\t\t\tMAINMENU"<<endl<<endl; cout<<"\t\t ##############################################"<<endl<<endl; cout<<"\t\t \t1. TAMBAH BUKU "<<endl; cout<<"\t\t \t2. LIHAT SEMUA BUKU "<<endl; cout<<"\t\t \t3. TAMBAH DATA PEMINJAM "<<endl; cout<<"\t\t \t4. LIHAT DATA PEMINJAM "<<endl; cout<<"\t\t \t5. PINJAM BUKU "<<endl; cout<<"\t\t \t6. KEMBALIKAN BUKU "<<endl; cout<<"\t\t \t0. EXIT "<<endl<<endl; cout<<"\t\t ##############################################"<<endl; cout<<endl; cout<<"\t\t\t\tPilih opsi:"; cin>>option; switch(option) { case 1: cout<<"\t\tTambah Buku"<<endl<<endl; cout<<"\t\tMasukkan jumlah buku :"; cin>>n; for(i=1;i<=n;i++) { cout<<"Kode buku:"<<100+i; b[i].addbook(); } cout<<endl; cout<<endl; cout<<"\t\t<<-----Kembali ke Main Menu-----"<<endl; main(); break; case 2: cout<<"\t\t\tDAFTAR BUKU"<<endl<<endl; cout<<"KODE BUKU\tJUDUL\tPENULIS \tHARGA"<<endl<<endl; for(i=1;i<=n;i++) { b[i].display_book(); } cout<<endl; for(i=1;i<=n;i++) { b[i].book_status(); } cout<<endl; cout<<"\t\t<<-----Kembali ke Main Menu-----"<<endl; main(); break; case 3: cout<<"\t\tTAMBAH PEMINJAM"<<endl<<endl; cout<<"\t\tJumlah : "; cin>>n1; for(i=1;i<=n1;i++) { s[i].addstud(); } cout<<endl; cout<<"\t\t<<-----Kembali ke Main Menu-----"<<endl; main(); break; case 4: cout<<"\t\tLIST OF ALL ADDED STUDENTS"<<endl; cout<<"\t\t^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl; cout<<endl; cout<<"\t******************************************"<<endl; cout<<"\tSTUDENT ID\tSTUDENT NAME\tDEPT NAME"<<endl; cout<<"\t******************************************"<<endl; for(i=1;i<=n1;i++) { s[i].dispstud(); } cout<<endl; cout<<"\t<<-----Back To Main Menu-----"<<endl; main(); break; break; case 5: cout<<"\t\t PEMINJAMAN BUKU"<<endl<<endl; cout<<"\t\tID Peminjam:"; cin>>borrower_id; for(i=1;i<=n1;i++) { if(borrower_id==s[i].borrower_id) { flag=1; spos=i; } } if(flag==1) { cout<<"\t\tKode Buku:"; cin>>book_id; for(i=1;i<=n;i++) { if(book_id==b[i].bookcode) { flag1=1; ipos=i; } } } cout<<endl; if(flag==1) { if(flag1==1) { if(s[spos].bookcount!=0) { if(b[ipos].status==1) { s[spos].bookcount--; b[ipos].status=0; cout<<"\t\tTanggal Peminjaman"<<endl<<endl; is.isdatecalc(); is.isdate(); is.retdate(); cout<<"\t\tBuku berhasil dipinjam"<<endl; cout<<endl; cout<<"\t\tBooks allowed now:"<<s[spos].bookcount<<endl; cout<<endl; cout<<"\t ID Peminjam\t Nama\t Kode Buku"<<endl; cout<<"\t ----------\t ------------\t --------"<<endl; cout<<"\t "<<s[spos].borrower_id<<"\t\t "<<s[spos].studname<<"\t\t "<<b[ipos].bookcode<<endl; } else { cout<<"\t\tMohon maaf, buku sudah dipinjam"<<endl; } } else { cout<<"\t\tMohon maaf, tidak dapat meminjam lebih dari dua buku"<<endl; } } else { cout<<"\t\tMohon maaf, buku tidak ditemukan dengan ID : "<<book_id<<endl; } } else { cout<<"\t\tMohon maaf, ID peminjam tidak ditemukan:"<<borrower_id<<endl; } cout<<endl; cout<<"\t\t<<-----Kembali ke Main Menu-----"<<endl; main(); break; case 6: cout<<"\t\tPengembalian Buku"<<endl<<endl; cout<<"\t\tID Peminjam"; cin>>rstudid; cout<<endl; for(i=1;i<=n1;i++) { if(rstudid==s[i].borrower_id) { rflag1=1; rpos1=i; } } if(rflag1==1) { cout<<"\t\tID Buku :"; cin>>rbookcode; cout<<endl; for(i=1;i<=n;i++) { if(rbookcode==b[i].bookcode) { rflag2=1; rpos2=i; } } } if(rflag1==1) { if(rflag2==1) { cout<<"\tID Buku:"<<b[rpos2].bookcode<<" ID Peminjam:"<<s[rpos1].borrower_id<<" ?y/n:"; cin>>ch4; if(ch4=='y') { if(b[rpos2].status==0) { cout<<endl; cout<<"\t\tBuku yang dapat dikembalikan..."<<endl; cout<<endl; is.retdate(); cout<<"\t\tApakah kamu yakin mengembalikan buku ini ?y/n:"; cin>>ch2; cout<<endl; if(ch2=='y') { cout<<"\t\t Buku belum lewat batas waktu ?y/n:"; cin>>ch3; cout<<endl; if(ch3=='y') { // is.retdate(); //cout<<endl; // cout<<"\t\tBook returned before due date"<<endl; // cout<<endl; cout<<"\t\t\tFine - NIL"<<endl; cout<<endl; cout<<"\t\t\t THANK YOU"<<endl; b[rpos2].status=1; s[rpos1].bookcount++; cout<<endl; cout<<"\t\t<<-----Kembali ke Main Menu-----"<<endl; main(); } else { cout<<endl; cout<<"\t\tAnda harus membayar tagihan !!!"<<endl; is.finecalc(); cout<<endl; b[rpos2].status=1; s[rpos1].bookcount++; cout<<"\t\t<<-----Kembali ke Main Menu-----"<<endl; main(); } } else { is.retdate(); cout<<endl; cout<<"\t\tYou can extend the book for another twenty days.."<<endl; is.edatecalc(); } } else { cout<<endl; cout<<"\t\tThis Book is not yet issued from library.. "<<endl; } } else { cout<<endl; cout<<"\t\t This book is not issued to you..Sorry!!!"<<endl; } } else { cout<<endl; cout<<"\t\tSorry!..No Book Exists With Code:"<<rbookcode<<endl; } } else { cout<<endl; cout<<"\t\tMohon maaf, ID peminjam tidak ditemukan:"<<rstudid<<endl; } cout<<endl; cout<<"\t\t<<-----Kembali ke Main Menu-----"<<endl; main(); break; case 0:exit(0); default: cout<<"\t\tPilihan salah.."<<endl; cout<<"\t\tMasukkan ulang pilihan...."<<endl; cout<<endl; cout<<"\t\t\t<<---Kembali---"<<endl; main(); break; } }while(option==0); }
0 komentar:
Posting Komentar