Sunday, 1 December 2013

Play Sound C++ Program

#include <iostream>
#include <windows.h>
using namespace std;
//twinkle twinkle
//CC GG AA G
//FF EE DD C
//GG FF EE D
//GG FF EE D
//CC GG AA G
//FF EE DD C
void playnote (char g, float l)
{
char n = g;
if (n == 'A'||'a'){
Beep(2750,l*1000);
cout <<n;
}
else if(n == 'B'||'b'){
Beep(3087,l*1000);
cout << n;
}
else if(n == 'C'||'c'){
Beep(1637,l*1000);
cout << n;
}
else if(n == 'D'||'d'){
Beep(1835,l*1000);
cout << n;
}
else if(n == 'E'||'e'){
Beep(2060,l*1000);
cout << n;
}
else if(n == 'F'||'f'){
Beep(2183,l*1000);
cout << n;
}
else if(n == 'G'||'g'){
Beep(2450,l*1000);
cout << n;
}
}
int main() {
playnote('C', 0.4);
playnote('C', 0.4);
playnote('G', 0.4);
playnote('G', 0.4);
playnote('A', 0.4);
playnote('A', 0.4);
playnote('G', 0.4);
Sleep(400);
cout<<endl;
playnote('F', 0.4);
playnote('F', 0.4);
playnote('E', 0.4);
playnote('E', 0.4);
playnote('D', 0.4);
playnote('D', 0.4);
playnote('C', 0.4);
Sleep(400);
cout<<endl;
playnote('G', 0.4);
playnote('G', 0.4);
playnote('F', 0.4);
playnote('F', 0.4);
playnote('E', 0.4);
playnote('D', 0.4);
playnote('G', 0.4);
Sleep(400);
cout<<endl;
playnote('G', 0.4);
playnote('F', 0.4);
playnote('F', 0.4);
playnote('E', 0.4);
playnote('D', 0.4);
playnote('C', 0.4);
playnote('C', 0.4);
Sleep(400);
cout<<endl;
playnote('G', 0.4);
playnote('G', 0.4);
playnote('A', 0.4);
playnote('A', 0.4);
playnote('G', 0.4);
playnote('F', 0.4);
playnote('F', 0.4);
Sleep(400);
cout<<endl;
playnote('E', 0.4);
playnote('E', 0.4);
playnote('D', 0.4);
playnote('D', 0.4);
playnote('C', 0.4);
cout<<endl;
cout << "thanks for listening <3";
return 0;

Saturday, 30 November 2013

Program for Heap Sort Method in C language

This is a simple program for heap sort. Its performance is O(n log(n)).   Heap sort :
The heapsort algorithm can be divided into two parts.
In the first step, a heap is built out of the data.
In the second step, a sorted array is created by repeatedly removing the largest element from the heap, and inserting it into the array. The heap is reconstructed after each removal. Once all objects have been removed from the heap, we have a sorted array. The direction of the sorted elements can be varied by choosing a min-heap or max-heap in step one.
Heapsort can be performed in place. The array can be split into two parts, the sorted array and the heap. The heap's invariant is preserved after each extraction, so the only cost is that of extraction.
Major functions : 
                         heapify : This function establishes the heap property by building a heap from the bottom up,                                        successively shifting downward.
                         heapsort : This function sorts the heap by calling heapify to maintain heap property.
#include<stdio.h>
 
void heapify(int a[],int i,int n)
{
int largest;
int left=(2*i)+1;
int right=(2*i)+2;
if(left<n && a[left]>a[i])
{
largest=left;
}
else
{
largest=i;
}
if(right<n && a[right]>a[largest])
{
largest=right;
}
if(largest!=i)
{
int temp=a[i];
a[i]=a[largest];
a[largest]=temp;
heapify(a,largest,n);
}
}
 
void hsort(int a[],int n)
{
int i;
for(i=n-1;i>=1;i--)
{
int temp=a[i];
a[i]=a[0];
a[0]=temp;
n=n-1;
heapify(a,0,n);
}
}
 
void main()
{
int i;
printf("Enter n ");
int n;
scanf("%d",&n);
int a[n];
printf("Enter elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Before heapification\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
printf(" ");
for(i=(n-1)/2;i>=0;i--)
{
heapify(a,i,n);
}
printf("\nAfter heapification\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
hsort(a,n);
printf("\nAfter heap sort\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
printf(" ");
}

Simple loading code :)

#include<iostream.h>
#include<unistd.h>

using namespace std;

main()
{
int i;
for(i=0;i<=10000;i++)
{
cout<<"Loading......."<<i<<"%\r";

}

return 0;
}

TIC TAC TOE PROGRAM in C++

// TIC TAC TOE PROGRAM

#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <ctime>
using namespace std;

//Winning info
struct win
{
    int Mini; // That equals 10 * row value + column value
    int Maxi; // The maximum value that you need to collect from Mini to win
    int a;
};

char board[3][3];
int turns;
win victory[2][8];
// Vitory[2] cuz there are 2 players and [8] cuz there are 8 ways to win in the board
/* counter function calculates your chance to win for example  :
if I player at the first block wich is ( 0 rows , 0 column ) this will increase the first way to win by 0 from 3 and if you played ( 0 , 1 ) it will be 1 out of 33 and if you played the last one you'll be 1 out of 1 so you won ... get it ?
*/
void counter(int x , int a , int b)
{
    victory[x][a].Mini += 10*a + b ;
    victory[x][b+3].Mini += 10*a + b ;
    victory[x][a].a ++ ;
    victory[x][b+3].a ++ ;
    if( a == b )
    {
        victory[x][6].Mini += 10*a + b ;
        victory[x][6].a ++ ;
    }
    if( a + b == 2 )
    {
        victory[x][7].Mini += 10*a + b ;
        victory[x][7].a ++ ;
    }
}
// This function do check if your input is right or not and if it's right it replaces the space by X or O depends on the player
bool check(int a , int b , int x , bool n )
{
    if ( board[a][b]!= ' '  )
        return false;
    else
    {
        if ( n == true )
        {
            counter ( x , a , b );
            if(x==0)
                board[a][b]='X';
            else
                board[a][b]='O';
        }
        return true;
    }
}
// AI intelligence
void computer()
{
    int a = 0 ,  b = 0 , f ;
    // Attack , Defence
    for(int i = 1 ; i>=0 ; i--)

        for(int j=0 ; j<=7 ; j++)

            if( victory[i][j].a == 2 )

                if ( check( (( victory[i][j].Maxi - victory[i][j].Mini ) / 10 ) , ( ( victory[i][j].Maxi - victory[i][j].Mini ) % 10 ) , 1 , true ) == true )
                    return;

    // Play strategy :D

    while ( true )
    {
        f = rand() % 4 + 1;
        if ( f == 1 )
        {
            while(true)
            {
                a = rand() % 3 ;
                b = rand() % 3 ;
                if(check(a,b,1,true)==true)
                {
                    return;
                }

            }
        }
        else if ( check (0,0,1,false) == true || check(1,1,1,false) == true || check(2,2,1,false) == true || check(2,0,1,false) == true || check(0,2,1,false) == true )
        {
            while (true)
            {
                f = rand() % 5  ;
                if( f<=2 )
                {
                    b = a = f;
                    if(check(a,b,1,true)==true)
                    {
                        return;
                    }
                }
                else if ( f == 3)
                {
                    a=0;
                    b=2;
                    if(check(a,b,1,true)==true)
                    {
                        return;
                    }
                }
                else if ( f == 4 )
                {
                    a=2;
                    b=0;
                    if(check(a,b,1,true)==true)
                    {
                        return;
                    }
                }
            }
        }
    }

}
// cleans every thing
void cleaner()
{
    for (int i = 0; i <= 1; i++)
    {

        for (int j = 0; j <= 7; j++)
        {
            victory[i][j].Mini = 0;
            victory[i][j].a    = 0;
        }
    }
    turns = 0;
    for(int i=0; i<=2; i++)
        for(int j=0; j<=2; j++)
            board[i][j]=' ';
}
// to write table and actually i can't explain it :D
void Table()
{
    system("cls");
    cout<<endl<<"TIC TAC TOE :) "<<endl<<endl;

    for (int rows = 0; rows <= 12; rows++)
    {

        if( rows  % 4 == 0)
            cout<<string(25,'-')<<"       " <<string(25,'-');
        else
        {
            for(int j=0; j<=3; j++)
            {
                if( (rows==2 || rows==6 || rows==10) && j!=3 )
                    cout<<"|   "<< board [ (rows-2) /4  ] [j]<<"   ";
                else
                    cout<<"|       ";
            }
            for(int j=0; j<=3; j++)
            {
                if( (rows==2 || rows==6 || rows==10) && j!=3 )
                    cout<<"|   "<< ( (3*rows-2) + (4*j) ) /4 <<"   ";
                else
                    cout<<"|       ";
            }
        }

        cout<<endl;
    }
}
// asks you to enter where you want to play
void InputCheck(int ys , int wf)
{
    int a , b ;
    if ( ys == 1 || wf == 0  )
    {
        string tempp="";
        while(true)
        {
            cout<<endl<<"Where would you like to play :) ? "<<endl<<endl;

            while (true)
            {
                cin>>tempp;
                if(tempp != "1" && tempp != "2" && tempp !="3" && tempp != "4" && tempp != "5" && tempp != "6" && tempp != "7" && tempp != "8" && tempp != "9")
                    cout<<"              ERROR"<<endl;
                else
                    break;
            }

            int temp;
            temp = atoi(&tempp[0]);
            if( temp <= 3  )
            {
                a=0;
                b=temp-1;
            }
            else if ( temp >= 4 && temp <= 6  )
            {
                a = 1 ;
                b = temp - 4 ;
            }
            else if ( temp >= 7 && temp <= 9 )
            {
                a = 2 ;
                b = temp - 7 ;
            }
            if (check(a,b,wf,true) == true )
            {
                return;
            }
            else
                cout<<"Already Entered";
        }
    }
    computer();
    return;
}
// checks if someone won
void WhoWins()
{
    bool c=false;

    //Player 1
    for (int i  =0; i <= 7; i++)
    {

        if(victory[0][i].a==3)
        {
            cout<<"Player 1 WON ";
            c=true;
        }
    }

    //Player 2
    for (int i = 0; i <= 7; i++)
    {

        if(victory[1][i].a==3)
        {
            cout<<"Player 2 WON " ;
            c=true;
        }
    }

    //Noone won
    if ( turns == 9 && c == false )
    {
        cout<<"Nobody WON !! " ;
        c=true;
    }

    if(c == true)
    {
        getch();
        cleaner();
        Table();
        return;
    }

}

int main()
{
    srand( time( NULL ) );
    string temp = " ";
    int yc; //Your Choice
    int wf; // Who First

    cout<<endl<<"      1 - Multiplayer "<<endl<<"      2 - Single Player " <<endl<<endl<<"      " ;

    cin >> temp;
    while (temp != "1" && temp != "2" )
    {
        cout<<"          ERROR "<<endl<<"      ";
        cin >> temp;
    }
    yc=atoi(&temp[0]);
    temp = " ";
    system("cls");

    cout<<endl<<"      1 - Player 1 first 'X' "<<endl<<"      2 - Player 2 first (or computer) 'O'"<<endl<<endl<<"      ";

    cin >> temp;
    while (temp != "1" && temp != "2" )
    {
        cout<<"          ERROR "<<endl<<"      ";
        cin >> temp;
    }

    wf=atoi(&temp[0]) - 1;

    for (int i = 0; i <= 1; i++)
    {
        victory[i][0].Maxi = 3; // first way to win play (0.0)(0,1)(0,2)
        victory[i][1].Maxi = 33; // second way to win play (1.0)(1.1)(1.3)
        victory[i][2].Maxi = 63; // and so on
        victory[i][3].Maxi = 30;
        victory[i][4].Maxi = 33;
        victory[i][5].Maxi = 36;
        victory[i][6].Maxi = 33;
        victory[i][7].Maxi = 33;
    }
    cleaner();
    for (turns = 0 ;; turns ++)
    {
        Table();
        WhoWins();
        InputCheck(yc , wf);
        wf=1-wf;
    }
}

#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <ctime>
using namespace std;

//Winning info
struct win
{
    int Mini; // That equals 10 * row value + column value
    int Maxi; // The maximum value that you need to collect from Mini to win
    int a;
};

char board[3][3];
int turns;
win victory[2][8];
// Vitory[2] cuz there are 2 players and [8] cuz there are 8 ways to win in the board
/* counter function calculates your chance to win for example  :
if I player at the first block wich is ( 0 rows , 0 column ) this will increase the first way to win by 0 from 3 and if you played ( 0 , 1 ) it will be 1 out of 33 and if you played the last one you'll be 1 out of 1 so you won ... get it ?
*/
void counter(int x , int a , int b)
{
    victory[x][a].Mini += 10*a + b ;
    victory[x][b+3].Mini += 10*a + b ;
    victory[x][a].a ++ ;
    victory[x][b+3].a ++ ;
    if( a == b )
    {
        victory[x][6].Mini += 10*a + b ;
        victory[x][6].a ++ ;
    }
    if( a + b == 2 )
    {
        victory[x][7].Mini += 10*a + b ;
        victory[x][7].a ++ ;
    }
}
// This function do check if your input is right or not and if it's right it replaces the space by X or O depends on the player
bool check(int a , int b , int x , bool n )
{
    if ( board[a][b]!= ' '  )
        return false;
    else
    {
        if ( n == true )
        {
            counter ( x , a , b );
            if(x==0)
                board[a][b]='X';
            else
                board[a][b]='O';
        }
        return true;
    }
}
// AI intelligence
void computer()
{
    int a = 0 ,  b = 0 , f ;
    // Attack , Defence
    for(int i = 1 ; i>=0 ; i--)

        for(int j=0 ; j<=7 ; j++)

            if( victory[i][j].a == 2 )

                if ( check( (( victory[i][j].Maxi - victory[i][j].Mini ) / 10 ) , ( ( victory[i][j].Maxi - victory[i][j].Mini ) % 10 ) , 1 , true ) == true )
                    return;

    // Play strategy :D

    while ( true )
    {
        f = rand() % 4 + 1;
        if ( f == 1 )
        {
            while(true)
            {
                a = rand() % 3 ;
                b = rand() % 3 ;
                if(check(a,b,1,true)==true)
                {
                    return;
                }

            }
        }
        else if ( check (0,0,1,false) == true || check(1,1,1,false) == true || check(2,2,1,false) == true || check(2,0,1,false) == true || check(0,2,1,false) == true )
        {
            while (true)
            {
                f = rand() % 5  ;
                if( f<=2 )
                {
                    b = a = f;
                    if(check(a,b,1,true)==true)
                    {
                        return;
                    }
                }
                else if ( f == 3)
                {
                    a=0;
                    b=2;
                    if(check(a,b,1,true)==true)
                    {
                        return;
                    }
                }
                else if ( f == 4 )
                {
                    a=2;
                    b=0;
                    if(check(a,b,1,true)==true)
                    {
                        return;
                    }
                }
            }
        }
    }

}
// cleans every thing
void cleaner()
{
    for (int i = 0; i <= 1; i++)
    {

        for (int j = 0; j <= 7; j++)
        {
            victory[i][j].Mini = 0;
            victory[i][j].a    = 0;
        }
    }
    turns = 0;
    for(int i=0; i<=2; i++)
        for(int j=0; j<=2; j++)
            board[i][j]=' ';
}
// to write table and actually i can't explain it :D
void Table()
{
    system("cls");
    cout<<endl<<"TIC TAC TOE :) "<<endl<<endl;

    for (int rows = 0; rows <= 12; rows++)
    {

        if( rows  % 4 == 0)
            cout<<string(25,'-')<<"       " <<string(25,'-');
        else
        {
            for(int j=0; j<=3; j++)
            {
                if( (rows==2 || rows==6 || rows==10) && j!=3 )
                    cout<<"|   "<< board [ (rows-2) /4  ] [j]<<"   ";
                else
                    cout<<"|       ";
            }
            for(int j=0; j<=3; j++)
            {
                if( (rows==2 || rows==6 || rows==10) && j!=3 )
                    cout<<"|   "<< ( (3*rows-2) + (4*j) ) /4 <<"   ";
                else
                    cout<<"|       ";
            }
        }

        cout<<endl;
    }
}
// asks you to enter where you want to play
void InputCheck(int ys , int wf)
{
    int a , b ;
    if ( ys == 1 || wf == 0  )
    {
        string tempp="";
        while(true)
        {
            cout<<endl<<"Where would you like to play :) ? "<<endl<<endl;

            while (true)
            {
                cin>>tempp;
                if(tempp != "1" && tempp != "2" && tempp !="3" && tempp != "4" && tempp != "5" && tempp != "6" && tempp != "7" && tempp != "8" && tempp != "9")
                    cout<<"              ERROR"<<endl;
                else
                    break;
            }

            int temp;
            temp = atoi(&tempp[0]);
            if( temp <= 3  )
            {
                a=0;
                b=temp-1;
            }
            else if ( temp >= 4 && temp <= 6  )
            {
                a = 1 ;
                b = temp - 4 ;
            }
            else if ( temp >= 7 && temp <= 9 )
            {
                a = 2 ;
                b = temp - 7 ;
            }
            if (check(a,b,wf,true) == true )
            {
                return;
            }
            else
                cout<<"Already Entered";
        }
    }
    computer();
    return;
}
// checks if someone won
void WhoWins()
{
    bool c=false;

    //Player 1
    for (int i  =0; i <= 7; i++)
    {

        if(victory[0][i].a==3)
        {
            cout<<"Player 1 WON ";
            c=true;
        }
    }

    //Player 2
    for (int i = 0; i <= 7; i++)
    {

        if(victory[1][i].a==3)
        {
            cout<<"Player 2 WON " ;
            c=true;
        }
    }

    //Noone won
    if ( turns == 9 && c == false )
    {
        cout<<"Nobody WON !! " ;
        c=true;
    }

    if(c == true)
    {
        getch();
        cleaner();
        Table();
        return;
    }

}

int main()
{
    srand( time( NULL ) );
    string temp = " ";
    int yc; //Your Choice
    int wf; // Who First

    cout<<endl<<"      1 - Multiplayer "<<endl<<"      2 - Single Player " <<endl<<endl<<"      " ;

    cin >> temp;
    while (temp != "1" && temp != "2" )
    {
        cout<<"          ERROR "<<endl<<"      ";
        cin >> temp;
    }
    yc=atoi(&temp[0]);
    temp = " ";
    system("cls");

    cout<<endl<<"      1 - Player 1 first 'X' "<<endl<<"      2 - Player 2 first (or computer) 'O'"<<endl<<endl<<"      ";

    cin >> temp;
    while (temp != "1" && temp != "2" )
    {
        cout<<"          ERROR "<<endl<<"      ";
        cin >> temp;
    }

    wf=atoi(&temp[0]) - 1;

    for (int i = 0; i <= 1; i++)
    {
        victory[i][0].Maxi = 3; // first way to win play (0.0)(0,1)(0,2)
        victory[i][1].Maxi = 33; // second way to win play (1.0)(1.1)(1.3)
        victory[i][2].Maxi = 63; // and so on
        victory[i][3].Maxi = 30;
        victory[i][4].Maxi = 33;
        victory[i][5].Maxi = 36;
        victory[i][6].Maxi = 33;
        victory[i][7].Maxi = 33;
    }
    cleaner();
    for (turns = 0 ;; turns ++)
    {
        Table();
        WhoWins();
        InputCheck(yc , wf);
        wf=1-wf;
    }
}

Hotel Manahement Project in C++

NOTE: For education purpose only....

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<dos.h>

class hotel
{
int room_no;
char name[30];
char address[50];
char phone[10];

  public:
void main_menu(); //to dispay the main menu
void add();        //to book a room
void display();        //to display the customer record
void rooms(); //to display alloted rooms
void edit();        //to edit the customer record
int check(int); //to check room status
void modify(int);        //to modify the record
void delete_rec(int); //to delete the record
};

void hotel::main_menu()
{
int choice;
while(choice!=5)
{

cout<<"\n\t\t\t\t*************";
cout<<"\n\t\t\t\t* MAIN MENU *";
cout<<"\n\t\t\t\t*************";
cout<<"\n\n\n\t\t\t1.Book A Room";
cout<<"\n\t\t\t2.Customer Record";
cout<<"\n\t\t\t3.Rooms Allotted";
cout<<"\n\t\t\t4.Edit Record";
cout<<"\n\t\t\t5.Exit";
cout<<"\n\n\t\t\tEnter Your Choice: ";
cin>>choice;

  switch(choice)
{
case 1: add();
break;
case 2: display();
break;
case 3: rooms();
break;
case 4: edit();
break;
case 5: break;
default:
{
cout<<"\n\n\t\t\tWrong choice.....!!!";
cout<<"\n\t\t\tPress any key to continue....!!";
getch();
}
}
}
}

void hotel::add()
{

int r,flag;
ofstream fout("Record.dat",ios::app);

  cout<<"\n Enter Customer Detalis";
cout<<"\n ----------------------";
cout<<"\n\n Room no: ";
cin>>r;
flag=check(r);

  if(flag)
cout<<"\n Sorry..!!!Room is already booked";

  else
{
room_no=r;
cout<<" Name: ";
gets(name);
cout<<" Address: ";
gets(address);
cout<<" Phone No: ";
gets(phone);
fout.write((char*)this,sizeof(hotel));
cout<<"\n Room is booked...!!!";
}

  cout<<"\n Press any key to continue.....!!";
getch();
fout.close();
}

void hotel::display()
{

ifstream fin("Record.dat",ios::in);
int r,flag;
cout<<"\n Enter room no: ";
cin>>r;

  while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
{

cout<<"\n Cusromer Details";
cout<<"\n ----------------";
cout<<"\n\n Room no: "<<room_no;
cout<<"\n Name: "<<name;
cout<<"\n Address: "<<address;
cout<<"\n Phone no: "<<phone;
flag=1;
break;
}
}

  if(flag==0)
cout<<"\n Sorry Room no. not found or vacant....!!";

  cout<<"\n\n Press any key to continue....!!";
getch();
fin.close();

}


void hotel::rooms()
{

ifstream fin("Record.dat",ios::in);
cout<<"\n\t\t\t    List Of Rooms Allotted";
cout<<"\n\t\t\t    ----------------------";
cout<<"\n\n Room No.\tName\t\tAddress\t\t\t\tPhone No.\n";

  while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
cout<<"\n\n "<<room_no<<"\t\t"<<name;
cout<<"\t\t"<<address<<"\t\t"<<phone;
}
cout<<"\n\n\n\t\t\tPress any key to continue.....!!";
getch();
fin.close();
}

void hotel::edit()
{

int choice,r;

  cout<<"\n EDIT MENU";
cout<<"\n ---------";
cout<<"\n\n 1.Modify Customer Record";
cout<<"\n 2.Delete Customer Record";

  cout<<"\n Enter your choice: ";
cin>>choice;

cout<<"\n Enter room no: " ;
cin>>r;

  switch(choice)
{
case 1: modify(r);
break;
case 2: delete_rec(r);
break;
default: cout<<"\n Wrong Choice.....!!";
}
cout<<"\n Press any key to continue....!!!";
getch();
}


int hotel::check(int r)
{
int flag=0;
ifstream fin("Record.dat",ios::in);
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
{
flag=1;
break;
}
}

  fin.close();
return(flag);
}


