Question
Hello. I am having trouble having my function output like the sample. In c++ request help in fixing my code: int main(){ const int DISPLAY
Hello.
I am having trouble having my function output like the sample. In c++ request help in fixing my code:
int main(){
const int DISPLAY = 18;
int buffer = 46;
// char array to hold entire record of instructors from file with the data size as the size of the array
char record[buffer];
// pointer array to manage all the instructor objects
Instructor* instructorRecord[SIZE] = {nullptr};
// for use with salary function
Instructor* highestSalary = nullptr;
ifstream dataFile;
dataFile.open("pa2data", ios::in);
if(!dataFile.is_open()){
cout
exit(EXIT_FAILURE);
}
// Dynamically allocate and initialize each element of instructor record to null pointer.
for (int i = 0; i
{
instructorRecord[i] = nullptr;
}
// reads the data and creates new objects of instructors based on the file its reading
for (int i = 0; i
{
instructorRecord[i] = new Instructor();
char charEmployeeId[10], charLastName[16], charMI[2],
charFirstName[11], charDepartment[6], charSalary[7];
strncpy(charEmployeeId, record, 9);
charEmployeeId[9] = '\0';
strncpy(charFirstName, record + 9, 11);
charFirstName[10] = '\0';
strncpy(charMI, record + 19, 1);
charMI[1] = '\0';
strncpy(charLastName, record + 20, 16);
charLastName[16] = '\0';
strncpy(charDepartment, record + 36, 6);
charDepartment[6] = '\0';
strncpy(charSalary, record + 42, 7);
charSalary[7] = '\0';
instructorRecord[i]->id = charEmployeeId;
instructorRecord[i]->lastName = charLastName;
instructorRecord[i]->middleInit = charMI[0];
instructorRecord[i]->firstName = charFirstName;
instructorRecord[i]->department = charDepartment;
instructorRecord[i]->salary = atoi(charSalary);
}
dataFile.close();
// Displays the record from the file
cout
cout
for (int i = 0; instructorRecord[i] != nullptr; i++){
cout id
lastName
middleInit
firstName
department
salary
}
// deletes allocated memory pointers and cleans up
for (int i = 0; i
delete []instructorRecord[i];
}
//terminate
return 0;
}
This is the sample
this is my sample
EmployeeID=====================================================ABC123456DEF234567LastnameAnconiaBulsaraMIDBFirstNameFranciscoFarrokhDepartmentBUSNMUSCSalary123456987654
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started