I'm having a problem with retrieving records from my file just started programming over a month a go please help this is for my class project.
I need to do delete,update,query,and add to binary file and prompt the user to enter which record they need to retrieve and i started adding.please if you could give me an example of each i would be very gratefully.my project needs to be submmitted by 28/7/08.
void get_house()
{
cout<<"Please enter the house number(integer data only): ";
cin>>house_number;
cout<<"Please enter the number of rooms(integer data only): ";
cin>>number_of_rooms;
cout<<"Please enter the cost of the house: ";
cin>>cost;
cout<<"Please indicate if the house is furnished(yes,no): ";
cin>>furnished;
}
void show_house()
{
cout<<"house number: "<<house_number<<endl;
cout<<"number of rooms: "<<number_of_rooms<<endl;
cout<<"cost of the house: "<<cost<<endl;
cout<<"Is house the furnished: "<<furnished<<endl;
}
void housewrite()
{
houses h;
ofstream out("house.bin",ios::app);
if(out == NULL)
{
for(int i = 0; i < 15;i++)
{
cout<<"..";
Sleep(200);
}
cout<<"......FILE COULD NOT BE OPENED";
}
else
{
get_house();
out.write((char *)&h,sizeof(h));
out.close();
for(int i = 0; i < 15;i++)
{
cout<<"..";
Sleep(200);
}
cout<<".....FILE WRITTEN SUCESSFULLY";
}
if(in == NULL)
{
for(int i = 0; i < 15; i++)
{
cout<<"..";
Sleep(200);
}
cout<<"..........FILE COULD NOT BE OPENED";
}
else
{
do
{
cout<<"ENTER HOUSE NUMBER: ";
cin>>house_temp;
int seekpos =((house_temp-1)*sizeof(h));
in.seekg(seekpos);
in.read((char *)&h,sizeof(h));
if(house_temp == h.house_number)
{
h.show_house();
break;
}
else
{
cout<<"HOUSE NUMBER DOES NOT EXIST.......";
break;
}
}while(!in.eof());
}in.close();
}
};
int main()
{
houses obj;
obj.housewrite();
getch();
system("cls");
obj.display_house();