Question
Write a simple payroll program that would: 1. Change the structure in project #3 to a class; 2. Making all variables of the class private;
Write a simple payroll program that would:
1. Change the structure in project #3 to a class;
2. Making all variables of the class private;
3. Add constructors, mutator, accessors, input, & output functions;
4. Save the class declaration in a head file;
5. Save the definitions of the class in a .cpp file;
6. Write a main function to (using classs functions):
7. Read employees information from a disk file (attached with email for project #3). The text file includes records of employees. Each record includes: employees name (30 bytes), employees id (5 bytes), hourly rate (int), hours worked (int).
8. Calculate the wage for each employee based on the hourly rate and the hours worked.
9. Display on the screen the employees name and wage.
10. Repeat step 7 through 9 until the end of file.
this is my program.
// c++ file read and structure
#include
#include
using namespace std;
struct employee
{
char name[50];
char id[5];
int hourlyrate;
int hourworked;
int wage;
};
// to sort record based on wage of employess
void sort(employee k[5], int n)
{
int i, j;
employee temp;
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < (n - 1 - i); j++) // inner loops
{
if (k[j].wage { temp = k[j]; k[j] = k[j + 1]; k[j + 1] = temp; } } } } int main() { ifstream dataIn("payroll.txt"); employee ob[5]; int i = 0; if (dataIn.fail()) { cout << "** File Not Found **"; return 1; } else { while (dataIn) { dataIn >> ob[i].name >> ob[i].id >> ob[i].hourlyrate >> ob[i].hourworked; ob[i].wage = ob[i].hourlyrate * ob[i].hourworked; i++; } } sort(ob, 5); for (i = 0; i<5; i++) cout << ob[i].name << " " << ob[i].wage << " "; system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started