Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is incomplete and I want the output of the program shown below Employee.cpp #include #include cstring.h // implemented in workshop 1 part 2

This program is incomplete and I want the output of the program shown below

Employee.cpp

#include

#include "cstring.h" // implemented in workshop 1 part 2 (DIY)

#include "Employee.h"

#include "File.h"

using namespace std;

namespace sdds {

int noOfEmployees;

Employee* employees;

void sort() {

int i, j;

Employee temp;

for (i = noOfEmployees - 1; i > 0; i--) {

for (j = 0; j < i; j++) {

if (employees[j].m_empNo > employees[j + 1].m_empNo) {

temp = employees[j];

employees[j] = employees[j + 1];

employees[j + 1] = temp;

}

}

}

}

// TODO: Finish the implementation of the 1 arg load function which

// reads one employee record from the file and loads it into the employee reference

// argument

bool load(...............) {

bool ok = false;

char name[128];

/* if reading of employee number, salay and name are successful

allocate memory to the size of the name + 1

and keep its address in the name of the Employee Reference

copy the name into the newly allocated memroy

make sure the "ok" flag is set to true

end if

*/

return ok;

}

// TODO: Finish the implementation of the 0 arg load function

bool load() {

bool ok = false;

int i = 0;

if (openFile(DATAFILE)) {

/*

Set the noOfEmployees to the number of recoreds in the file.

dyanamically allocated an array of employees into the global

Employee pointer; "employees" to the size of the noOfEmployees.

In a loop load the employee records from the file into

the dynamic array.

If the number of the records does not match the number of reads

print the message

"Error: incorrect number of records read; the data is possibly corrupted"

Otherwise

set the ok flag to true

End if

close the file

*/

}

else {

cout << "Could not open data file: " << DATAFILE<< endl;

}

return ok;

}

// TODO: Implementation for the display functions go here

// TODO: Implementation for the deallocateMemory function goes here

}

Header file for employee

#ifndef SDDS_EMPLOYEE_H_

#define SDDS_EMPLOYEE_H_

#define DATAFILE "employees.csv"

namespace sdds {

struct Employee {

char* m_name;

int m_studentNumber;

double m_gpa;

};

//sorts the dynamic array of employees based on the GPA of the employees.

void sort();

// loads a employee structue with its values from the file

bool load(.............);

// allocates the dyanmic array of employees and loads all the file

// recoreds into the array

bool load();

// TODO: Declare the prototype for the display function that

// displays a employee record on the screen:

// TODO: Declare the prototype for the display function that

// first sorts the employees then displays all the employees on the screen

// TODO: Declare the prototype for the deallocateMemory function that

// first will deallocate all the names in the employee elements

// then it will deallocate the employee array

#endif // SDDS_EMPLOYEE_H_

Header file for File.h

#ifndef SDDS_FILE_H_

#define SDDS_FILE_H_

namespace sdds {

bool openFile(const char filename[]);

void closeFile();

int noOfRecords();

// TODO: Declare read prototypes

}

#endif // !SDDS_FILE_H_

File.cpp

#define _CRT_SECURE_NO_WARNINGS

#include

#include "File.h"

namespace sdds {

FILE* fptr;

bool openFile(const char filename[]) {

fptr = fopen(filename, "r");

return fptr != NULL;

}

int noOfRecords() {

int noOfRecs = 0;

char ch;

while (fscanf(fptr, "%c", &ch) == 1) {

noOfRecs += (ch == ' ');

}

rewind(fptr);

return noOfRecs;

}

void closeFile() {

if (fptr) fclose(fptr);

}

/* TODO: read functions go here

bool read(................) {

return .....

}

bool read(................) {

return .....

}

bool read(................) {

return .....

}

*/

}

SalReport.cpp. - .can not make any changes in this file

#include "Employee.h"

using namespace sdds;

int main() {

if (load()) {

display();

}

deallocateMemory();

return 0;

}

Sample output

Employee Salary report, sorted by employee number no- Empno, Name, Salary

------------------------------------------------

1- 117493: Bumblebee Man, 43554.1

2- 238023: Alice Glick, 15310.6

3- 261382: Artie Ziff, 44801.1

4- 268411: Bernice Hibbert, 27776.9

5- 463877: Allison Taylor, 93971.9

6- 529967: Abraham Simpson, 80084.4

7- 543817: Barney Gumble, 54858.7

8- 737371: Agnes Skinner, 32943.1

9- 760089: Akira Kurosawa, 55772

10- 811518: Baby Gerald, 90670.1

11- 836915: Apu Nahasapeemapetilon, 63415.7

12- 881837: Bart Simpson, 47608.2

13- 928072: Carl Carlson, 23678.4

14- 954291: Brandine Spuckler, 51499.7

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago