Main.cpp
#include <iostream>
#include "phew.h"
using namespace std;
int main()
{
address p;
list l;
infotype info;
createempty(&l);
int pil, pil2;
char jh[10];
do
{
system ("cls");
cout << "Penitipan Hewan\n";
cout << "================\n";
cout << "1. Input Data Penitipan Hewan\n";
cout << "2. Pengambilan Hewan\n";
cout << "3. Perpanjangan Waktu Penitipan Hewan\n";
cout << "4. Lihat Data Penitipan\n";
cout << "Pilihan : ";cin >> pil;
cout <<endl<<endl;
if (pil==1)
{
cout << "No Penitipan : " ; cin>>info.nope;
cout << "Nama Pemilik : " ; cin>>info.nama;
cout << "Jenis Hewan <1. Kucing> <2. Kelinci> <3. Ikan> : " ; cin>>pil2;
cout << "Lama Penitipan : " ; cin>>info.lamap;
if (pil2==1)
{
strcpy(info.jh,"Kucing");
info.biaya=info.lamap*50000;
}
if (pil2==2)
{
strcpy(info.jh,"Kelinci");
info.biaya=info.lamap*40000;
}
if (pil2==3)
{
strcpy(info.jh,"Ikan");
info.biaya=info.lamap*30000;
}
cout << "Biaya : " <<info.biaya;
cout << endl;
p=alokasi(info);
if (listempty(l)==true)
{
cout << "<<<Insert First>>>"<<endl;
insertfirst(&l,p);
cout << "Input data berhasil."<<endl;
}
else
{
cout << "<<<Insert Last>>>"<<endl;
insertlast(&l,p);
cout << "Input data berhasil."<<endl;
}
cout <<endl <<"Press any key to continue . . .";
getch();
}
if (pil==2)
{
cout << "1. Ambil Data Pertama \n";
cout << "2. Ambil DataAfter\n";
cout << "3. AMbil Data XXX\n";
cout << "Inputkan Pilihan : "; cin >>pil2;
if (pil2==1)
{
deletefirst(&l,&p);
}
if (pil2==2)
{
cout << "Inputkan No Penitipan : ";
cin >>info.nope;
deleteafter(&l,&p,searchdata(l,info.nope));
}
if (pil2==3)
{
cout << "Inputkan No Penitipan : ";
cin >>info.nope;
}
getch();
}
if (pil==3)
{
getch();
}
if (pil==4)
{
system ("cls");
cout << "1. Lihat Semua Data Penitipan\n";
cout << "2. Lihat Data Penitipan Berdasarkan Jenis Hewan\n";
cout << "3. Lihat Data Penitipan berdasarkan Nama Pemilik\n";
cout << "inputkan Pilihan : "; cin>>pil2;
cout <<endl<<endl;
if (pil2==1)
{
printallinfo(l);
}
if (pil2==2)
{
cout << "Lihat Berdasarkan Jenis Hewan\n";
cout << "1. Kucing\n";
cout << "2. Kelinci\n";
cout << "3. Ikan\n";
cout << "Inputkan Pilihan : "; cin >> pil2;
if (pil2==1)
{
strcpy(jh,"Kucing");
}
if (pil2==2)
{
strcpy(jh,"Kelinci");
}
if (pil2==3)
{
strcpy(jh,"Ikan");
}
printinfojenis(l,jh);
}
if (pil2==3)
{
cout << "Lihat Berdasarkan Nama Pemilik \n";
cout << "Inputkan Nama Pemilik : "; cin>>info.nama;
printinfopemilik(l,info.nama);
}
getch();
}
}while(pil==1 || pil==2 || pil==3 || pil==4);
}
PHew.cpp
#include <iostream>
#include "phew.h"
using namespace std;
bool listempty(list l)
{
if (first(l)==nil)
return true;
else
return nil;
}
void createempty(list *l)
{
first(*l)=nil;
}
address alokasi(infotype x)
{
address p;
p=(address)malloc(sizeof(elmlist));
info(p).nope=x.nope;
strcpy(info(p).nama,x.nama);
strcpy(info(p).jh,x.jh);
info(p).lamap=x.lamap;
info(p).biaya=x.biaya;
next(p)=nil;
prev(p)=nil;
return p;
}
void dealokasi(address p)
{
free(p);
}
void insertfirst(list *l, address p)
{
next(p)=first(*l);
first(*l)=p;
last(*l)=p;
}
void insertlast(list *l, address p)
{
address q;
q=first(*l);
while(next(q)!=nil)
{
q=next(q);
}
next(q)=p;
prev(p)=q;
last(*l)=p;
}
void delp(list *l, int nopenitipan)
{
// address q,p;
// p=searchdata(*l,nopenitipan);
// q=prev(p);
// next(p)=next(q);
// prev(next(q)=p);
// prev(q)=nil;
// next(q)=nil;
// dealokasi(q);
}
void deletefirst(list *l, address *p)
{
first(*l)=next(first(*l));
next(*p)=nil;
prev(first(*l))=nil;
next(*p)=nil;
dealokasi(*p);}
void deleteafter(list *l, address *p, address prec)
{
address q;
q=next(prec);
next(prec)=next(q);
prev(next(q)=prec);
prev(q)=nil;
next(q)=nil;
dealokasi(q);
}
void printallinfo(list l)
{
address p;
p=first(l);
while (p!=nil)
{
cout << "No Penitipan : " <<info(p).nope<<endl;
cout << "Nama Pemilik : " <<info(p).nama<<endl;
cout << "Jenis Hewan : " <<info(p).jh<<endl;
cout << "Lama Penitipan : " <<info(p).lamap<<endl;
cout << "Biaya : " <<info(p).biaya<<endl<<endl;
p=next(p);
}
}
void printinfojenis(list l, char jenishewan[20])
{
address p;
p=first(l);
while (p!=nil)
{
if (strcmpi(info(p).jh,jenishewan)==0)
{cout << "No Penitipan : " <<info(p).nope<<endl;
cout << "Nama Pemilik : " <<info(p).nama<<endl;
cout << "Jenis Hewan : " <<info(p).jh<<endl;
cout << "Lama Penitipan : " <<info(p).lamap<<endl;
cout << "Biaya : " <<info(p).biaya<<endl<<endl;}
p=next(p);
}
}
void printinfopemilik(list l, char namapemilik[50])
{
address p;
p=first(l);
while (p!=nil)
{
if (strcmpi(info(p).nama,namapemilik)==0)
{cout << "No Penitipan : " <<info(p).nope<<endl;
cout << "Nama Pemilik : " <<info(p).nama<<endl;
cout << "Jenis Hewan : " <<info(p).jh<<endl;
cout << "Lama Penitipan : " <<info(p).lamap<<endl;
cout << "Biaya : " <<info(p).biaya<<endl<<endl;}
p=next(p);
}
}
void updatedata(list l)
{
}
address searchdata(list l, int nopenitipan)
{
address p;
p=first(l);
while (p!=nil)
{
if (info(p).nope==nopenitipan)
return p;
}
PHew.h
#ifndef PHEW_H_INCLUDED
#define PHEW_H_INCLUDED
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define nil NULL
#define info(p) (p)->info
#define next(p) (p)->next
#define prev(p) (p)->prev
#define first(l) ((l).first)
#define last(l) ((l).last)
typedef struct
{
int nope;
char nama[10];
char jh[10];
int lamap;
int biaya;
}infotype;
typedef struct telmlist *address;
typedef struct telmlist
{
infotype info;
address next, prev;
}elmlist;
typedef struct
{
address first, last;
}list;
bool listempty(list l);
void createempty(list *l);
address alokasi(infotype x);
void dealokasi(address p);
void insertfirst(list *l, address p);
void insertlast(list *l, address p);
void delp(list *, char x[10]);
void deletefirst(list *l, address *p);
void deleteafter(list *l, address *p, address prec);
void printallinfo(list l);
void printinfojenis(list l, char jenishewan[20]);
void printinfopemilik(list l, char namapemilik[50]);
void updatedata(list l);
address searchdata(list l, int nopenitipan);
#endif // PHEW_H_INCLUDED
0 komentar:
Post a Comment