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

Create a text file named info.dat containing the following data (without the hea

ID: 655311 • Letter: C

Question

Create a text file named info.dat containing the following data (without the headings):

Maybell    555-34-9081        12.31
Kendal 555-10-2910        14.34
Quan       555-79-0385        15.61
Chris       555-52-4607        15.04
Larry       555-85-3206        13.51

Using Data I/O write a C++ program that reads the data file and computes and displays the payroll schedule. The output should list the Social Security number, name, and gross pay for each person, calculating gross pay as hourly rate * hours worked.

(This is not an Assignment, It's Only PRACTICE)

Explanation / Answer

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
using namespace std;
int main()
{
String filename="Payroll.dat";//filename in string
string initial, name ,SSN;//declare variables to read data from file
int hours;
double rate;
ifstream inFile;
inFile.open(filenmae.c_str());
if(inFile.fail())
{
cout<<" The file was not suucessfully opened "
<<" please check that the file currently exists"<<endl;
exit(!);
}
inFile >> initial >>name >> SSN >> rate >>hours;
while(inFile.good())
{
   cout<<"SSN <<' ' << initial << ' ' << name << ' ' << rate * hours << endl;
inFile>> initial >. name >>SSN >>rate>> hours;
}
inFile.close();
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