// 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 ;
		}
	}
}

Recommended Answers

All 7 Replies

Hi,

Could you elaborate clearly what is it that you want to do and what are the issues you are facing ?

in my store function,I want to store words and their meanings without using file handling..the meaning can be 5-6 lines long description...plz help...

I don't understand why you wish to store the words and their meaning without using file handling. Either you can hard-code all possible words-meanings into the program(highly improbable and bad) or you can use a database to store words and their meanings and then fetch them from the database. Which option do you prefer ?

bcz...later in this code i want to add encryption function also..i dont think with file handling i will be at ease...
moreover i want to perform searching and sorting...and using link lists is must in my program...file handling will also do but with link lists only...

As difficult as it is to make out much from your post above, I mentioned 2 alternatives in my earlier post, do you fancy using any of them ?

Storing the words and their meanings in a file and then loading from the file seems quite natural to me though.

ok...i agree to ur logic...but file handling using link lists only...

Cool. Then go ahead and do it and post back if you face any issues.

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.