我正试图让该程序从.dat文件中读取数据,但我所能做的就是在不实际显示文件日期的情况下运行。我在这里想念什么?
"
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <fstream>
#include <iterator>
using namespace std;
void calculation(double &, double &, double &, double & , double &,
double &, double &,
double &, double &, double &);
int main()
{
ifstream input_file;
string social_security, last_name, first_name;
double payrate, income_taxrate;
double rhours, ohours, thours;
double netpay, grosspay, overtimepayrate, regularpayrate;
int record_number = 1;
double taxes;
input_file.open ("employee.dat",ios::in);
while(!input_file.eof()&& record_number !=12)
{
input_file >> social_security
>> last_name >> first_name
>> thours >> payrate >> income_taxrate;
regularpayrate = 0;
overtimepayrate = 0;
grosspay = 0;
ohours = 0;
calculation(overtimepayrate, payrate, regularpayrate, grosspay,
rhours, ohours, income_taxrate, netpay, thours, taxes);
cout << "Record #" << record_number
<< "\n" << "Employee Social security #: " <<
social_security
<< "\n" << "Last Name: " << last_name
<< "\tFirst Name: " << first_name
<< "\n" << "Hours Worked: " << thours
<< "\nPay Rate: $" << payrate;
//Setting the overtime hours versus regular hours
if(ohours > 0)
{
cout << "\n" << "Regular Pay "
<< 40.0 << " hours @ $"
<< payrate << ": $"
<< regularpayrate
<< "\n" << "Overtime Pay "
<< ohours << " hours @ $"
<< (payrate * 1.5) << " : $"
<< overtimepayrate;
}
else
{
cout << "\n" << "Regular Pay " << rhours << " hours @ "
<< payrate
<< " $"
<< regularpayrate;
}
cout << "\n" << "Gross Pay: $" << grosspay
<< "\n" << "Taxes @ " << (income_taxrate * 100) << "%: $" <<
taxes
<< "\n" << "Net Pay: $" << netpay
<< "\n\n\n";
record_number++;
}
}
void calculation(double & overtimepayrate, double & payrate, double &
regularpayrate
, double & grosspay , double & rhours, double & ohours,
double & income_taxrate,
double & netpay, double & thours, double & taxes)
{
if (thours> 40)
{
rhours = 40;
ohours = thours - 40;
}
if (thours < 40)
{
rhours = thours;
}
//Calculations
overtimepayrate = ohours* (payrate*1.5);
regularpayrate = rhours * payrate;
grosspay = regularpayrate + overtimepayrate;
taxes = grosspay * income_taxrate;
netpay = grosspay - taxes;
}
void intro(){
cout << "\n\tHello C++ user, I am a program that uses"
<< "\n\ta pointer function in order to access a"
<< "\n\tparticular data file.\n";
}
"
这是我希望在运行时显示的数据: