// Program Dictionary
// Proogram that uses linked list to maintain a dictionary
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
class dict
{
private :
struct node
{
char data[20] ;
char m[100] ;
int mcount ;
struct node * link ;
} *dic[22] ;
public :
dict( ) ;
void store ();
int search ( char * );
void show( ) ;
void deldic( ) ;
} ;
// initialises data member
dict :: dict()
{
for ( int i = 0 ; i < 22 ; i++ )
dic[i] = NULL ;
}
// stores word with their meanings in the dictionary
void dict :: store ( )
{
char * str,char * meaning
int i, j = toupper ( str[0] ) - 65 ;
node *r, *temp = dic[j], *q ;
char ch = 'y' ;
q = new node ;
strcpy ( q -> data, str ) ;
strcpy ( q -> m, meaning ) ;
q -> link = NULL ;
??????????????????here i want to store some strings...
like
intelligent="description having 5 6 lines";
i dont want to use file handling...plz help...?????????
}
// searches for given word in dictionary
int dict :: search ( char *str )
{
struct node *n ;
char temp1[20] ;
char temp2[20] ;
int i ;
n = dic[toupper ( str[0] ) - 65] ;
strcpy ( temp2, str ) ;
strupr ( temp2 ) ;
while ( n != NULL )
{
strcpy ( temp1, n -> data ) ;
if ( strcmp ( strupr ( temp1 ), temp2 ) == 0 )
{
cout << "\n" << n -> data << "\t\t" << n -> m ;
}
n = n -> link ;
}
return 0 ;
}
// displays word and its meaning
void dict :: show( )
{
node *n ;
int i, j ;
cout << "Word\t\tMeaning\n" ;
for ( i = 0 ; i <= 30 ; i++ )
cout << "-" ;
for ( i = 0 ; i <= 22 ; i++ )
{
n = dic[i] ;
while ( n != NULL )
{
cout << "\n" << n -> data << "\t\t" << n -> m ;
n = n -> link ;
}
}
}
void main( )
{
char word[20] ;
int ch ;
int i ;
dict d ;
char temp ;
clrscr( ) ;
while ( 1 )
{
clrscr( ) ;
cout << "\n\t\tDictionary\n" ;
cout << "\t\t1.Search Word.\n" ;
cout << "\t\t2.Show Dictionary.\n" ;
cout << "\t\t0.Exit." ;
cout << "\n\n\t\tYour Choice " ;
cin >> ch ;
switch ( ch )
{
case 1 :
cout << "\nEnter the word to search : " ;
cin >> word ;
i = d.search ( word ) ;
if ( ! i )
cout << "Word does not exists." ;
cout << "\nPress any key to continue..." ;
cin >> temp ;
break ;
case 2 :
d.show( ) ;
cout << "\nPress any key to continue..." ;
cin >> temp ;
break ;
case 0 :
exit ( 0 ) ;
break ;
default :
cout << "\nWrong Choice" ;
cout << "\nPress any key to continue..." ;
cin >> temp ;
}
}
}
learnersunakshi 0 Newbie Poster
Agni 370 Practically a Master Poster Featured Poster
learnersunakshi 0 Newbie Poster
Agni 370 Practically a Master Poster Featured Poster
learnersunakshi 0 Newbie Poster
Agni 370 Practically a Master Poster Featured Poster
learnersunakshi 0 Newbie Poster
Agni 370 Practically a Master Poster Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.