Skip to content

Instantly share code, notes, and snippets.

@oktavianto
Last active October 16, 2022 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oktavianto/3fd8fb718cdb2b3f1dbf3f027252299b to your computer and use it in GitHub Desktop.
Save oktavianto/3fd8fb718cdb2b3f1dbf3f027252299b to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
struct Kategori_buku{
string kategori[6] = {"Fiksi", "Kuliner", "Biologi", "Filsafat", "Komputer", "Managemen"};
};
struct Penerbit{
string penerbit[5] = {"Erlangga", "Tiga Sekawan", "Erlangga", "Gramedia", "Tiga Dunia"};
};
struct Buku{
int id_buku;
string judul_buku;
int Jumlah_buku;
string pengarang_buku;
string No_ISBN;
int kategori_buku;
Kategori_buku kategori;
int penerbit_buku;
Penerbit penerbit;
};
int main(){
Buku buku[5];
int pilih;
int i = 0;
do{
cout << "==============================" << endl;
cout << "Program Input Data Buku" << endl;
cout << "==============================" << endl;
cout << "1. Input data buku" << endl;
cout << "2. Cetak data buku" << endl;
cout << "3. Keluar program" << endl;
cout << "Pilih : ";
cin >> pilih;
switch(pilih){
case 1:
cout << "Input data buku" << endl;
cout << "ID Buku : ";
cin >> buku[i].id_buku;
cout << "Judul Buku : ";
cin >> buku[i].judul_buku;
cout << "Jumlah Buku : ";
cin >> buku[i].Jumlah_buku;
cout << "Pengarang Buku : ";
cin >> buku[i].pengarang_buku;
cout << "No ISBN : ";
cin >> buku[i].No_ISBN;
cout << "Kategori Buku : " << endl;
for(int j = 0; j < 6; j++){
cout << j << ". " << buku[i].kategori.kategori[j] << endl;
}
cout << "Pilih : ";
cin >> buku[i].kategori_buku;
cout << "Penerbit Buku : " << endl;
for(int j = 0; j < 5; j++){
cout << j << ". " << buku[i].penerbit.penerbit[j] << endl;
}
cout << "Pilih : ";
cin >> buku[i].penerbit_buku;
i++;
break;
case 2:
cout << "Cetak data buku" << endl;
cout << "ID Buku" << "\t" << "Judul Buku" << "\t" << "Jumlah Buku" << "\t" << "Pengarang Buku" << "\t" << "No ISBN" << "\t" << "Kategori Buku" << "\t" << "Penerbit Buku" << endl;
for(int j = 0; j < i; j++){
cout << buku[j].id_buku << "\t" << buku[j].judul_buku << "\t" << buku[j].Jumlah_buku << "\t" << buku[j].pengarang_buku << "\t" << buku[j].No_ISBN << "\t" << buku[j].kategori.kategori[buku[j].kategori_buku] << "\t" << buku[j].penerbit.penerbit[buku[j].penerbit_buku] << endl;
}
break;
case 3:
cout << "Keluar program" << endl;
break;
default:
cout << "Pilihan tidak ada" << endl;
break;
}
}while(pilih != 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment