Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

ProLog Program of searching a students data when Name or a phone no is input

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

Write a complete prolog program to read a list of 10 students containing their name, address, Phone number and marks of five subjects. Now provide means for Searching a students data when Name or a phone no is input.

Code for ProLog Program of searching a students data when Name or a phone no is input in Artificial Intelligence

domains
    name,address = symbol
    phone = string
    l = integer*
    
predicates
    start
    repeat
    selectItem(integer)
    studentData
    subjectL(l)
    searchByName(name)
    searchByPhone(phone)
database
    studentDB(name,address,phone,l)
goal
    clearwindow,
    makewindow(1,7,7,"Search Student Detail",0,0,25,80),
    start.
clauses
    repeat.
        repeat:-
            repeat.
    start:-
        repeat,
        write("\n0.Exit"),
        write("\n1.Enter student data"),
        write("\n2.Search by Name"),
        write("\n3.Search by Phone number"),
        write("\n4.Show all Student Data"),
        write("\nEnter your choice::"),
        readint(Choice),
        selectItem(Choice),
        Choice=0.
    selectItem(0).
    selectItem(1):-
        studentData,
        fail.
    selectItem(2):-
        write("\nEnter your name::"),
        readln(Name),
        searchByName(Name),
        fail.
    selectItem(3):-
        write("\nEnter the phone no::"),
        readln(Phone),
        searchByPhone(Phone),
        fail.
    selectItem(4):-
        studentDB(Name,Address,Phone,Marks),
        write(Name,"  ",Address,"  ",Phone,"  ",Marks),nl,
        fail.
    studentData:-
        write("\nEnter the name of the student::"),
        readln(Name),
        write("\nEnter the address of the student::"),
        readln(Address),
        write("\nEnter the phone number of the student::"),
        readln(Phone),
        write("\nEnter the five subject marks of the student"),
        subjectL(Marks),
        assert(studentDB(Name,Address,Phone,Marks)).
    subjectL(Marks):-
        write("\nC ::"),
        readint(C),
        write("\nC++ ::"),
        readint(CC),
        write("\nVB ::"),
        readint(VB),
        write("\nJAVA ::"),
        readint(Java),
        write("\nPROLOG ::"),
        readint(Prolog),
        Marks=[C,CC,VB,Java,Prolog].
    searchByName(Name1):-
        studentDB(Name1,Address,Phone,Marks),
        write("\nName::",Name1),
        write("\nAddress::",Address),
        write("\nPhone::",Phone),
        write("\nMarks[C,C++,VB,Java,Prolog]::",Marks).
    searchByPhone(Phone1):-
        studentDB(Name,Address,Phone1,Marks),
        write("\nName::",Name),
        write("\nAddress::",Address),
        write("\nPhone::",Phone1),
        write("\nMarks[C,C++,VB,Java,Prolog]::",Marks).


Output  :


+-----------------------------Search Student Detail----------------------------+
¦0.Exit                                                                        ¦
¦1.Enter student data                                                          ¦
¦2.Search by Name                                                              ¦
¦3.Search by Phone number                                                      ¦
¦4.Show all Student Data                                                       ¦
¦Enter your choice::1                                                          ¦
¦                                                                              ¦
¦Enter the name of the student::hiral                                          ¦
¦                                                                              ¦
¦Enter the address of the student::10 b ,Panama society                        ¦
¦                                                                              ¦
¦Enter the phone number of the student::26640832                               ¦
¦                                                                              ¦
¦Enter the five subject marks of the student                                   ¦
¦C ::30                                                                        ¦
¦                                                                              ¦
¦C++ ::35                                                                      ¦
¦                                                                              ¦
¦VB ::40                                                                       ¦
¦                                                                              ¦
¦JAVA ::45                                                                     ¦
¦                                                                              ¦
¦PROLOG ::45        
                                                                              ¦
¦0.Exit                                                                        ¦
¦1.Enter student data                                                          ¦
¦2.Search by Name                                                              ¦
¦3.Search by Phone number                                                      ¦
¦4.Show all Student Data                                                       ¦
¦Enter your choice::4        
                                                  ¦
¦hiral  10 b ,Panama society  26640832  [30,35,40,45,45]     
                  
¦bright  1 nandan  26925740  [32,50,25,40,22]                  
                
¦nilima  21,b Amipura  26840131  [20,32,35,45,32]             
                 
¦nidhi  22,Ashapura  26861536  [32,33,41,31,36]         
                       
¦sweety  34,Radha  26637389  [22,15,23,22,20]      
                            
¦mikita  12,Prakruti  26637390  [20,30,40,45,25]       
                 
¦                                                                              ¦
¦0.Exit                                                                        ¦
¦1.Enter student data                                                          ¦
¦2.Search by Name                                                              ¦
¦3.Search by Phone number                                                      ¦
¦4.Show all Student Data                                                       ¦
¦Enter your choice::2                                                          ¦
¦                                                                              ¦
¦Enter your name::bright                                                       ¦
¦                                                                              ¦
¦Name::bright             
                                                     
¦Address::1 nandan      
                                                       
¦Phone::26925740       
                                                        
¦Marks[C,C++,VB,Java,Prolog]::[32,50,25,40,22]            
                          
                              
¦0.Exit                                                                        ¦
¦1.Enter student data                                                          ¦
¦2.Search by Name                                                              ¦
¦3.Search by Phone number                                                      ¦
¦4.Show all Student Data                                                       ¦
¦Enter your choice::3                                                          ¦
¦                                                                              ¦
¦Enter the phone no::26640832                                                  ¦
¦                                                                              ¦
¦Name::hiral             
                                                      
¦Address::10 b ,Panama society     
                                            
¦Phone::26640832         
                                                      
¦Marks[C,C++,VB,Java,Prolog]::[30,35,40,45,45]   
  
Share: 



Milind Mishra
Milind Mishra author of ProLog Program of searching a students data when Name or a phone no is input is from India.
 
View All Articles

Related Articles and Code:


 
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!