Tuesday, November 2, 2010

Haapy Deepavali

Post to my social network or blog

Happy Deepavali By :-
SATYAM SRIVASTAVA    /   DIKSHA SRIVASTAVA
SHUBHAM SRIVASTAVA
PRIYAM SRIVASTAVA

Saturday, October 30, 2010

18.Program to demonstrate reversing of an input text using a function with string arguments.

// Program  to demonstrate reversing of  an input text
// using a function with string arguments.


#include <stdio.h>
#include <iostream.h>
#include<conio.h>
/* strlen - return length of string s
 */
int strlen(char s[])
    {
    int i;
    for (i = 0; s[i] != '\0'; ++i);
    return (i);
    }

/* reverse - reverses order of characters in a string
 */
void reverse(char s[])
    {
    char t;
    short i, j;

    for (i = 0, j = strlen(s) - 1; i < j; ++i, --j)
t = s[i], s[i] = s[j], s[j] = t;
    }

main()
    {
    char line[BUFSIZ];  /* the line of input text */

    cout<<endl;
    cout<<"Input String to obtain in reverse");
    cin.getline(line,BUFSIZ);
    reverse(line);
    cout<<endl;
    cout<<line;
    getch();
}

Friday, October 22, 2010

17.Matrices : To implement cell value of a defined matrix

// Program for  : Matrices : To implement cell value of a defined matrix
// Input: Row & Col. and Output : Cell element of the points Row, Col.

#include <stdlib.h>
#include <iostream.h>
#include<conio.h>
int main()
{
clrscr();
  int x, y;                    // Loop Counter
  int x1, y1, repeat;
  //         x, y           Think like that if you input x = 1, y = 3
  //                        You will output "69", that how a matrix works
  int matrix[4][4] = { 12, 4, 23, 6,
      45, 78, 3, 57,
      69, 23, 9, 2,
      34, 11, 5, 99 };
  cout<<"My Matrix: "<< endl << endl;
  for( x = 0; x < 4; x++)
  {
       for( y = 0; y < 4; y++)
       {
   cout<< matrix[x][y] << " ";
       }
       cout<<endl;
  }
  cout<< endl <<"Both x and y have a max point of 3" << endl;
  do
  {
       cout<< endl <<"Enter in x and y points[ x <space> y ]: ";
       cin>> x1 >> y1;

       cout<<"Point ("<< x1 <<", " << y1 <<") = " << matrix[x1][y1] << endl
  << endl;
       cout<<"Would You like Output new points (0 to quit)? ";
       cin>> repeat;
  }while( repeat != 0);
  cout<<endl;
  cout<<"Press any key to continue";
  getch();
  return 0;
}

16.Program to Calculate Polynomial. Loading the libraries.

// Program to  Calculate Polynoms

//Loading the libraries
#include <iostream.h>
#include <math.h>
#include<conio.h>
//Defining variables
int result=0; //here will be stored the result
int *arr; //here will be stored the numbers
int power; //this is the maximum power
int x; //the value for "x"

//Beginning the main function
void main()
{
 cout << "What s the maximum power in the polynom? : ";
 cin >> power;
 cout << endl;

 arr=new int[power]; //creates an array with "power" cells
 
 //Asking the user to enter the values...
 for(int n=0;n<power+1;n++)
 {
  cout <<"A"<<power-n<<" = ";
  cin >> arr[power-n];
 }

 cout << "The polynom is: ";

 //Prints the polynom on the screen
 for(int go=power; go >-1; go--)
 {
  if(go > 0)
   cout <<arr[go]<<"*x^"<<go<<" + ";
  else
   cout <<arr[go]<<"*x^"<<go;
 }
 cout <<endl;
 cout <<"Enter value for X : ";
 cin >> x;

 //Calculating the polynom
 for(int cal=0; cal < power+1; cal++)
 {
  result=result+(arr[cal]*(pow(x,cal)));
 }

 cout <<" Y(x)= "<< result<<endl; // showing the result
 getch();
}

15.Program to display Fibonaccis Heap

// Program to display  Fibonaccis Heap

#include <iostream.h>
#include<conio.h>

