هذا للقرائة من الملف ... اعتقد نفس اسم الملف الي في البرنامج السابق ..
كود:
#include<iostream.h> #include<fstream.h>
#include<stdlib.h>
void main()
{
struct customer_record
{
int customer_no;
char firstname[10];
char lastname[10];
float weight;
float cost;
};
int n;
ofstream outcust("customer_record.dat",ios::binary);
if(!outcust)
{
cerr<<"file could not be opened"<<endl;
exit(1);
}
customer_record blankcust={0,"","",0.0,0.0};
cout<<"Enter the number of customer_record"<<endl;
cin>>n;
for(int i=0;i<n;i++)
outcust.write(reinterpret_cast<const char *>(& blankcust),sizeof(customer_record));
outcust.seekp(0);
customer_record cust ;
cout<<"Enter customer_record number "<<endl;
cin>>cust.customer_no;
while( cust.customer_no > 0 && cust.customer_no <= n )
{
cout<<"Enter firstname,lastname,weight of car \n";
cin>>cust.firstname>>cust.lastname>>cust.weight;
if(cust.weight > 2000)
cust.cost= 30* cust.weight;
else if(cust.weight > 1500)
cust.cost= 25* cust.weight;
else if( cust.weight > 1000)
cust.cost= 20* cust.weight;
else
cust.cost= 10* cust.weight;
outcust.seekp((cust.customer_no-1)*sizeof(customer_record));
cout<<"Enter customer_record number "<<endl;
cin>>cust.customer_no ;
}
outcust.close();
}