Saturday, 30 July 2011

Dictionary


//**********************************************************************************//
//        
//
//                   Project Name ::: C++ DICTIONARY
//
//                   Prepared By :::  ASHUTOSH SINGH
//
//
//
//
//********************************************************************************//

#include<fstream.h>
#include<conio.h>
#include<iomanip.h>
#include<dos.h>
#include<string.h>
#include<stdio.h>
#include<process.h>

class Dictionary
{
  public:

  char name[40],meaning[40],adj[40];
  void insert();
  void search();
  void write();
  void display();
  void read();
}D;

void Dictionary :: insert() // insert data function....
{
cout<<"\n\n\t\tWord Name : ";
gets(name);
cout<<"\n\n\t\tMeaning   : ";
gets(meaning);
cout<<"\n\n\t\tAdjective : ";
gets(adj);
}            // End Function..

void Dictionary :: display()   //Function start.
{
cout<<"\n\t\t\t\t:: Dictionary ::";

  cout<<"\n\n\n\tWord  : "<<name;
  cout<<"\n\t Meaning  : "<<meaning;
  cout<<"\n\tAdjective : "<<adj;

}     //End Function.



void Dictionary :: write()       //   WRITE DATA.
      {
      char ch1;
      Dictionary D;
      ofstream f1;
      D.insert();
      f1.open("dict.dat",ios::app | ios::binary);
      cout<<"\n\nDo you want to save Record (y/n). ";
      cin>>ch1;
      if(ch1=='y'||'Y')
      {
      f1.write((char*) &D,sizeof(D));
      cout<<"\n\n\n\t\t\t Adding in Dictionary....";
      delay(1500);
      cout<<"\n\n\n\n\n\t\tWord is Added in Dictionary.";
      }
      else
     {
     cout<<"\nErasing DATA....\n";
     delay(1000);
     }
      f1.close();

   }

   void Dictionary :: read()      //   FUNCTION READ THE VALUES.
{
clrscr();
fstream f1;
f1.open("dict.txt",ios::in | ios::binary);

f1.read((char*) &D,sizeof(D));

while(!f1.eof())
{
D.display();
getch();
f1.read((char*) &D,sizeof(D));
if(f1.eof())
cout<<"\n\n\n\n\nEnd of file Reached !!";

}
f1.close();
getch();
   }

   void Dictionary :: search()
    {
       char word[20],ch1,found='n';
   ifstream fin("dict.txt",ios::in);
   clrscr();
   z:
   cout<<"\n\n\t\t\t\t@ Search New Word @";
   cout<<"\n\n\t\t\t\t///////////////////";
   cout<<"\n\nEnter Word.. : ";
   gets(word);
   while(!fin.eof())
{

   fin.read((char*) &D,sizeof(D));

    if(strcmp(word,name))
  {
    cout<<"\n\nSearching....\n";
    delay(2000);
    cout<<"\n\n\aFound !\n";
    delay(150);
    clrscr();
    cout<<"\n\n\t\t\t\t  ....D E T A I L S ....  \n";
    D.display();
 

cout<<"\n///////////////////////////////////////////////////////\n\n";
    found='y';
    break;
  }
}

   if(found=='n')
   {
    cout<<"\nSearching.....";
    delay(3000);
    cout<<"\n\n\a\a\aNot Found !!\n";
    cout<<"\n\nWant to countinue ? (Y/N).\n";
    cin>>ch1;
    if(ch1=='y' || ch1=='Y')
    goto z;
   }
     fin.close();
    }



void main()
{
 clrscr();
 cout<<"\n\n\t\tWELCOME TO \"ASHUTOSH's\" DICTIONARY";
 delay(2500);
 for(int p=0;p<=100;p++)
 {
 clrscr();
 cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tPlease Wait..."<<p<<" %";
 delay(100);
 }
 delay(1500);
  clrscr();
    char ch;
    b:
    clrscr();
    cout<<"\n\n";
    cout<<"\n\t\t\t      DICTIONARY           ";
    cout<<"\n\t\t\t-----------------------------    ";
    cout<<"\n\t\t\t  -------------------------  \n\n";
    cout<<"\n\t\t\t||*********************||\n";
    cout<<"\n\t\t\t||  'A':Add Words.     ||\n";
    cout<<"\n\t\t\t||  'S':Search Words.  ||\n";
    cout<<"\n\t\t\t||  'D':Display Words. ||\n";
    cout<<"\n\t\t\t||  'E':EXIT.          ||\n";
    cout<<"\n\t\t\t||*********************||\n";
    cout<<"\n\n\t\tWhat`s your choice: ";
    cin>>ch;
    switch(ch)
     {

     case 'A' :

D.write();
getch();
goto b;
break;


     case 'S' :

D.search();
getch();
goto b;
break;

     case 'D' :
  D.read();
  getch();
  goto b;
  break;

     case 'E' :

     exit(0);

     default :

     clrscr();
     cout<<"\n\t\t\t\a\a\a\aWrong Choice !!!\a";
     cout<<"\n\nPress ENTER To Continue..";
     goto b;
     break;
    }

getch();
}

No comments:

Post a Comment