% =====================KNOWLEDGE BASE==============================
% dynamic variables
:-dynamic(pc_member/2).
:-dynamic(pc_list/4).
% list of people registered as member. pc_member(ID,Name)
pc_member(110,ali).
pc_member(112,abdul).
pc_member(115,salmah).
pc_member(111,farah).
pc_member(118,siti).
% list of pc (all). pc_list(PcNum,Username,Usertype,Starttime)
pc_list(1,null,null,0).
pc_list(2,ali,member,2007).
pc_list(3,farah,member,1100).
pc_list(4,null,null,0).
pc_list(5,aminah,nonmember,0900).
pc_list(6,null,null,0).
pc_list(7,null,null,0).
pc_list(8,samad,nonmember,1434).
%pc_ava(X):- pc_list(X,null,_,_).
pc_available(L):-
findall(X,pc_list(X,null,_,_),L).
all_pc(L):-
findall(X,pc_list(X,_,_,_),L).
% =========================PROGRAMME===============================
% the program
run:-
greetings.
% ========================MAIN MENU================================
% main menu
greetings:-
nl,nl,
write('+---------------------------+'),nl,
write('| Epc-shop cybercafe Center |'),nl,
write('+---------------------------+'),nl,nl,
write(' Main Menu '),nl,
write(' -----------'),nl,
write(' 1 . PC Menu '),nl,
write(' 2 . Member Menu '),nl,
write(' 3 . Payment Menu '),nl,
write(' 4 . Terminate Program '),nl,nl,
write('Enter your selection : '),
read(X),
mainmenu(X).
% =======================PC MENU==================================
% pc menu
mainmenu(1):-
nl,nl,
write(' PC Menu '),nl,
write(' -------'),nl,
write(' 1 . View list of all pc '),nl,
write(' 2 . Register to use '),nl,
write(' 3 . Back to Main menu '),nl,nl,
write('Enter your selection : '),
read(X),
pcmenu(X).
% pc listing all.
pcmenu(1):-
write('+------------------------------------------------------+'),nl,
write('| PC NO | Name | Type | Start at |'),nl,
write('+------------------------------------------------------+'),nl,
listing(pc_list),nl,
mainmenu(1).
% pc listing all.
pcmenu(2):-
write('Enter pc number : '),read(W),nl,
write('Enter Name : '),read(X),nl,
write('Enter User Type : '),read(Y),nl,
write('Enter Start time (24-hours format): '),read(Z),nl,
retract(pc_list(W,_,_,_)),
assert(pc_list(W,X,Y,Z)),
write('PC loaded! : '),nl,
mainmenu(1).
% =======================MEMBER MENU================================
% member menu
mainmenu(2):-
nl,nl,
write(' Member Menu '),nl,
write(' -----------'),nl,
write(' 1 . View list of registered members '),nl,
write(' 2 . Search existing member '),nl,
write(' 3 . New member registration '),nl,
write(' 4 . Back to Main menu '),nl,nl,
write('Enter your selection : '),
read(X),
membermenu(X).
% member listing.
membermenu(1):-
write('+----------------------------------------------+'),nl,
write('| ID | Name |'),nl,
write('+----------------------------------------------+'),nl,
listing(pc_member),nl,
mainmenu(2).
% searching existing member.
membermenu(2):-
nl,nl,
write(' Searching Menu '),nl,
write(' --------------'),nl,
write(' 1 . By ID '),nl,
write(' 2 . By Name '),nl,
write(' 3 . Back '),nl,nl,
write('Enter your selection : '),
read(X),
searchmenu(X).
% search existing member by ID.
searchmenu(1):-
write('Enter member''s ID : '),
read(Z),
searching(Z).
searching(Z):-
pc_member(X,Y),nl,
Z=:=X,
write('Member information are :'),
write('ID: '),write(X),nl,
write('Name: '),write(Y),nl,
membermenu(2).
searching(Z):-
pc_member(X,Y),
Z=\=X,
write('Member not exist! :'),
membermenu(2),!.
% search existing member by name.
searchmenu(2):-
write('Enter member''s Name: '),
read(M),
searching2(M).
searching2(M):-
pc_member(X,Y),nl,
M=:=Y,
write('Member information are : '),
write('ID: '),write(X),nl,
write('Name: '),write(Y),nl,
membermenu(2).
searching2(M):-
pc_member(X,Y),
Z=\=Y,
write('Member not exist! :'),
membermenu(2),!.
%register new member
membermenu(3):-
write('Enter your name : '),
read(X),nl,
write('Enter your secret id : '),
read(K),nl,
assert(pc_member(X,K)),
write('Successfully add!'),nl,
mainmenu(2).
% ======================PAYMENT MENU================================
% payment menu
mainmenu(3):-
nl,nl,
write('List of available pc: '),nl,
write('+------------------------------------------------------+'),nl,
write('| PC NO | Name | Type | Start at |'),nl,
write('+------------------------------------------------------+'),nl,
listing(pc_list),nl,nl,
write('Enter pc number : '),read(W),nl,
pc_list(A,B,C,D),
W =:= A,
write('pc number : '),write(A),nl,
write('Customer Name : '),write(B),nl,
memberstatus(C,D).
% if PC not in use
memberstatus(null,0):-
write('PC not being use!'),nl,
greetings,!.
% for member PC usage
memberstatus(member,D):-
write('Enter current time (24-hours format) : '),read(X),nl,
Time is X-D,
Time2 is D/60,
Time3 is (Time2*2*0.9),
write('Status : '),write('member'),nl,
write('Start using pc at : '),write(D),nl,
write('End using pc at : '),write(X),nl,
write('Total time using : '),write(Time2),write(' hour'),nl,
write('Total payment is : RM'),write(Time3),nl,
total(1,Time3).
total(1,Time3):-
write('RM: '),write(Time3),
greetings.
% for non member PC usage
memberstatus(nonmember,D):-
write('Enter current time (24-hours format) : '),read(X),nl,
Time is X-D,
Time2 is D/60,
Time3 is (Time2*2),
write('Status : '),write('nonmember'),nl,
write('Start using pc at : '),write(D),nl,
write('End using pc at : '),write(X),nl,
write('Total time using : '),write(Time2),write(' hour'),nl,
write('Total payment is : RM'),write(Time3),nl,
greetings.
% ====================ERROR HANDLING===============================
% back to previous menu
membermenu(4):- greetings,!.
pcmenu(3):- greetings,!.
searchmenu(3):- mainmenu(2),!.
% to exit the program
mainmenu(4):-
nl,write('Exiting program..thank you'),nl,!.
% invalid data input
mainmenu(X):-
nl,write('Invalid input.Reenter again: '),nl,
greetings,!.
membermenu(X):-
nl,write('Invalid input.Reenter again: '),nl,
mainmenu(2),!.
searchmenu(X):-
nl,write('Invalid input.Reenter again: '),nl,
membermenu(2),!.
pcmenu(X):-
nl,write('Invalid input.Reenter again: '),nl,
mainmenu(1),!.
No comments:
Post a Comment