For this assignment you will attempt to store records in a structured way. You w
ID: 3881381 • Letter: F
Question
For this assignment you will attempt to store records in a structured way. You will store these records in a text file using a fix number of bytes for every record. This will allow your program to more easily store and read data. This is especially useful for when the program needs to begin reading from the middle of the data. This fixed sized of each record allows the program to quickly move to the nth record by seeking In a normal setup you would need to read every record up until you reached the nth record to ensure that you parsed the correct number of records. This new type of file is known as a random-access file. You will write a program that stores generk records in a random-access file. This program can store data of type Personnel, which contains: SSN, nane, city, year of birth, and salary, and of type Student which extends Personnel to include major Your program must be able to: e Insert a new record into a file .Find a record in the file .Modify an existing record The user will supply the name of the file, if the file is not found, then it will create it. You will need the following functions: find 0:This method determines if a record exists in the file by sequentially comparing it to the supplied record using an overloaded equality operator but it should be something that can be used elsewhere. This function may return whatever you like, nodi fy )This method will use findto locate a record within the file then it will use the overloaded operator>> to update the record. To do this you must move the file pointer back to the beginning of the record. This position is known because of the fixed size of the record. This is done by using: database. seekp -d. si zeo , ios: : cur ) . where size () must be defined in the class T which is the class type for object d You will need a class Database that includes the following functions: add ): Adds a new record to the file. print 0: Prints the contents of the file to console. The class Database must be able to write all records within the same number of bytes for each data member, For SSN and year of birth this is easy as they have a fxed size of 9 and 4 respectively, However, for name, city, and salary this is more difficult as they often have different lengths. For name and city, we can set a constant for the max length. We will use nameLen and cityLen to hold these alues. This will also allow us more flexibility when creating new records. To initialize these constants you must use syntax similar to this:Explanation / Answer
class Personnel
{
public:
int SSN;
char[] name;
char[] city;
int year_of_birth;
float salary;
Personnel():nameLen(10),cityLen(10)
{
name=new char[nameLen+1];
city=new char[cityLen+1];
}
void writeToFile(fstream out)
{
out.open("Input.txt", ios::out);
out.write(SSN, sizeof(int));
out.write(name,nameLen);
out.write(city,cityLen);
out.write(year_of_birth, sizeof(int));
out.write(salary, sizeof(float));
}
}
class Student : public Personnel
{
public:
char[] major;
Student:majorLen(10)
{}
insert();
find();
modify();
writeToFile(fstream out)
{
Personnel::writeToFile(out);
out.write(major,majorLen);
}
}
class Database
{
public:
add();
print();
}
File handling in c++ is mainly used
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.