网站建设的开多少税率东莞企业网站设计公司
本作业主要考察:C++二进制文件读写
二进制文件读写是格式化数据的持久化的基础,就算是像数据库这种大型的复杂的系统软件,其原理也就是建立在格式化文件读写的基础上的。
C++中级程序员教程
C++读写文本文件的请移步这里
需求如下:

实现代码完成下面的测试用例,要求和预期输出结果一致
#include <iostream>
#include <string>
#include <fstream>
#include <list>
using namespace std;struct Record
{static constexpr int FIRST_NAME_LEN = 10;static constexpr int SECOND_NAME_LEN = 10;static constexpr int SOCIAL_SECURITY_LEN = 9;static constexpr int DEP_ID_LEN = 9;public:Record(void);friend istream& operator>>(istream& in, Record& record);friend ostream& operator<<(ostream& out, const Record& record);ofstream& WriteToBinaryFile(ofstream& out) const;ifstream& Record::ReadFromBinaryFile(ifstream& fin);void WriteToOstream(ostream& os) const;
public:char m_firstName[FIRST_NAME_LEN];char m_secondName[SECOND_NAME_LEN];char m_socialSecurity[SOCIAL_SECURITY_LEN];char m_departmentID[DEP_ID_LEN];int m_years;int m_salary;int m_averageSalary;int m_averageYears;
};
bool ReadTextEmployee(const string& textFileName, list<Record>& listEmployee);
void PrintAllEmployee(const list<Record>& listEmployee);
bool WriteEmployeeToBinaryFile(const list<Record>& listEmployee, const string& textFileName);
bool ReadBinaryEmployee(const string& fileName, list<Record>& listEmployee);
bool WriteEmployeeToTextFile(const list<Record>& listEmployee, const string& textFileName);
void CalculateAverage(list<Record>& listEmployee);
void PrintAllEmployeeWithAverage(const list<Record>& listEmployee);int main(int arcg, char** argv)
{list<Record> listEmployee;cout<<"ReadTextEmployee from employee.in"<<endl;if (!ReadTextEmployee("employee.in", listEmployee)){return -1;}PrintAllEmployee(listEmployee);cout<<"WriteEmployeeToBinaryFile to employee.binaryn"<<endl;WriteEmployeeToBinaryFile(listEmployee, "employee.binary");listEmployee.clear();cout<<"ReadBinaryEmployee from employee.binary"<<endl;ReadBinaryEmployee("employee.binary", listEmployee);PrintAllEmployee(listEmployee);CalculateAverage(listEmployee);PrintAllEmployeeWithAverage(listEmployee);WriteEmployeeToTextFile(listEmployee, "employee.out");return 0;
}
预期输出结果:

employee.ini
Bill Tarpon 182460678 789 8 30600
Fred Caldron 456905434 789 10 40700
Sally Bender 203932239 790 8 50000
David Kemp 568903493 790 9 60000

来吧!
C++中级程序员教程