void main()
{
clrscr();
   unsigned int to,a,n,n1,n2,sum;

   cout << "Enter the limit: n=";
   cin >> to;
   to--;

   n1=n2=1;
   a=2;
   sum=2;

   cout << "Fibonacci's numbers: " << endl;
   cout << "1 1 ";

   while(a<=to)
   {
      n=n1+n2;
      cout << n << " ";
      n1=n2; n2=n;
      sum=sum+n;
      a++;
   }

   cout << endl << endl ;
   cout << "Sum of all numbers= "<< sum << endl;
   getch();
}

Thursday, October 21, 2010

14.Declaration of a Class and manipulation of member function. Display of the result of students with computed grade of marks.

//  Declaration of a Class and manipulation of member function.
//  Display of the result of students with computed grade of marks.

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
class result // Declaration of the Class
{
private:
int serialno;
int rollnum;
int total;
int percent;
public:
void inputdata(int ser,int rol,int tot,int per)
{
serialno = ser;
rollnum = rol;
total = tot;
percent = per;
}
void display(void)
{
clrscr();
gotoxy(30,5);
cout<<"R E S U L T ";
cout<<endl;
// Music creation through sound command
for(double d=0;d<=800;d++)
{sound (d);
delay(5);  }
nosound();
// Sound command de-activated
char grade[20];
cout<<endl<<"The serial number is "<<serialno;
cout<<endl<<"The roll number is "<<rollnum;
cout<<endl<<"The total marks is "<<total;
cout<<endl<<"The percent marks is "<<percent;
if (percent<40) strcpy(grade,"Fail");
if (percent>=40 && percent<60) strcpy(grade,"Pass");
if (percent>=60 && percent<80) strcpy(grade,"First");
if (percent>=80) strcpy(grade,"Excellent");
cout<<endl<<"The grade obtained is "<<grade;
cout<<endl;
}
};
main()
{
result studrecord;
int ser;
int rol;
int tot;
int per;
clrscr();
cout<<"Enter the serial number"<<endl;
cin>>ser;
cout<<"Enter the rollnumber"<<endl;
cin>>rol;
cout<<"Enter the total"<<endl;
cin>>tot;
per=tot/5;
clrscr();
studrecord.inputdata(ser,rol,tot,per);
studrecord.display();
cout<<endl;
cout<<"Press any key to return ";
getch();
clrscr();// Screen cleared for the next program output.
return 0;
 }

13.Program to depict the usage of Binary Search Technique.

// Program to depict the usage of Binary Search Technique.
// It is assumed that the list of numbers in an array is
// stored in ascending order.

#include<iostream.h>
#include<conio.h>
main()
{
int num[10],m,min,max,mid,pp;
clrscr();
cout<<"Enter any ten numbers as elements ofan array in";
 cout<<" ascending order "<<endl;
for (int i=0;i<10;i++)
{
cin>>num[i];
}
cout<<endl<<"Enter number to search ";
cin>>m;
cout<<endl;
min = 0;
max = 9;
pp = -1;
while ((min<= max)&&(pp == -1))
{
mid = (min+max)/2;
if (num[mid] == m)
pp = mid;
else
if (num[mid]<m)
min = mid + 1;
else
max = mid - 1;
}
if (pp>-1)
cout<<"The element "<<m<<" lies in the array"<<" at "<<pp+1<<" position";
else
cout<<"The element does not lie in the array";
cout<<endl;
cout<<"Program over....press any key to continue";
getch();
return 0;
}

Friday, October 15, 2010

ADD if you like bye this product

12.Program to input any string upto 500 characters and convert the same into binary

// Program to input any string upto 500 characters
// and convert the same into binary
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>

char *entry, letter, choice[2];
int ascii, len, binary[8], total;
void prog();

int main()
{
      clrscr();
      prog();
      return 0;
}

