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

C++ program with structures, array of structures, files, sorting, and formatting

ID: 3812937 • Letter: C

Question

C++ program with structures, array of structures, files, sorting, and formatting. Thank you!

**Must read in the file and output to a file**

Sample input file (employees.txt):

1000 George Washington 10000

2000 John Adams 15000

1212 Thomas Jefferson 34000

1313 Abraham Lincoln 45000

1515 Jimmy Carter 78000

1717 George Bush 80000

objectives: Work with structures, array of structures, files, sorting, and formatting ****DO NOT USE SSTREAM A company keeps its employee records in a file. Each line in the file includes a single employee record (id, first name, last name, salary). Write a C++ program that prints several reports of employee data You are asked to process the data in the file be storing each record in an array of structures. You may assume thatthe number of employees will never exceed 100. Your program must print two reports All employee records sorted by last name. All employee records sorted by salary. Find and print the total payroll. Hints: Write a function to load the arrayof structures (make sure the name is in the right format) Write a function to sort the array by last name. Write a function to sort the array by salary o Use the same swap function for both sort functions Write a function to printthe report. This function can be used for both reports. Write a function to calculate and return the total payroll.

Explanation / Answer

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

employee

    {

       char firstname[15];

       char lastname[15];

       int id;

       int salary;

    };

main( )

    {

      

       constint n=2;

       employee e[n];

       for(int i=0;i<100;i++)

      {

         cout<<" Enter the details of the employee"<<i+1<<" is : ";

         cout<<" Enter the firstname = ";

         gets(e[i].firstname);

         cout<<" Enter the id = ";

         cin>>e[i].id;

         cout<<" Enter the lastname of employee”<<i+1<<” is: ”; = ";

         cin>>e[i].lastname;

         cout<<" Enter the salary = ";

         cin>>e[i].salary;

}

Function sortlastname

{

char lastname[numlastnames][100];

for(int i=1; i<=numNames; i++)    

{       

for(int j=numNames-1; j>=i; j--)       

{         

if(lastname[j-1] [0] > lastname[j][0])

{

strcpy(lastname_buff [1],lastname[j-1]);

strcpy(lastname[j-1], lastname[j]);

strcpy(lastname[j], lastname_buff[1]);

}        }      }

for (int i = 0; i < numNames; i++)       

cout << lastname[i] << " ";   

return 0;

}

Function payroll

{

int sumsum = 0;

int payroll = 0;

int i = 0;

    while (payroll != -1) {

        cout << "Enter a payroll amount ";

        cin >> payroll;

        if(payroll == -1) break;

        if((payroll < -1)){

            cout << "Please enter a correct value. " ;

            continue;

        }

        else {

            sum = sum + payroll;

            i++;

        }

    }

    cout << “payroll amount is: " << sum;

        return 0;

}

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