Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

ProLog Program to search car by company name, car name, price, class, color...

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 5394

Program to search car by company name, car name, price, class, color etc....

Code for ProLog Program to search car by company name, car name, price, class, color... in Artificial Intelligence

%trace
domains
    pr = price(real)
    clr = color(symbol)
    co = company(symbol)
    name = name(symbol)
    cls = class(symbol)

predicates
    data(name,co,clr,pr,cls)
    choice(integer)
    repeat
    
clauses

    repeat.
    repeat :-
        repeat.

    data(name(Van), company(maruti), color(White), price(265000), class(family)).
    data(name(fiat), company(fiat), color(white), price(200000), class(family)).
    data(name(Swift), company(maruti), color(Red), price(400000), class(family)).
    data(name(sumo), company(tata), color(white), price(300000), class(travel)).
    data(name(toyata), company(tata), color(black), price(800000), class(travel)).
    
    
    choice(1) :- 
        write("Enter Company Name : "),
        readln(CO_NAME),
        
        data(name(Z),company(CO_NAME),_,_,_),
        nl, write(Z),
        fail.
        
    choice(2) :-
        write("Enter Car Name : "),
        readln(CAR_NAME),
        
        data(name(CAR_NAME),company(X),color(Y),price(Z),_),
        nl, write(CAR_NAME), nl, write(X), nl, write(Y), nl, write(Z),
        fail.
        
    choice(3) :-
        write("Enter the Price : "),
        readreal(PRCE),
        
        data(name(X),_,_,price(PRCE),_),
        nl, write(X),
        fail.
        
    choice(4) :-
        write("Enter the Class (travel/family) : "),
        readln(CL),
        
        data(name(X),company(Y),_,_,class(CL)),
        nl, write(X), write(' '), write(Y),
        fail.
        
    choice(5) :-
        write("Enter the Color : "),
        readln(CLR),
        
        data(name(X),_,color(CLR),_,_),
        nl, write(X),
        fail.        
        
    choice(6) :-
        data(name(A),company(B),color(C),price(D),class(E)),
        nl, write(A), write(' '), write(B), write(' '), 
        write(C), write(' '), write(D), write(' '), write(E),
        fail.
        
    choice(0) :- !.
    
    
    goal 
        repeat,
        
        write("\n\n1. Search by Com Name"),
        write("\n2. Search by Car Name"),
        write("\n3. Search by Price"),
        write("\n4. Search by Class"),
        write("\n5. Search by Color"),
        write("\n6. Search all Cars"),
        write("\n0. Exit"),
        write("\n\nEnter your choice : "),
        readint(CH),
        choice(CH).
        
  
Share: 

 
 


Milind Mishra
Milind Mishra author of ProLog Program to search car by company name, car name, price, class, color... is from India.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Artificial Intelligence:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!