Quote:
C++ project...display not working(runtime error)
When asking for help, it is generally considered a good idea to tell what is the error and its position.
Quote:
when I try to display it does not give the desired output..
And what is the desired output ?
Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<stdlib.h>
#include<string.h>
class hospappt
{
char uname[20];
int idno;
int age;
int pno;
int id;
int dp;
int hospid;
char hospname[50];
char email[30];
char dpt[30];
char gender;
char docname[50];
public:
void admin();
void user();
void insert();
void Delete();
void display();
void dept();
};
void hospappt::admin()
{
clrscr();
int c;
char ch;
do
{
cout<<"\n\t\t****ADMIN MENU****";
cout<<"\n\t\t1. INSERT INFORMATION";
cout<<"\n\t\t2. DISPLAY INFORMATION";
cout<<"\n\t\t3. DELETE INFORMATION";
cout<<"\n\t\t4.RETURN TO MAIN";
cout<<"\n\t\tPLEASE ENTER YOUR CHOICE: ";
cin>>c;
switch(c)
{
case 1:
insert();
break;
case 2:
display();
break;
case 3:
Delete();
break;
case 4:
return;
default:
cout<<"\n\t\tWRONG OPTION!!!!!";
return;
}
cout<<"\n\tDO YOU WANT TO CONTINUE WITH ADMIN MODE?(Y\N)";
cin>>ch;
}while(ch=='Y'||ch=='y');
}
void hospappt::insert()
{
clrscr();
int n,i;
hospappt h;
ofstream d;
d.open("doct.dat",ios::app|ios::binary);
cout<<"\nENTER NUMBER OF DOCTORS YOU WOULD LIKE TO ADD:";
cin>>n;
for(i=0;i<n;++i)
{
cout<<"\n\t\tPLEASE ENTER THE FOLLOWING DETAILS";
cout<<"\n\t\tHOSPITAL ID: ";
cin>>hospid;
cout<<"\n\t\tHOSPITAL NAME: ";
gets(hospname);
cout<<"\n\t\tDEPARTMENT: ";
gets(dpt);
cout<<"\n\t\tNAME OF DOCTOR: ";
gets(docname);
d.write((char*)&h,sizeof(h));
cout<<"\n\t\t!!!!!RECORD SUCCESSFULLY INSERTED!!!!!";
}
d.close();
return;
}
void hospappt::display()
{
hospappt h;
int id;
char dep[30];
ifstream fin;
fin.open("doct.dat",ios::app|ios::binary);
cout<<"ENTER ID NUMBER:";
cin>>id;
cout<<"ENTER DEPARTMENT:";
gets(dep);
while(fin.read((char*)&h,sizeof(h)))
{
if(id==hospid)
{
if(strcmpi(dpt,dep))
{
cout<<"HOSPITAL NAME: "<<hospname;
cout<<"DEPARTMENT : "<<dpt;
cout<<"DOCTOR : "<<docname;
}
}
else
{
cout<<"HOSPITAL NOT FOUND!!!";
return;
}
}
fin.close();
return;
}
void hospappt::dept()
{
clrscr();
cout<<"\n\t\t*****DEPARTMENT*******";
cout<<"\n\t1. GENERAL MEDICINE";
cout<<"\n\t2. CARDIOLOGY";
cout<<"\n\t3. ENT";
cout<<"\n\t4. GASTROENTEROLOGY";
cout<<"\n\t5. GYNAECOLOGY";
cout<<"\n\t6. PEDIATRICIAN";
cout<<"\n\t7. NEUROLOGY";
cout<<"\n\t8. ONCOLOGY";
cout<<"\n\t9. OPTHALMOLOGY";
cout<<"\n\t10.ORTHOPAEDICS";
cout<<"\n\t PLEASE ENTER YOUR OPTION:";
cin>>dp;
return;
}
void hospappt::Delete()
{
return;
}
void main()
{
hospappt h;
h.admin();
cout<<"SMILE";
getch();
return;
}
Indentation style - Wikipedia[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]