Input 10 last names, first names and ages, and write them to the file.

What will be an ideal response?

```
string last;
string first;
string age;
int id;
unsigned int counter{1};
while (counter <= 10) {
cpphtp10.book Page 4 Tuesday, September 6, 2016 7:06 PM
Exercises 5
do { // obtain id-number value
cout << "Enter id number for new record (1 - 100): "
cin << id;
} while ((id < 1) || (id > 100));
// move file-position pointer to correct record in file
fileObject.seekg((id - 1) * sizeof(Person));
// read record from file to determine if one already exists
Person person;
fileObject.read(reinterpret_cast(&person), sizeof(Person));
// create record, if record does not previously exist
if (person.getId() == 0) {
cout << "Enter last name, first name, and age: ";
cin >> setw(15) last;
cin >> setw(15) first;
cin >> setw(4) >> age;
person.setLastName(last);
person.setFirstName(first);
person.setAge(age);
person.setId(id);
// move file-position pointer to correct record in file
fileObject.seekp((id - 1) * sizeof(Person));
// insert new record
fileObject.write(reinterpret_cast(&person),
sizeof(Person));
++counter; // record added, increase counter
}
else { // display error if record previously exists
cerr << "Record #" << id << " already contains data." << endl;
}
}
```

Computer Science & Information Technology

You might also like to view...

Most smartphones come with a standard collection of software that includes all of the following EXCEPT ________

A) personal productivity software B) a database C) a contact list D) a calendar

Computer Science & Information Technology

The ________ content control allows the user to select a specific item from a list

A) Plain Text B) Drop-Down List C) List D) Combo List

Computer Science & Information Technology