void prog()
{
   entry = new char[501];
   cout<<"Enter string to convert (up to 500 chars): ";
   cin.getline(entry, 500);
   len = strlen(entry);  /* get the number of characters in entry. */
   for(int i = 0; i<len; i++)
   {
      total = 0;
      letter = entry[i]; /* store the first letter */
      ascii = letter;    /* put that letter into an int, so we can
   see its ASCII number */
      while(ascii>0) /* This while loop converts the ASCII # into binary,
stores it backwards into the binary array. */
      {
if((ascii%2)==0)
{
   binary[total] = 0;
   ascii = ascii/2;
   total++; /* increasing by one each time will yeild the
number of numbers in the array. */
}
else
{
   binary[total] = 1;
   ascii = ascii/2;
   total++;
}
      }
      total--;
      while(total>=0)
      {
cout<<binary[total];
total--;
      }
   }
   delete[] entry; /* free up the memory used by entry */
   cout<<endl<<"Do again(1 = yes, 2= no)?: ";
   cin.getline(choice,3);
   if(choice[0] == '1')
      prog();
   else
      exit(0); /* quits the program */
}

11.Program to define a class point and implement operations

// Program to define a class point and implement operations

#include<iostream.h>
#include<math.h>
#include<conio.h>
class Point{
public:
     Point();
void setPoint(float,float);
void printPoint();
float getx();
float gety();

private:
   float x;
   float y;

      };
  Point::Point(){x=0.0;y=0.0;}
void Point::setPoint(float a,float b)
  {x=a;y=b;}
void Point::printPoint()
     {
     cout<<'('<<x<<","<<y<<')';
     }
float Point::getx(){return x;}
float Point::gety(){return y ;}

  void main()
{
clrscr();
Point p1,p2;
char ch;

cout<<"Initially,the points are :";
  p1.printPoint();

cout<<",";

  p2.printPoint();
cout<<endl;
p1.setPoint(3.5,4.5);
p2.setPoint(7.5,9.5);

  cout<<"After setting the points are:";

p1.printPoint();
cout<<",";
p2.printPoint();
cout<<endl;
  float d=0.0;
d=sqrt((p2.getx()-p1.getx())*(p2.getx()-p1.getx())+(p2.gety()-p1.gety())*(p2.gety()-p1.gety()));
cout<<"d="<<d<<endl;

cout<<"Enter any key to continue";
getch();
}

Thursday, October 14, 2010

10. Program to get the day the month starts on, and the number of days in the month to output a calendar.

// Program to get the day the month starts on, and
//the number of days in the month to output a calendar.

//-------------------Includes--------------------
#include <iostream.h>
#include<conio.h>

//--------------Function Prototypes--------------
int ShowDateLine(int day, int EndDay, int BoxWidth);
void ShowRestOfBox(int BoxWidth, int BoxHeight);
void ShowDates(int BoxWidth);
void Divider(int BoxWidth);

//---------------------Main----------------------
int main()
{
    int StartDay, EndDay, day, counter, weeks;
    const int BoxWidth = 8, BoxHeight = 3;
    char end;
    cout << "1. Sun  2. Mon  3. Tue  4. Wed " << endl;
    cout << "5. Thu  6. Fri  7. Sat" << endl << endl;
    do
    {
        cout << "Enter the starting day: ";
        cin >> StartDay;
        if ((StartDay < 1) || (StartDay > 7))
        {
            cout << "\aError, must be between 1 and 7.\n";
}
    }
    while ((StartDay < 1) || (StartDay > 7)); /* Error checking */
    day = StartDay * -1 + 2;
    cout << "Enter the amount of days in the month: ";
    cin >> EndDay;
    cout << endl;
    weeks = (EndDay + StartDay - 2) / 7;
weeks++;
    //----------------Draw Calendar------------------
    ShowDates(BoxWidth);
    Divider(BoxWidth);
    for (counter = 0; counter < weeks; counter++)
    {
        day = ShowDateLine(day, EndDay, BoxWidth);
        ShowRestOfBox(BoxWidth, BoxHeight);
        Divider(BoxWidth);
    }
    cout<<"Press any key to continue"<<endl;
getch();
}

