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

Write a program using a class that has array data members NAME, SALARY, YEAR_HIR

ID: 3601918 • Letter: W

Question

Write a program using a class that has array data members NAME, SALARY, YEAR_HIRED. This program will

1) write the data for 10 records to a random access file

2) allow the user to output the name, salary, hire_date for a selected record

3) allow the user to change the name, salary, or hire_date for a selected record.

4) allow the user to add a record.

Note: The record number is the sbscript of the array for NAME, SALARY, DATE_HIRED.  

PLEASE FIRST WRITE A PROGRAM THAT WRITES NAME TO A RANDOM ACCESS FILE AND READS IT  

*************** MAKE SURE THIS WORKS !!*****************

***********THEN MAKE NAME, SALARY, DATE_HIRED ARRAYS and MAKE SURE IT WORKS *********

    ***************THEN MAKE YOUR PROGRAM WRITE and READ 10 RECORDS. . MAKE SURE THIS WORKS *********

***************** FINALLY ALLOW USER TO OUTPUT AND MODIFY SELECTED RECORD.*********** MAKE SURE IT WORKS.

Programming language C++

Explanation / Answer

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

int ID[10];

double hrs[10];

double payrate[10];

double total[10];

void ReadFromFile()

{

char filename[30];

cout<<"Enter the input file name"<<endl;

cin>>filename;

ifstream myfile(filename);

int i=0;

while((i<10)&&(!myfile.eof()))

{

myfile>>ID[i];

myfile>>hrs[i];

myfile>>payrate[i];

i++;

}

myfile.close();

}

double totalpay(double hrs,double payrate)

{

if(hrs<=40)

{

return hrs*payrate;

}

else

{

return (hrs*payrate)+((hrs-40)*100*0.1/5);

}

}

void WriteToFile()

{

cout<<"Enter the output file name"<<endl;

char filename[30];

cin>>filename;

ofstream out(filename);

int i=0;

for(i=0;i<10;i++)

{

out<<ID[i]<<" "<<hrs[i]<<" "<<payrate[i]<<" "<<total[i]<<endl;

}

out.close();

}

int main()

{

ReadFromFile();

int i=0;

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

{

total[i]=totalpay(hrs[i],payrate[i]);

}

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