Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE HELP! A company keeps its employee databases in two text files. The first

ID: 3576948 • Letter: P

Question

PLEASE HELP!

A company keeps its employee databases in two text files. The first file contains the first name, the last name and ID in the following format

FirstName LastName ID

This is provided to you as file1.txt

The second file contains the ID, the SSN and the salary of the employee

ID SSN Salary

This is provided to you in file2.txt. Note that the order of the IDs may not be the same in both files. Design a program with a nested structure. The outer structure is named Employee and has variables for first name, last name and salary. The inner structure is called Confidential and has variables for SSN and salary

Declare an array of structures in your main function

For e.g. Employee E[20]

Assume there are no more than 20 employees in the company. After reading both files and paring the data by ID, display the first name, the last name, the SSN and the salary of each employee

HINT: EXAMPLE OF HOW TO USE ARRAY STRUCTURE

#include <iostream>
using namespace std;
struct Student
{
string fname;
string lname;
double GPA;
};
int main()
{
Student S[20];
cout<<"Enter data for students";
for (int i=0;i<20;++i)
cin>>S[i].fname>>S[i].lname>>S[i].GPA;
for (int i=0;i<20;++i)
cout<<S[i].fname<<" "<<S[i].lname<<" "<<S[i].GPA<<endl;
return 0;
}

HERE IS INFORMATION IN file1.txt

HERE IS THE INFORMATION IN file2.txt

Explanation / Answer

// C++ code
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>     // std::string, std::to_string
#include <math.h>
#include <fstream>

using namespace std;

struct Confidential
{
    int id;
    int SSN;
    double salary;
};

struct Student
{
    string FirstName;
    string LastName;
    int id;
    struct Confidential conf;
};


int main()
{
    Student s[20];
    int size = 0;

    ifstream inFile ("file1.txt");
    if (inFile.is_open())
    {
      while(true)
      {
          if(inFile.eof())
            break;

          inFile >> s[size].FirstName >> s[size].LastName >> s[size].id;
          size++;
      }
      inFile.close();
    }
    else cout << "Unable to open file";

    int readID;
    ifstream inFile1 ("file2.txt");
    if (inFile1.is_open())
    {
      while(true)
      {
          if(inFile1.eof())
            break;

          inFile1 >> readID;
          for (int i = 0; i < size; ++i)
          {
             if(s[i].id == readID)
             {
                s[i].conf.id = readID;
                inFile1 >> s[i].conf.SSN;
                inFile1 >> s[i].conf.salary;
             }
          }
      }
      inFile1.close();
    }
    else cout << "Unable to open file";

    cout << "Employee details ";
    for (int i = 0; i < size; ++i)
    {
       cout << s[i].id << " " << s[i].FirstName << " " << s[i].LastName << " " << s[i].conf.SSN << " " << s[i].conf.salary << endl;
    }

    return 0;
}


/*
file1.txt
John Harris 1000
Lisa Smith 1002
Adam Johnson 1007
Sheila Smith 1009
Tristen Major 1012
Yannic Lennart 1015
Lorena Emil 1018
Tereza Santeri 1020


file2.txt
1002 225365256 50000.00
1009 256214856 75000.00
1000 256314765 80000.00
1020 245123655 38000.00
1018 225453664 125000.00
1007 215236645 65800.00
1012 236456425 58000.00
1015 256452256 99000.00


output:
Employee details
1000 John Harris 256314765 80000
1002 Lisa Smith 225365256 50000
1007 Adam Johnson 215236645 65800
1009 Sheila Smith 256214856 75000
1012 Tristen Major 236456425 58000
1015 Yannic Lennart 256452256 99000
1018 Lorena Emil 225453664 125000
1020 Tereza Santeri 245123655 38000

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote