我有两个类,一个名为“OrganisationRecord
”,另一个名为“PayrollProcessing
”。 “OrganisationRecord
”包含员工的职业和部门名称。
class OrganisationRecord
{
private:
public:
string name;
string occupation;
string department;
};
class PayrollProcessing
{
private:
ifstream inputfile;
ofstream outputfile;
vector<OrganisationRecord> OrganisationRecords;
public:
void loadOrganisationRecords(string filename);
void displayEmployeeOfSalaryGTE(double salary);
//GTE = greater than or equal to
};
“PayrollProcessing
”中的是两个成员函数; “loadOrganisationRecords
”和“displayEmployeeOfSalaryGTE
”代码为:
void PayrollProcessing::loadOrganisationRecords(string filename)
{
inputfile.open(ORGANISATIONALRECORDSFILE);
if (!inputfile)
{
cout << "the organisation records file does not exist!" << endl;
return;
}
OrganisationRecord _organisationrecord;
int employeenumber;
while (inputfile >> employeenumber)
{
inputfile.ignore();
getline(inputfile, _organisationrecord.name);
getline(inputfile, _organisationrecord.occupation);
getline(inputfile, _organisationrecord.department);
OrganisationRecords.push_back(_organisationrecord);
}
inputfile.close();
}
void PayrollProcessing::displayEmployeeOfSalaryGTE(double salary)
{
unsigned int count;
salary = SALARY;
if (salary < 0)
{
cout << "no record match this criteria!" << endl;
return;
}
for (count = 0; count < PayrollRecords.size(); count++)
{
if (PayrollRecords[count].salary >= salary)
{
cout << "=============================================" << endl;
cout << "Employeenumber: " << endl << endl;
cout << "Name: " << OrganisationRecords[count].name << endl;
cout << "Adress: " << HRRecords[count].address << endl;
cout << "Department: " << OrganisationRecords[count].department << endl;
cout << "Salary: " << PayrollRecords[count].salary << endl;
cout << "=============================================" << endl;
cout << OrganisationRecords.size();
}
}
return;
}
如何隐含地将员工编号显示在“displayEmployeeOfSalaryGTE
”中。
答案 0 :(得分:0)
根据您的阅读代码,每个组织记录都有一个员工编号。只需将该值的字段添加到OrganisationRecord
类,然后您就可以在displayEmployeeOfSalaryGTE()
中访问它,例如:
class OrganisationRecord
{
public:
int employeeNumber; // <-- add this
...
};
...
void PayrollProcessing::loadOrganisationRecords(string filename)
{
...
int employeeNumber;
OrganisationRecord _organisationrecord;
while (inputfile >> employeeNumber)
{
inputfile.ignore();
_organisationrecord.employeeNumber = employeeNumber // <-- add this
...
}
...
}
...
cout << "EmployeeNumber: " << OrganisationRecords[count].employeeNumber << endl;