C programing A company keeps the record of its employees in

C++ programing

A company keeps the record of its employees in a text file. The text file is in the following format FirstName LastName ID Salary

Write C++ program to read the text file and calculate the maximum salary. You then need to display the maximum salary and the FirstName, the LastName and the ID of the corresponding employee earning that maximum salary.

company file**

John Harris 11374 50000.00

Lisa Smith 11985 75000.00
Adam Johnson 12585 68500.00
Sheila Smith 11654 150000.00
Tristen Major 11274 75800.00
Yannic Lennart 15687 58000.00
Lorena Emil 17414 43000.00
Tereza Santeri 12597 48000.00

Solution

// C++ code read emploee details from file and determine maximum salary

#include <iostream>
#include <string.h>
#include <fstream>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{

string FirstName, LastName, ID;
double Salary;
double maxSalary = 0;
string maxFirstName, maxLastName, maxID;

ifstream inputfile (\"employee.txt\");
if (inputfile.is_open())
{
    while ( true )
    {
      inputfile >> FirstName >> LastName >> ID >> Salary;

      if(Salary > maxSalary)
      {
            maxSalary = Salary;
            maxID = ID;
            maxLastName = LastName;
            maxFirstName = FirstName;
      }
      if(inputfile.eof())
        break;
    }
    inputfile.close();
}

else
    cout << \"Unable to open file\";

cout << \"Maximum Salary: \" << maxSalary << endl;
cout << \"Name: \" << maxFirstName << \" \" << maxLastName << endl;
cout << \"ID: \" << maxID << endl;

return 0;
}

/*
employee.txt
John Harris 11374 50000.00
Lisa Smith 11985 75000.00
Adam Johnson 12585 68500.00
Sheila Smith 11654 150000.00
Tristen Major 11274 75800.00
Yannic Lennart 15687 58000.00
Lorena Emil 17414 43000.00
Tereza Santeri 12597 48000.00


output:
Maximum Salary: 150000
Name: Sheila Smith
ID: 11654


*/

C++ programing A company keeps the record of its employees in a text file. The text file is in the following format FirstName LastName ID Salary Write C++ progr
C++ programing A company keeps the record of its employees in a text file. The text file is in the following format FirstName LastName ID Salary Write C++ progr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site