Anda di halaman 1dari 7

#include <iostream.

h>
#include <stdio.h>
#include <string.h>
#include <fstream.h>
#include <stdlib.h>
#include <ctype.h> #
#include <conio.h>

class perpus
{
private:
char judul[10][30];
char peng[10][30];
int hal[10];
int tahun[10];

public:
int no;
char bjudul[10][30];
char bpeng[10][30];
int bhal[10];
int btahun[10];
int index[10];
void input();
void sojud();
void sopeng();
void sotah();
void sejud();
};

class perpus data;

void main()
{
b:
system("cls");

int i;

cout<<"PROGRAM PERPUSTAKAAN\n"<<endl;
cout<<"1. Input Data Buku"<<endl;
cout<<"2. Sorting by Judul ( Ascending )"<<endl;
cout<<"3. Sorting by Pengarang"<<endl;
cout<<"4. Sorting by Tahun ( output berupa file )"<<endl;
cout<<"5. Searching by Judul Buku"<<endl;
cout<<"6. Exit\n"<<endl;
cout<<"Masukan Pilihan Anda [1-6] : ";
cin>>i;

switch(i)
{
case 1: {
data.input();
goto b;
}
case 2: {
data.sojud();
goto b;
}
case 3: {
data.sopeng();
goto b;
}
case 4: {
data.sotah();
goto b;
}
case 5: {
data.sejud();
goto b;
}
case 6: {
break;
}
default: {
cout<<"Anda Salah Memasukan Kode Pilihan !";
getch();
goto b;
}
}

getch();
}

void perpus::input()
{
b:
clrscr();
int x;

cout<<"Berapa Buku Yang Akan Di Inputkan : ";


cin>>no;

clrscr();
cout<<"INPUT BUKU\n"<<endl;
cout<<"
"<<endl;
cout<<" NO Judul Pengarang Jumlah Halaman Tahun "<<endl;
cout<<"
"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"
"<<endl;

for (x=0;x<no;x++)
{
gotoxy(3,6+x);
cout<<(x+1);
gotoxy(8,6+x);
gets(judul[x]);
strcpy(bjudul[x],judul[x]);
gotoxy(23,6+x);
gets(peng[x]);
strcpy(bpeng[x],peng[x]);
gotoxy(46,6+x);
cin>>hal[x];
bhal[x]=hal[x];
gotoxy(58,6+x);
cin>>tahun[x];
btahun[x]=tahun[x];
}
getch();
}

void perpus::sojud()
{
clrscr();
char tmp[30];
int it,x,y;

for (x=0;x<no;x++)
{
index[x]=x;
}

for(y=0;y<no;y++)
{
for(x=0;x<no-1;x++)
{
if(strcmp(bjudul[x],bjudul[x+1])>0)
{
strcpy(tmp,bjudul[x]);
strcpy(bjudul[x],bjudul[x+1]);
strcpy(bjudul[x+1],tmp);

it=index[x];
index[x]=index[x+1];
index[x+1]=it;
}
}
}

cout<<"SORTING BY JUDUL\n"<<endl;
cout<<"
"<<endl;
cout<<" NO Judul Pengarang Jumlah Halaman Tahun "<<endl;
cout<<"
"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"
"<<endl;

for (x=0;x<no;x++)
{
gotoxy(3,6+x);cout<<(x+1);
gotoxy(8,6+x);cout<<judul[index[x]];
gotoxy(23,6+x);cout<<peng[index[x]];
gotoxy(46,6+x);cout<<hal[index[x]];
gotoxy(58,6+x);cout<<tahun[index[x]];
}

getch();
}