void hotel::modify(int r)
{
long pos,flag=0;
fstream file("Record.dat",ios::in|ios::out|ios::binary);
while(!file.eof())
{
pos=file.tellg();
file.read((char*)this,sizeof(hotel));
if(room_no==r)
{
cout<<"\n Enter New Details";
cout<<"\n -----------------";
cout<<"\n Name: ";
gets(name);
cout<<" Address: ";
gets(address);
cout<<" Phone no: ";
gets(phone);

  file.seekg(pos);
file.write((char*)this,sizeof(hotel));
cout<<"\n Record is modified....!!";
flag=1;
break;
  }
}

  if(flag==0)
cout<<"\n Sorry Room no. not found or vacant...!!";
file.close();
}

void hotel::delete_rec(int r)
{
int flag=0;
char ch;
ifstream fin("Record.dat",ios::in);
ofstream fout("temp.dat",ios::out);
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
{
cout<<"\n Name: "<<name;
cout<<"\n Address: "<<address;
cout<<"\n Pone No: "<<phone;
cout<<"\n\n Do you want to delete this record(y/n): ";
cin>>ch;

  if(ch=='n')
fout.write((char*)this,sizeof(hotel));
flag=1;
}
else
fout.write((char*)this,sizeof(hotel));
}

  fin.close();
fout.close();
if(flag==0)
cout<<"\n Sorry room no. not found or vacant...!!";
else
{
remove("Record.dat");
rename("temp.dat","Record.dat");
}
}


main()
  {
hotel h;


 
cout<<"\n\t\t\t****************************";
cout<<"\n\t\t\t* HOTEL MANAGEMENT PROJECT *";
cout<<"\n\t\t\t****************************";


  cout<<"\n\n\n\n\t\tMade By:";

cout<<"\tThe Crazy Programmer";



cout<<"\n\n\n\n\n\n\n\t\t\t\t\tPress any key to continue....!!";
getch();
h.main_menu();
}