#include #include #include using std::cin; using std::cout; using std::ofstream; using std::ifstream; using std::fstream; using std::ios; struct record { int idno; char name[10]; char surname[15]; float gpa; }; typedef struct record Record; void main() { fstream datafile("C:/Temp/Student.dat", ios::in|ios::out|ios::binary); Record rec={0,"","",0.0}; int number; cout << "Enter ID Number : "; cin >> number; //Move the Read/Write head datafile.seekg((number - 100) * sizeof(Record)); //Read from the RAF where the Read/Write head has been positioned datafile.read(reinterpret_cast (&rec), sizeof(Record)); cout << rec.idno <<"\t" << rec.name <<"\t" << rec.surname <<"\t" << rec.gpa <<"\n"; //Prompt the user to rename the Surname cout << "Enter new Surname : "; cin >> rec.surname; //Move the Read/Write head datafile.seekp((number - 100) * sizeof(Record)); //Read from the RAF where the Read/Write head has been positioned datafile.write(reinterpret_cast (&rec), sizeof(Record)); datafile.close(); getch(); } /* void main() { ofstream outfile("C:/Temp/Student.dat", ios::binary); ifstream infile("C:/Temp/Student.txt"); Record rec; //Get data from the keyboard and insert into outfile while (infile >> rec.idno >> rec.name >> rec.surname >> rec.gpa) { //Move the Read/Write head outfile.seekp((rec.idno - 100) * sizeof(Record)); //Write to the RAF outfile.write(reinterpret_cast (&rec), sizeof(Record)); } outfile.close(); infile.close(); getch(); } */ /* void main() { ifstream infile("C:/Temp/Student.dat", ios::binary); Record rec; //Get data from the keyboard and insert into outfile while (infile) { //Reading from the RAF infile.read(reinterpret_cast (&rec), sizeof(Record)); //Display the record on the screen if (rec.idno > 0) cout << rec.idno <<"\t" << rec.name <<"\t" << rec.surname <<"\t" << rec.gpa <<"\n"; } infile.close(); getch(); } */ /* void main() { ofstream outfile("C:/Temp/Student.dat", ios::binary); ofstream outfileTxt("C:/Temp/Student.txt"); Record rec; //Get data from the keyboard and insert into outfile for (int x = 0; x < 20; x++) { cout << "Enter ID, Name, Surname and GPA for record " << x+1 << " of 20 : "; cin >> rec.idno >> rec.name >> rec.surname >> rec.gpa; //Write to the RAF outfile.write(reinterpret_cast (&rec), sizeof(Record)); //Write to the TEXT file outfileTxt << rec.idno <<"\t" << rec.name <<"\t" << 2rec.surname <<"\t" << rec.gpa <<"\n"; } outfile.close(); outfileTxt.close(); getch(); } */