Quick Print – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
Solved Problem Solved Problem#CPP#7030

Problem Statement - 04C-2019S-C1

Find the output of the following C++ code considering that the binary file STOCK.DAT exist on the hard disk with the following 5 records for the class Stock containing Name and Price .

Name Price
Rice 110
Wheet 60
Cheese 200
Pulses 200
Sauce 150
void main()
{
  fstream FileĀ 
  File.open("STOCK.DAT,ioc::binary|ios::in);
  Stock S;
  for (int I=1; I<=2; I++)
  {
    File.seekg((2*I-1)*sizeof(S));
    File.read((char*)&S, sizeof(S));
    cout<<"Read:"<<File.tellg()/sizeof(S)<<endl;
  }
  File.close();
}

Solution