void perpus::sopeng()
{
clrscr();
char tmp[30];
int it,x,y;

for (x=0;x<no;x++)
{
index[x]=x;
}

for(y=0;y<no;y++)
{
for(x=0;x<no-1;x++)
{
if(strcmp(bpeng[x],bpeng[x+1])>0)
{
strcpy(tmp,bpeng[x]);
strcpy(bpeng[x],bpeng[x+1]);
strcpy(bpeng[x+1],tmp);

it=index[x];
index[x]=index[x+1];
index[x+1]=it;
}
}
}

cout<<"SORTING BY PENGARANG\n"<<endl;
cout<<"
"<<endl;
cout<<" NO Pengarang Judul Jumlah Halaman Tahun "<<endl;
cout<<"
"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"
"<<endl;

for (x=0;x<no;x++)
{
gotoxy(3,6+x);cout<<(x+1);
gotoxy(8,6+x);cout<<peng[index[x]];
gotoxy(26,6+x);cout<<judul[index[x]];
gotoxy(49,6+x);cout<<hal[index[x]];
gotoxy(61,6+x);cout<<tahun[index[x]];
}

getch();
}
void perpus::sotah()
{
clrscr();
char tmp[30];
int it,x,y;

for (x=0;x<no;x++)
{
index[x]=x;
}

for(y=0;y<no;y++)
{
for(x=0;x<no-1;x++)
{
if(btahun[x] > btahun[x+1])
{
it=btahun[x];
btahun[x]=btahun[x+1];
btahun[x+1]=it;

it=index[x];
index[x]=index[x+1];
index[x+1]=it;
}
}
}

cout<<"SORTING BY TAHUN\n"<<endl;
cout<<"
"<<endl;
cout<<" NO Tahun Judul Pengarang Jumlah Halaman "<<endl;
cout<<"
"<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<"
"<<endl;
cout<<"\nInfo : Hasil sorting by tahun ini sudah"<<endl;
cout<<" disimpan berupa file yang bernama"<<endl;
cout<<" sort-tahun.txt ."<<endl;

ofstream ftahun;
ftahun.open("sort-tahun.txt");

ftahun<<"SORTING BY TAHUN"<<endl;
ftahun<<endl;
ftahun<<"-------------------------------------------------------------------"<<endl
;
ftahun<<"| NO | Tahun | Judul | Pengarang | Jumlah Halaman |"<<endl;
ftahun<<"-------------------------------------------------------------------"<<endl
;

for (x=0;x<no;x++)
{
gotoxy(3,6+x);cout<<(x+1);
gotoxy(8,6+x);cout<<tahun[index[x]];
gotoxy(16,6+x);cout<<judul[index[x]];
gotoxy(34,6+x);cout<<peng[index[x]];
gotoxy(57,6+x);cout<<hal[index[x]];

ftahun<<" "<<(x+1)<<" "<<tahun[index[x]]<<"\t"<<judul[index[x]]<<"\t\t


"<<peng[index[x]]<<"\t\t\t"<<hal[index[x]];
ftahun<<endl;
}
ftahun.close();

getch();
}

void perpus::sejud()
{
b:
clrscr();

int x,y,z,t,r;
char cari[30],j;

cout<<"SEARCHING BY JUDUL\n"<<endl;
cout<<"Masukan Judul Buku : ";
cin>>cari;

for(x=0;x<no;x++)
{
t=0;
for (y=0;y<strlen(cari);y++)
{
if (cari[y]==judul[x][y])
{
t=t+1;
if(t==strlen(cari))
{
z=x;
y=strlen(cari);
x=no;
}
}
else y=strlen(cari);
}
}

cout<<"\n";
cout<<""<<endl;
cout<<" Hasil Pencarian : "<<endl;
cout<<""<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<" "<<endl;
cout<<""<<endl;

if (t==strlen(cari))
{
gotoxy(4,8);cout<<"Judul Buku : "<<judul[z]<<endl;
gotoxy(4,9);cout<<"Nama Pengarang : "<<peng[z]<<endl;
gotoxy(4,10);cout<<"Jumlah Halaman : "<<hal[z]<<endl;
gotoxy(4,11);cout<<"Tahun : "<<tahun[z]<<endl;
}
else
{
gotoxy(9,10);
cout<<"Judul Tidak Di Temukan !!";
}

gotoxy(1,14);cout<<"Apakah Anda Mau Mencari Buku Lagi [Y/T] ? ";

do
{
j = toupper(getch());
}

while (!((j=='Y') || (j=='T')));


cout<<j<<endl;

if (j == 'Y')
goto b;

getch();
}

Anda mungkin juga menyukai