Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to read 10 string and store them in database and then write the string in increasing order of their length to other database

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

Write a complete prolog program to read 10 string and store them in database and then write the string in increasing order of their length to other database.

Code for Prolog program to read 10 string and store them in database and then write the string in increasing order of their length to other database in Artificial Intelligence

Predicates
    reading
    writing
    delete
    find(integer)
    startup(integer)

Database
    unsortedDatabase(string,integer)
    sortedDatabase(string)


clauses
    startup(0).
    
    startup(Num):-
        write("Enter String = "),
        readln(Name),
        str_len(Name,Len),
        asserta(unsortedDatabase(Name,Len)),
        TempNum = Num - 1,
        startup(TempNum).

    writing:-
        sortedDatabase(Name),
        write(Name),nl,
        fail.        
    writing.
    
    find(Index):-
        unsortedDatabase(Name,Index),
        assertz(sortedDatabase(Name)),
        retract(unsortedDatabase(Name,Index)),
        find(Index).
        
    find(Index):-
        Index = 255.
        
    find(Index):-
        TempIndex = Index + 1,
        find(TempIndex).

    reading:-
        NumRead = 10,
        startup(NumRead).
    
    delete :-
        retract(sortedDatabase(_)),
        fail.    
    delete.
            
Goal
    Clearwindow,
    makewindow(1,2,3,"String Operations",0,0,25,80),
    reading,!,
    find(1),
    write("\nString In Increasing Order Of Their Length Are : \n"),
    writing,
    delete.


Output :-->

+-------------------------------String Operations------------------------------+
¦Enter String = Mayank                                                         ¦
¦Enter String = Kesha                                                          ¦
¦Enter String = Zunobia                                                        ¦
¦Enter String = Slna                                                           ¦
¦Enter String = Salna                                                          ¦
¦Enter String = Anukul                                                         ¦
¦Enter String = Payal                                                          ¦
¦Enter String = Shwetambari                                                    ¦
¦Enter String = rahul                                                          ¦
¦Enter String = raj                                                            ¦
¦                                                                           ¦            
¦String In Increasing Order Of Their Length Are :                              ¦                  ¦                                                                              ¦                  
¦raj                                                                           ¦
¦Slna                                                                          ¦
¦rahul                                                                         ¦
¦Payal                                                                         ¦
¦Salna                                                                         ¦
¦Kesha                                                                         ¦
¦Anukul                                                                        ¦
¦Mayank                                                                        ¦
¦Zunobia                                                                       ¦
¦Shwetambari                                                                   ¦
¦                                                                              ¦
¦Press the SPACE bar                                                           ¦
¦                                                                              ¦
+------------------------------------------------------------------------------+
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to read 10 string and store them in database and then write the string in increasing order of their length to other database 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!