organisation.txt
というテキストファイルから従業員番号(クラスに宣言せずに)、氏名、職種、部署を表示したいクラスOrganisationRecord
で宣言された変数。ファイルからデータを読み込んで変数に保存する
テキストファイルのデータをプルして対応する変数に保存するにはどうすればよいですか?ここで
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#define ORGANISATIONALRECORDSFILE "organisation.txt"
#define HRRECORDSFILE "HR_records.txt"
#define PAYROLLRECORDSFILE "payroll_records.txt"
using namespace std;
class OrganisationRecord
{
private:
public:
string name;
string occupation;
string department;
};
class HRRecord
{
private:
public:
string address;
string phonenumber;
string ninumber;
};
class PayrollRecord
{
private:
public:
string ninumber;
double salary;
};
class PayrollProcessing
{
private:
ifstream inputfile;
ofstream outputfile;
vector<OrganisationRecord> OrganisationRecords;
vector<HRRecord> HRRecords;
vector<PayrollRecord> PayrollRecords;
public:
void loadOrganisationRecords(string filename);
void loadHRRecords(string filename);
void loadPayrollRecords(string filename);
void displayEmployeeOfSalaryGTE(double salary);
//GTE = greater than or equal to
};
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)
{
while (inputfile >> _organisationrecord.name)
{
cout << _organisationrecord.name;
cout << _organisationrecord.occupation;
cout << _organisationrecord.department <<endl;
}
OrganisationRecords.push_back(_organisationrecord);
}
}
int main(void)
{
PayrollProcessing database1;
database1.loadOrganisationRecords(ORGANISATIONALRECORDSFILE);
return 0;
}
organisation.txt
0001
Stephen Jones
Sales Clerk
Sales
0002
John Smith
Programmer
OS Development
0003
Fred Blogs
Project Manager
Outsourcing
'私はそれをどのように行うことができますか?'私はあなたがエラーが、私はなぜあなたがしたいと思う」の明白な質問のほかに質問 – UKMonkey
です正確に何の状態に質問を言い換えるする必要があると思いますそれ? "、次の質問は、"あなたはクラスで宣言することなく、正確に何を意味していますか? "もしそれがそのタイプのレコードのための有効なデータであれば、本当にそれ自身のプロパティ/フィールドが設定されていなければなりません...また、あなたの命名規則、クラスの命名方法、あなたは会社を説明していますが、フィールドに基づいて、実際に従業員の情報を記述しています –
を編集した[OK]を – Taegost