如何从文件中提取薪酬最高的员工的详细信息
How to extract the details of the highest paid employee in files?
我在从empdetails.txt提取薪酬最高的员工,并最终显示给用户的问题。我已经完成了从用户和合并两个文件的详细信息,但显示使用功能的最高报酬,我不知道它。
这是我到现在为止的代码:
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
class emp
{
int num,age;
char name[20],dep[5];
public:
void getdata()
{
cout<<"nn Name = ";
cin>>name;
cout<<"n Emp Num = ";
cin>>num;
cout<<"n Department= ";
cin>>dep;
cout<<"n Age = ";
cin>>age;
}
void display1()
{
cout<<"n"<<name<<"t"<<num<<"t"<<dep<<"tt"<<age;
}
};
class sal
{
float gs,ns;
public:
void getsal()
{
cout<<"n Gross sal = ";
cin>>gs;
cout<<"n Net sal = ";
cin>>ns;
}
void display2()
{
cout<<"t"<<gs<<"t"<<ns;
}
};
void display()
{
emp e;sal s;
ifstream fil1;
fil1.open("empdetails.txt",ios::in);
cout<<"nn Name t Emp Num t Dep t Age t Gross Sal t Net Sal n";
while(!fil1.eof())
{
fil1.read((char*)&e,sizeof(e));
e.display1();
fil1.read((char*)&s,sizeof(s));
s.display2();
}
}
int main()
{
int n;
emp e1;sal s1;
ofstream fil1,fil2,fil3;
fil1.open("emp.txt",ios::out);
fil2.open("sal.txt",ios::out);
fil3.open("empdetails.txt",ios::out);
cout<<"n How many employee details do you want to enter = ";
cin>>n;
cout<<"n Enter the deatils one by one n";
for(int i=0;i<n;i++)
{
e1.getdata();
fil1.write((char*)&e1,sizeof(e1));
s1.getsal();
fil2.write((char*)&s1,sizeof(s1));
fil3.write((char*)&e1,sizeof(e1));
fil3.write((char*)&s1,sizeof(s1));
}
fil1.close();
fil2.close();
fil3.close();
cout<<"nntt Merged file contents nntt";
display();
getch();
return 0;
}
如何创建函数以及使用什么条件?
你不需要一个函数,已经有一个了:std::max_element
。它可以计算出您正在处理class emp
(std::max_element
的前两个参数)。它无法计算出您希望员工按工资排序,因此这是您必须提供的第三个参数:一个接受两个员工的函数,如果第一个员工的收入低于第二个员工,则返回true
。(听起来很奇怪,但这允许您对std::min_element
使用相同的函数)
相关文章:
- std::extent 实现详细信息说明
- VisualC++ 2010 有没有办法找出有关未处理异常错误的更多详细信息
- 如何使用软化工具包从 OPC UA 服务器异步读取操作回调中的数据值响应中获取 NodeId 详细信息
- protobuf,如何在protobuf消息中遍历所有集合字段,我不知道详细信息?(C++)
- AVX2收集指令使用详细信息
- 如何在文本文件中搜索员工记录(按名称)并仅显示其详细信息?
- 使用TDD时隐藏文件访问实现详细信息
- 显示 txt 文件详细信息
- 如何在Linux终端的目录下显示详细的文件信息?-C++
- 为什么 Boost 和其他库的某些部分(如 Folly)在详细信息子文件夹中
- 使用IShellDispatch界面更改文件的详细信息选项卡(右键单击时)?
- 在 C++ 中设置内置 exe 的 Windows 文件详细信息
- 当全局函数需要指向 impl 的指针时,如何防止 impl 详细信息出现在头文件中
- 如何在二进制文件(.net或非托管文件)中注入/更新Version和其他详细信息
- 从 C++ 中的文件中获取特定位置的详细信息
- 如何将字符串行作为cl_uint数组和文件详细信息传递给GPGPU
- 如何从文件中提取薪酬最高的员工的详细信息
- 从libcurl获取详细信息到文件
- 从显示输出中最后一行详细信息的文本文件中读取两次
- 在gdb - c++中打印有关文件流对象的详细信息