#include #include //myostream_RandomAccess.cpp using namespace std; const int narray1=10 ; class Emp { public: char name[20]; double Sal; void RandomDisplay() ; }; void Emp::RandomDisplay() {cout <<"\n E-Name "<< name << " E-Sal $" << Sal << endl;} int main() { Emp e1[narray1]; char repeat; int i; // ofstream fout("empdata6.dat", ios_base::binary); if (fout.is_open()) { cerr << "File activated to Write." << endl; } strcpy(e1[1].name,"Harry Smith"); e1[1].Sal =4500.00; // strcpy(e1[2].name,"Brian Lopez"); e1[2].Sal = 4200.00; // strcpy(e1[5].name,"Rowdy Hyde"); e1[5].Sal =3500.59; fout.write(reinterpret_cast (e1), narray1 * sizeof(Emp)); fout.close(); // Emp empindex; ifstream ifs("empdata6.dat", ios_base::binary); do{ cout<<"\n Enter emp lid 1-9 : 0 to quit >> " ; cin>>i; if(i==0){exit(1);} if(i){ ifs.seekg(i * sizeof(Emp), ios::beg); //required to read the contents ifs.read(reinterpret_cast(&empindex),sizeof(Emp)); empindex.RandomDisplay(); cout<<"\n done : do you want more : "; cin>>repeat; } }while(repeat=='y'|| repeat=='Y'); ifs.close(); return 0; }