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
// 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
sizeof(Person));
++counter; // record added, increase counter
}
else { // display error if record previously exists
cerr << "Record #" << id << " already contains data." << endl;
}
}
```
You might also like to view...
The ____ list style type uses lowercase Roman numerals.
A. non-roman B. lowercase-roman C. lowercase D. lower-roman
The PivotTable ________ tab focuses on formatting and the appearance aspect of designing the PivotTable
A) Layout B) Options C) Design D) Format
Which calculation uses the formula AV × EF?
A. SLE B. ARO C. ALE D. Cost-benefit analysis
When a data flow diagram (DFD) is exploded, the lower-level diagram is referred to as the parent diagram.
Answer the following statement true (T) or false (F)