Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;作业按顺序排列工资单上的姓名。使用数组_C++_Function_Fstream - Fatal编程技术网

C++ C++;作业按顺序排列工资单上的姓名。使用数组

C++ C++;作业按顺序排列工资单上的姓名。使用数组,c++,function,fstream,C++,Function,Fstream,请假设我的代码示例的标题已经准备好了 我好像没法让它工作 错误显示: c:\ProgramFiles(x86)\microsoft visual studio 10.0\vc\include\fstream(890):错误C2248:“std::basic\u ios::basic\u ios”:无法访问在类“std::basic\u ios”中声明的私有成员。 这是我的家庭作业问题: 问题:按关键值对员工进行排序。 对于此任务,您需要扩展以前编写的员工工资单报告程序。应修改您的程序,以允许输入

请假设我的代码示例的标题已经准备好了

我好像没法让它工作

错误显示:

c:\ProgramFiles(x86)\microsoft visual studio 10.0\vc\include\fstream(890):错误C2248:“std::basic\u ios::basic\u ios”:无法访问在类“std::basic\u ios”中声明的私有成员。

这是我的家庭作业问题:

问题:按关键值对员工进行排序。

对于此任务,您需要扩展以前编写的员工工资单报告程序。应修改您的程序,以允许输入最多15名员工的数据。无论输入员工数据的顺序如何,报告的详细信息行都应按员工姓名升序打印。换句话说,在生成报告之前,您应该首先对员工数据进行排序。您的程序应包括上一次任务中描述的员工和工资报告类

这是我的密码。。。 员工类别:
class员工
{
公众:
雇员();
int输入();
void calculate();
void display();
无效输入存储(员工[]);
无效排序(员工[],整数);
无效掉期(员工和,员工和);
无效集合名称(字符串);
字符串get_name();
无效设置时间(双倍);
双倍获得时间();
空置率(双倍);
双重获得率();
空套(双套);
双倍获得卵巢();
无效设置(双);
双关语;
空套(双套);
double get_ovrsal();
无效集合计数(int);
int get_count();
私人:
字符串名;
整数计数;
双倍时数、速率、卵数、sal、卵数;
河流充填;
};
雇员::雇员()
{
计数=0;
open(“payroll.txt”,ios::in);
如果(!infle)
cout>姓名>>小时数>>费率)
返回1;
其他的
返回0;
}
作废员工::计算()
{
卵母细胞=小时-40;
如果(卵圆>=10)
{
ovrsal=(10*(1.5*费率))+((50小时)*(2*费率));
sal=(40*比率)+ovrsal;
}
else if(ovrhours>0&&ovrhours0;i--)
对于(int j=0;j存储[j+1].name)交换(存储[j],存储[j+1]);
}
作废员工::掉期(员工a、员工b)
{
员工临时工=a;
a=b;
b=温度;
}
void Employee::display()
{   

cout那里有大量与实际问题无关的代码

以下是您如何将其简化为一个,使我们能够更轻松地帮助您:

#include <iostream>
#include <fstream>

using namespace std;

class Employee
{
public:
    Employee();
    void swap(Employee &, Employee &);
private:
    int count;
    ifstream infile;
};

Employee::Employee()
{
    count=0;
    infile.open("payroll.txt", ios::in);
    if (!infile)
        cout << " Error: Could not open input file. \n";
}

void Employee::swap(Employee &a, Employee &b)
{
    Employee temp = a;
    a = b;
    b = temp;
}
然后,您需要更改在
main()函数中打开和读取文件的方式

// [...]
    p.columnheadings();

    std::ifstream infile("payroll.txt");
    if (!infile)
    {
        // N.B: Report errors on stderr!
        std::cerr << " Error: Could not open input file. \n";
    }

    while (infile >> x)
    {
        x.calculate();
        x.input_storage(storage);

        loopcount++;
    }

    x.sort(storage, loopcount);
// [...]
/[…]
p、 列标题();
std::ifstream infle(“payroll.txt”);
如果(!infle)
{
//注意:在stderr上报告错误!
标准:cerr>x)
{
x、 计算();
x、 输入存储(存储);
loopcount++;
}
x、 排序(存储、循环计数);
// [...]
    int main()
    {

        int loopcount;
        Employee x;
        Employee storage[15];
        PayrollReport p;

        p.reportheader();
        p.columnheadings();


        while (x.input()==1)
        {       
            x.calculate();
            x.input_storage(storage);

            loopcount++;
        }

        x.sort(storage, loopcount);

        for (int i=0; i<loopcount; i++)
        p.insertDetail(storage, loopcount);


        p.display_total(storage);
        x.display();

        cin.ignore();
        return 0;

    }
#include <iostream>
#include <fstream>

using namespace std;

class Employee
{
public:
    Employee();
    void swap(Employee &, Employee &);
private:
    int count;
    ifstream infile;
};

Employee::Employee()
{
    count=0;
    infile.open("payroll.txt", ios::in);
    if (!infile)
        cout << " Error: Could not open input file. \n";
}

void Employee::swap(Employee &a, Employee &b)
{
    Employee temp = a;
    a = b;
    b = temp;
}
std::ifstream& operator >>(std::ifstream& is, Employee& employee)
{
    std::string name;
    double hours, rate;
    if (is >> name >> hours >> rate)
    {
        employee.set_name(name);
        employee.set_hours(hours);
        employee.set_rate(rate);
    }
    return is;
}
// [...]
    p.columnheadings();

    std::ifstream infile("payroll.txt");
    if (!infile)
    {
        // N.B: Report errors on stderr!
        std::cerr << " Error: Could not open input file. \n";
    }

    while (infile >> x)
    {
        x.calculate();
        x.input_storage(storage);

        loopcount++;
    }

    x.sort(storage, loopcount);
// [...]