//------------------Functions--------------------
int ShowDateLine(int day, int EndDay, int BoxWidth)
/* Outputs a '*' then it outputs the days till it reaches the 'EndWeek' value.
If day reaches the EndDay value, then it will output a space instead of a day.
After each date it will output a '*', then proceed 'BoxWidth' spaces ahead. */
{
    int counter, EndWeek;
    cout.setf(ios::right);
    cout << "*";
    EndWeek = day + 7;
    for (counter = 0; counter < 7; counter++, day++)
    {
        cout.width(BoxWidth - 1);
        if ((day < 1) || (day > EndDay))
        {
            cout << " ";
        }
        else
        {
            cout << day;
        }
        cout << "*";
    }
    cout << endl;

    return day;
}
//-----------------------------------------------
void ShowRestOfBox(int BoxWidth, int BoxHeight)
/* Outputs a '*' every 'BoxWidth' length, for a total of 8 '*'.
It does that 'BoxHeight' times. */
{
    int countera, counterb;
    cout.setf(ios::right);
    for (countera = 1; countera < BoxHeight + 0; countera++)
    {
        cout << "*";
        for (counterb = 0; counterb < 7; counterb++)
        {
             cout.width(BoxWidth);
             cout << "*";
        }
        cout << endl;
    }
}
//-----------------------------------------------
void ShowDates(int BoxWidth)
/* Outputs the all 7 days of the week. It takes the 'BoxWidth' and outputs the
day in the
middle of where the box will be. */
{
  cout.setf(ios::right);
  cout.width(BoxWidth / 2 + 2);
  cout << "Sun";
  cout.width(BoxWidth);
  cout << "Mon";
  cout.width(BoxWidth);
  cout << "Tue";
  cout.width(BoxWidth);
  cout << "Wed";
  cout.width(BoxWidth);
  cout << "Thu";
  cout.width(BoxWidth);
  cout << "Fri";
  cout.width(BoxWidth);
  cout << "Sat" << endl;
}
//-----------------------------------------------
void Divider(int BoxWidth)
//Outputs a bar of '*' 'BoxWidth' * 7 + 1
{
    int length, counter;
    length = BoxWidth * 7 + 1;
    for (counter = 0; counter < length; counter++)
    {
        cout << "*";
    }
    cout << endl;
}

9. Program to print the corresponding ASCII character

// Program to print the  corresponding ASCII character

#include <stdio.h>
#include <fstream.h>
#include <stdlib.h>
#include<conio.h>
main()
    {
    clrscr();
    char line[512]; /* input string */
    char sym;       /* ASCII code number */
    cout<<"Please enter the number to be factored: ";
    cin.getline(line, 512);
    sym = atoi(line);
    cout<<int(sym)<<"  is the ASCII code for ";
    if (sym == 0)
cout<<"null\n";
    else if (sym == ' ')
cout<<"blank\n";
    else if (sym == 127)
cout<<"del\n";
    else if (sym >=  1 && sym <=  31)
cout<<"CONTROL-\n"<< sym + 64;
    else if (sym >= '0' && sym <=  '9')
cout<<"digit \n"<< sym;
    else if (sym >= 'A' && sym <=  'Z')
cout<<"UPPERCASE \n"<< sym;
    else if (sym >= 'a' && sym <= 'z')
cout<<"lowercase \n"<< sym;
    else
cout<<"punctuation mark \n"<< sym;
getch();
    }

// Program to input a string and print the character with the maximum frequency in the string.

// Program to input a string and print the character with the
// maximum frequency in the string.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
#include<string.h>
main()
{
clrscr();
char name[40],ans;
int l=0,count=0,max=0;
cout<<"Enter any word "<<endl;
gets(name);
l = strlen(name);
cout<<endl;
for(int a=0;a<l;a++)
{
for (int b=0;b<l;b++)
{
if (name[a]==name[b] && name[a]!=' ')
count = count+1;
}
if (max<count)
{
max=count;
ans=name[a];
}
count=0;}
cout<<endl<<"The character with maximum frequency is ";
cout<<ans<<" with occurring "<<max<<endl;
getch();
return 0;
}

Tuesday, October 12, 2010

7.This C++ program displays the month

// This C++ program displays the month
// of any year and also has controls to view the
// previous & the Next  months.

