Deepika13 0 Newbie Poster

I have made a minor program. My program doesn't modify and I want to add a person at begining with emergency function.
please help me out where i m lacking.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
#include<string.h>
#include<stdio.h>

class hospital
{
 char name[20];
 int age;
 int i;
	 public:
	 hospital()
	 {
	  i = 0;
	 }
 void getdata();
 void putdata();
 void modify();
void emergency();
 void menu();
}h[100];

char ch;

void hospital::getdata()
{
 clrscr();
 ch = 'Y';
 while(ch == 'Y')
 {
  cout<<"Enter Name";
  cin>>name;
  cout<<"Enter Age";
  cin>>age;
  /*if(islower(d[i].name))
  d[i].name=toupper(d[i].name); */
  i++;
  cout<<"\n\n\tPatient Added.\n\n";
  cout<<"\tPatient ID is " <<i<<"\n\n";
  cout<<"\tAdd another record (y/n)";
  cin>>ch;
  if(islower(ch))
  {
  ch = toupper(ch);
  }
 }
}
void hospital::putdata()
{
 clrscr();
 cout<<"\n\nDetail of Patient : "<<i;
 cout<<"\n\tName : "<<name;
 cout<<"\n\tAge  : "<<age;
 getch();

}

void hospital:: modify()
{
 clrscr();
  char nm[20];
  int age1;
  cout<<"\nEnter New Details";
  cout<<"\n\tEnter Name";
  cin>>nm;
  cout<<"\n\tEnter Age";
  cin>>age1;
  if(strlen(nm)!=0)
  strcpy(name,nm);
  if(age1>age||age1<age)
  age=age1;
}

/*void hospital:: emergency()
{
  if(i>=100)
{
 cout<<"Hospital is full";
}

for(int j = i - 1;j>=0;j-- )
{
 h[j+1] = h[j];
}
h[0] = 
i++;
}*/

void hospital :: menu()
{
 clrscr();
 int temp = 0,offset = 0;
 fstream file;
 file.open("Hospi",ios::in|ios::out|ios::binary);
 int choice;
 cout<<"1. Enter Data \n";
 cout<<"2. Modify Data \n";
 cout<<"3. View Data\n";
 cout<<"4. Emergency\n";
 cout<<"5. Exit"
 cout<<"\n\n\tEnter Your Choice : ";
cin>>choice;
switch(choice)
{
 case 1 :
 clrscr();
 h.getdata();
 temp = i;
 offset = (temp - 1)*sizeof(hospital);
 file.seekp(offset,ios::beg);
 file.write((char *)&h,sizeof(hospital));
 h.menu();
 break;

 case 2:
 clrscr();
 if(!i)
 {
  cout<<"No Record";
  getch();
  h.menu();
  break;
 }
 cout<<"RECORD TO BE MODIFIED : ";
 cin>>temp;
 if(temp>i)
 {
  cout<<"Only"<<i<<"records are added.\n";
  h.menu();
  getch();
  break;
 }
 else
 {
  offset = (temp - 1)*sizeof(hospital);
  file.seekp(offset,ios::beg);
  file.read((char *)&h,sizeof(hospital));
  h.putdata();
  cout<<"Do you want to modify?(y/n)";
  cin>> ch;
  if(islower(ch))
  {
  ch = toupper(ch);
  }
   if(ch == 'Y')
 {
    h.modify();
    file.seekp(offset,ios::beg);
    file.write((char *)&h,sizeof(hospital));
cout<<"Modified";
    getch();
 }
break;
}

 case 3:
 clrscr();
 if(!i)
 {
  cout<<"No Record";
  getch();
  h.menu();
  break;
 }
 cout<<"RECORD : ";
 cin>>temp;
 if(temp>i)
 {
  cout<<"Only"<<i<<"records are added.\n";
  getch();
  h.menu();
  break;
 }
 else
 {
  offset = (temp - 1)*sizeof(hospital);
  file.seekp(offset,ios::beg);
  file.read((char *)&h,sizeof(hospital));
  h.putdata();
  getch();
 }
 h.menu();
 break;


case 4:
h.emergency();
break;
 
case 5:
break;

default:
 cout<<"Enter valid option" ;
 break;
}
file.close();
}
void main()
{
clrscr();
h.menu();

getch();
}
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.