Question: This is the original question: This is the second part: This is my code for the second question: #include #include #include using namespace std; //function
This is the original question:

This is the second part:

This is my code for the second question:
#include
//function prototype void sortEmployees(struct Employee emp[], int);
// Create struct Employee struct Employee { string firstname; string lastname; int id; double salary; };
int main() { int i=0; //i will hold the count of employees // defines an input stream for the data file ifstream dataIn; // Declaring variables string fname, lname; int id, count = 0; double sal, tot = 0.0, avg = 0.0; // Create and instance of struct Employee of array type struct Employee emp[20]; // Opening the input file dataIn.open("D:\\HW10Prob1.dat"); /* If the file with the name is not found * display error message and terminate */ if (dataIn.fail()) { cout > fname >> lname >> sal >> id; //store the firstname, lastname, salary and id for ith employee in the struct array emp[i].firstname = fname; emp[i].lastname = lname; emp[i].salary = sal; emp[i].id = id;
// Displaying data on the console cout
//function that takes an array of structure and sort it void sortEmployees(struct Employee emp[], int numOfEmplopyees) { //loop through the array for (int i = 0; i emp[j + 1].salary) { //swap the employees struct Employee temp = emp[j]; emp[j] = emp[j + 1]; emp[j + 1] = temp; } } } }
This is the question I need answered in c++. Thanks :
![//function prototype void sortEmployees(struct Employee emp[], int); // Create struct Employee struct](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f525c64d294_02166f525c5ba71f.jpg)
Problem 1. Structures (25 points) Define a structure called Employee with four member variables- first name, last name, ID and salary. Use appropriate data types. You are provided a data file named HW10Probl.dat with four parameters in the format of: FirstName LastName Salary ID Declare an instance ofthe structure and name it emp. Read the appropriate parameter from the file, assign the read parameter to the correct variable and display them on the screen. Also, calculate the average salary and display on screen. Don't worry about arrays in this problem, you can display as you read them, one line at a time
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
