#include <fstream> //for file streams
#include <iostream>
using std::fstream;
#include <cstdlib>

using namespace std;
////////////////////////////////////////////////////////////////

class person //class of persons
{
  protected:
    char name[80]; //person’s name
    int age; //person’s age
  public:
    void getData() //get person’s data
    {
      cout << "\n Enter name: "; cin >> name;
      cout << " Enter age: "; cin >> age;
    }
    void showData() //display person’s data
    {
      cout << "\n Name: " << name;
      cout << "\n Age: " << age;
    }
};
int diskCount(){
   
  ifstream infile;
  infile.open("group.dat", ios::in | ios::binary);
  infile.seekg(0, ios::end); //go to 0 bytes from end
  int n = (int)infile.tellg() / sizeof(person); 
  infile.close();
  //calculate number of persons
  return n;
}

main()
{
  person pers; //create person object
  ofstream outfile; //create input file
  outfile.open("group.dat", ios::out | ios::binary); //open file
  int n = diskCount();
  cout << "\nThere are " << n << " persons in file";
  if(n>0){
  cout << "Enter which record to modify ";
  cin >> n;
  pers.getData();
  int position = (n-1) * sizeof(person); //number times size
  outfile.seekp(position); //bytes from start
  outfile.write( reinterpret_cast<char*>(&pers), sizeof(pers) );
}
  cout << endl;
  system("pause");
}