# include <iostream.h>
# include <stdio.h>
# include <conio.h>
void main()
{
    clrscr();
    int b1,b2,o;
  cout<<"  ENTER THE MONTH  : ";
cin>>b1;
cout<<"  ENTER THE YEAR  : ";
cin>>b2;
a:cout<<"\n";
     o = b1-1;
    int
i,j,k=0,l=0,m=0,n=0,b3,c=0,c1,c2,c3,a[12]={31,28,31,30,31,30,31,31,30
,31,30,31};
    int ab[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
    char *z[12] =
{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
char choice;
    for (o=0;o<=11;o++)
    {
     if (b1 == ab[o])
     {
      cout<<"\n         "<<z[o]; cout<<"       "<<b2;
     }
    }
if(b2%4==0)
a[1] = 29;
    else
        a[1] = 28;
if(b2>=2000)
b3=b2-2000;
else
{
b3=2000-b2;
b3*=2;
}
if(b1==12)
n=12;
if(b1==1)
{
k=11;
l=1;
for(i=0;i<=k;i++)
m+=a[i];
}
for(i=0;i<(b1-1);i++)
c+=a[i];

   c2=(c+b3)%7;
   textcolor(10);
cout<<"\n\n\n\n";
cout<<"  SU  MO  TU  WE  TH  FR  SA\n\n";
for(j=0;j<c2;j++)
cout<<"    ";
for(j=1;j<=a[b1-1];j++)
{
if(j<10)
cout<<"   "<<j;
else
cout<<"  "<<j;
if((j+c2)%7==0)

cout<<"\n\n";
}
cout<<"\n";


    cout<<"\n\n Use these arrow keys to display the Sequential Year or Month :   \n";
    cout<<"**************************************************************\n";
    cout<<" |     Up    = Next Year  |   Down = Previous Year   | \n";
    cout<<" |     Right = Next Month   |   Left = Next Month   | \n";
    cout<<"************************************************************** \n";
    choice = getch();
    if (choice==0)
    {
     choice = getch();
     switch(choice)
     {
      case 80  : {b2-=1; goto a; break;}
      case 72  : {b2+=1;goto a; break;}
      case 75 :  {
 if (b1!=1)
                    b1-=1;
                  else
                   {b1=12; b2-=1;}
                 goto a; break;}
      case 77 : {
                 if (b1!=12)
                   b1+=1;
                 else
                   {b1 = 1; b2+=1;}
                 goto a; break;}
     }
    }
 getch();
}

Thursday, September 30, 2010

Program to print prime factorization

// Program to print prime factorization

#include<conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>
main()
    {
    clrscr();
    char line[512]; /* input string */
    short ii;   /* number to be factored */
    short j;   /* divisors */
    short p;   /* powers of j in ii */
    cout<<"Please enter the number to be factored: ";
    cin.getline(line, 512);
    ii = atoi(line);
    cout<<"The prime divisors of "<< ii<< " are/ is ";
    for (j = 2; ii != 1; j = j + 1)
{
if (ii % j == 0)
   {
   for (p = 0; ii % j == 0; p = p + 1)
ii = ii / j;
   cout<< j<<" ";
   }
}
    cout<<endl;
    getch();
    }

Program to conduct binary search for any alphabet [a-z] out of an array.

// Program to conduct binary search
// for any alphabet [a-z] out of an array.
#include <ctype.h>
#include <conio.h>
#include <iostream.h>

#define max 26

char array[max] = "\0";

void initialise()
{
for(int i=0; i<max; i++)
{
array[i] = (char)(65+i);
}
}

int binsearch(int low, int high, int &num)
{
int mid = (high+low)/2;

if( array[mid] == num )
{
return mid;
}
else if( low >= high )
{
return -1;
}
else if( num > array[mid] )
{
return binsearch(mid+1, high, num);
}
else if( num < array[mid] )
{
return binsearch(low, mid-1, num);
}
else return -2;
}

void main()
{
char alpha;
int number;
int   result;

clrscr();
initialise();

cout << "Enter the alphabet to search [lower case]: ";
cin  >> alpha;

number = (int)toupper(alpha);

result = binsearch(0, max, number);

if( result >= 0 )
{
cout << "Found at index # : " << result+1;
}
else if( result == -1 )
{
cout << "Not Found";
}
        else cout << "Unspecified Error";

        getch();
}

Program using structure to define a Bank A/c System

// Program using structure to define a Bank A/c System

#include "iostream.h"
#include "conio.h"
#include "stdio.h"
struct account
{
int no[10];
char name[20];
long int d,b,a;
long double t;
};
void main()
{
clrscr();
window(27,2,53,4);
textbackground(3);
clrscr();
textcolor(0);
cprintf(" \n   BANK ACCOUNT SYSTEM");
/*menu*/
window(20,5,60,25);
textbackground(13);
clrscr();
gotoxy(2,3);
textcolor(10);
cprintf("G");
gotoxy(3,3);
textcolor(14);
cprintf("ive The Account No.");
/*name of the account holder*/
textcolor(10);
gotoxy(2,5);
cprintf("E");
textcolor(14);
gotoxy(3,5);
cprintf("nter The Name ");
/*balance*/
textcolor(10);
gotoxy(2,7);
cprintf("A");
textcolor(14);
gotoxy(3,7);
cprintf("mount");
/*amount*/
account i;
/*input*/
gotoxy(22,3);
cin>>i.no[10];
gotoxy(22,5);
cin>>i.name;
gotoxy(22,7);
cin>>i.a;
gotoxy(3,14);textcolor(11);
cout<<"Name: "<<i.name;
/*runtime calculations*/
/*******************************for deposit*******************************/
i.d=i.a+5;
gotoxy(3,16);
cout <<"The Deposite Is: "<<i.d;
/****************************Tax Deduction ***********************************/
i.t=700.8/i.d*100;
gotoxy(3,18);
cout <<"The deduced Tax is :"<<i.t;
gotoxy(15,35);
cout <<"%";
/***************************For Balance**********************************/
i.b=i.d-i.t;

/********** object of the struct account********************/
if (i.b>0 && i.a<=i.b)
{
gotoxy(3,20);
cout <<"WITHDRAW THE BALANCE :"<<i.b;
}
else
     {
       gotoxy(3,20);textcolor(11);
cprintf("Can't Withdraw Your Balance!!!");}
getch();
}

Program to perform updation of a data file for mainipulating an address book

//Program to perform updation of a data file
// for mainipulating an address book

#include<stdio.h>
#include<stdlib.h>
#include<fstream.h>
#include<string.h>
#include<conio.h>
#define ENTER 13
#define BACK 8


struct student
{
  char name[30];
  char proff[40];
  char address[20];
  char country[20];
  char tel[20];
  char fax[20];
  char mobile[20];
  char email[50];
};

class data
{
private:
  student std;
  int j,count;
  char sname[50],pass[10],c;
public:
  struct student getData();
  void showData(struct student);
  void saveData();
  int readData();
  void delet();
  void modify();
  void searchData();
  void emergency();
  void password();
  int checkpass();
  void modpass();
  char* takepass();
  int checkvalidity(char []);
};

student data::getData()
{
 cout<<"Name          : ";
 gets(std.name);
 cout<<"Proffession   : ";
 gets(std.proff);
 cout<<"Address       : ";
 gets(std.address);
 cout<<"Country       : ";
 gets(std.country);
 cout<<"Telephone     : ";
 gets(std.tel);
 cout<<"Fax           : ";
 gets(std.fax);
 cout<<"Mobile        : ";
 gets(std.mobile);
 cout<<"E.mail        : ";
 gets(std.email);
}
void data:: showData(student str)
{
clrscr();
cout<<"\nName         : "<<str.name;
cout<<"\nProffession  : "<<str.proff;
cout<<"\nAddress      : "<<str.address;
cout<<"\nCountry      : "<<str.country;
cout<<"\nTelephone    : "<<str.tel;
cout<<"\nFax          : "<<str.fax;
cout<<"\nMobile       : "<<str.mobile;
cout<<"\nE.mail       : "<<str.email;
getch();
}
void data::modify()
{
char dname[30];
int l;
int coutn=0,choice;
int k=0;
l=checkpass();
if(l==1)
{
cout<<"\nPlease mention the name to be modified : ";
cin>>dname;
fstream infile;
infile.open("tata.Dat",ios::in|ios::out);
infile.seekg(0);
if(infile)
{
while(infile.read((char *)&std,sizeof(student)))
{
   coutn++;
   char ans='y';
   if(stricmp(std.name,dname)==0)
   {
   k=1;
   while(ans=='y'||ans=='Y')
   {
   clrscr();
   cout<<"What do you want to modify\n1.Name\n2.Proffession\n3.Address ";
   cout<<"\n4.Country\n5.Telephone Number\n6.Fax Number\n7.Mobile";
   cout<<"\n8.E-mail\t";
   cin>>choice;
   switch(choice)
   {
 case 1:
cout<<"Name          : ";
cin>>std.name;
break;
 case 2:
cout<<"Proffession   : ";
cin>>std.proff;
break;
 case 3:
cout<<"Address       : ";
cin>>std.address;
break;
 case 4:
cout<<"Country       : ";
cin>>std.country;
break;
 case 5:
cout<<"Telephone     : ";
cin>>std.tel;
break;
 case 6:
cout<<"Fax           : ";
cin>>std.fax;
break;
 case 7:
cout<<"Mobile        : ";
cin>>std.mobile;
break;
 case 8:
cout<<"E-mail        : ";
cin>>std.email;
break;
 default:
cout<<"Wrong choice ";
break;
   }
   cout<<"\nAnything More to modify ";
   cin>>ans;
         }
   infile.seekp((coutn-1)*sizeof(student));
   infile.write((char *)&std,sizeof(student));
   }
}
if(k!=1)
   cout<<"The name doesn't exist ";
else
   cout<<"The name has been successfully modified ";
}
}
else
   cout<<"access denied ";
   getch();
}
void data::delet()
{
char dname[30];
int coutn=0;
int k=0;
if(checkpass()==1)
{
cout<<"\n\nPlease mention the name to be deleted : ";
gets(dname);
fstream infile;
infile.open("tata.Dat",ios::in|ios::out);
infile.seekg(0);
if(infile)
{
while(infile.read((char *)&std,sizeof(student)))
{
   coutn++;
   if(stricmp(std.name,dname)==0)
   {
   k=1;
   strcpy(std.name," ");
   strcpy(std.proff," ");
   strcpy(std.address," ");
   strcpy(std.country," ");
   strcpy(std.tel," ");
   strcpy(std.fax," ");
   strcpy(std.mobile," ");
   strcpy(std.email," ");
   infile.seekp((coutn-1)*sizeof(student));
   infile.write((char *)&std,sizeof(student));
   break;
   }
}
if(k!=1)
   cout<<"The name doesn't exist ";
else
   cout<<"The name has been successfully deleted ";
}
}
else
   cout<<"\n\nAccess Denied ";
getch();
}

void data:: saveData()
{
ofstream outfile;
outfile.open("tata.Dat",ios::app);
outfile.write( (char *)&std,sizeof(student));
}
int data::readData()
{
count=0;
ifstream infile;
infile.open("tata.Dat",ios::app);
if(infile)
{
while(infile.read((char *)&std,sizeof(student)))
{
   if(strcmp(std.name," ")!=0)
   showData(std);
   count++;
}
}
else
cout<<"no file";
return(count);
}
void data::emergency()
{
char emer[30];
int j=0;
cout<<"Please type the name to be searched: ";
gets(emer);
ifstream infile;
infile.open("tata.Dat",ios::nocreate);
while(infile.read((char *)&std,sizeof(student)))
{
if(stricmp(emer,std.proff)==0)
{
j=1;
showData(std);
}
}
if(j==0)
cout<<"Sorry the name doesn't exist";
getch();
}
void data::searchData()
{
j=0;
cout<<"Please type the name to be searched: ";
gets(sname);
ifstream infile;
infile.open("tata.Dat",ios::nocreate);
while(infile.read((char *)&std,sizeof(student)))
{
if(stricmp(sname,std.name)==0)
{
j=1;
showData(std);
}
}
if(j==0)
cout<<"Sorry the name doesn't exist";
}
void data::password()
{
char fre[20];
int pd;
clrscr();
cout<<endl<<endl<<"Password ";
strcpy(fre,takepass());
pd=checkvalidity(fre);
clrscr();
if(pd==1)
cout<<"This password already exist Please try for new password ";
else
{
strcpy(pass,fre);
ofstream passfile;
passfile.open("pass.dat",ios::app);
passfile.write(pass,sizeof(pass));
cout<<"Passwords are sensitive do not lend it ";
}
}
int data::checkvalidity(char fre[])
{
int idm=0;
ifstream passfile;
passfile.open("pass.dat",ios::app);
while(passfile.read(pass,sizeof(pass)))
{
   if(stricmp(fre,pass)==0)
   {
idm=1;
break;
   }
}
return idm;
}


void data::modpass()
{
  char d[20],npass[20];
  clrscr();
  int me=0,in=0;
  cout<<endl<<endl<<"Old Password ";
  strcpy(d,takepass());

  fstream infile;
  infile.open("pass.dat",ios::out|ios::in);
  {
 while(infile.read(pass,sizeof(pass)))
 {
me++;
if(strcmp(d,pass)==0)
{
   in=1;
   cout<<"\nOK the password exist ";
   getch();
clrscr();
cout<<endl<<endl<<"New password ";
   strcpy(pass,takepass());
infile.seekp((me-1)*sizeof(pass));
   infile.write(pass,sizeof(pass));
}
 }
  }
  if(in==0)
   cout<<"\nThe password doesn't exist ";
  else
   cout<<"\nThe password has been successfully modified ";
   getch();
}

int data::checkpass()
{
char da[20];
int z=0,to=0,u=0;
clrscr();
ifstream passfile;
passfile.open("pass.dat",ios::app);
while(to<1&&z!=1)
{
to++;
cout<<endl<<endl<<"Your password ";
strcpy(da,takepass());
passfile.seekg(0);
while(passfile.read(pass,sizeof(pass)))
{
clrscr();
if(strcmp(da,pass)==0)
{
   z=1;
   break;

}
}
}
return z;
}
char* data::takepass()
{
 char ma[20],pa[20];
int q=0,row=30,col=3;
int i=0;
gotoxy(30,3);
while((c=getch())!=ENTER)
{

if(c==BACK)
{
  gotoxy((row-1),col);
  cout<<" ";
  row--;
  i--;
}
else
{
  ma[i]=c;
  i++;
  gotoxy(row,col);
  cout<<"*";
  row++;
}
}
ma[i]='\0';
strcpy(pa,ma);
  clrscr();
return pa;
}
void main()
{
clrscr();//Clearing the screen.
int ch,i,k,a;
char choice,sm[20];
data s;
      srand(time(NULL));
a=1+(rand()%100);
      textcolor(WHITE);
while(1)
{
   clrscr();
   cout<<"Your Choices";
   cout<<"\n1.Enter datas\n2.Read From File\n3.Search data\n4.ModifyData\n5.DeleteData\n6.View Emergency Contacts\t";
   cout<<"\n7.Create New Password\n8.Modify Password\n9.Exit\t";
   cin>>ch;
   switch(ch)
   {
case 1:
cout<<"How many datas do u want to feed " ;
cin>>i;
for(k=0;k<i;k++)
{
   s.getData( );
   s.saveData();
}
break;
case 2:
s.readData();
getch();
break;
case 3:
s.searchData();
getch();
break;
case 4:
s.modify();
break;
case 5:
s.delet();
break;
case 9:
exit(0);
case 7:
cout<<"Please mention Your institution ";
cin>>sm;
if((strcmpi(sm,"spsl")==0)&&(a%4==0))
s.password();
else
if((strcmpi(sm,"spsl")==0)&&(a%4!=0))
{
clrscr();

textcolor(LIGHTRED+BLINK);
      gotoxy(25,10);
cout<<"Sorry the system is busy";
}
else
{
 clrscr();
gotoxy(25,10);
 textcolor(LIGHTRED+BLINK);
 cout<<"\nYOU ARE NOT THE LEGAL PERSON ";
}
 getch();
textcolor(WHITE);
break;
case 8:
s.modpass();
break;
case 6:
s.emergency();
break;
default:
cout<<"\nWrong Choice ";
getch();
   }
}
getch();
}