Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*** C++ only *** If you post a handwritten answer, please try to be clear with the writing. I do not understand how to go

*** C++ only ***

If you post a handwritten answer, please try to be clear with the writing. I do not understand how to go about this question at all. Thanks in advance! Below are the instructions:

a) You will write a C++ program that stores generic records in a random-access file. This program can store data of type Personnel, which contains: SSN, name, city, year of birth, and salary, and of type Student which extends Personnel to include major. You will store these records in a text file using a fix number of bytes for every record. Your program must be able to:

Insert a new record into a file

Find a record in the file

Modify an existing record

b) The user will supply the name of the file. If the file is not found, then it will create it.

c) You will need the following functions:

find(): and modify():

d) You will need a class Database that includes the following functions:

add(): and print():

e) The class Database must be able to write all records within the same number of bytes for each data member. For name and city, we can set a constant for the max length. We will use nameLen and cityLen to hold these values. To initialize these constants, you must use syntax similar to:

Personnel::Personnel() : nameLen(10), cityLen(10) {

name = new char[nameLen+1];

city = new char[cityLen+1];

f) The following function should be used to write data to files:

writeToFile(): Your program will also encounter issues when writing salary. You cannot write 50,000 and 100,000 in the same number of bytes (50000 vs. 100000). To avoid this problem, represent the number in a binary string using 32 bits (4 bytes). To do this we will store each byte as an ASCII character. The ASCII codes would be 0, 0, 195, 80. You can do this by using: out.write(reinterpret_cast(&salary),sizeof(long))

g) You must also be able to print the data to the user via the console. To do this you must interpret the data from the file as something that is readable. You should use one function to read from file and one to display the data the data to user. You should override the operator<< function in the Database class.

h) To test the flexibility of your program you must also be able to handle the Student class. When writing data for this class you must also include the variable major. You should use the super function from the Personnel class. Like this:

void Student::writeToFile(fstream& out) const {

Personnel::writeToFile(out);

out.write(major,majorLen);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions