1、     在实验3的基础上,重载运算符<<、>>,实现信息的文件读写操作;

2、 实现一个win32控制台的应用程序,可以对学校人员的信息文件的读写操作。

学校人员信息文件读写_C++学校人员信息文件读写_C++_02
 1 void TDate::ReadFile(ifstream&  Infile)
 2 {
 3     Infile >> Year >> Month >> Day;
 4 }
 5 void TDate::WriteFile(ofstream& OutFile)
 6 {
 7     OutFile << Year << " " << Month << " " << Day << " ";
 8 }
 9 void Person::ReadFile(ifstream& InFile)
10 {
11     InFile >> ID >> Name >> Sex;
12     Birthday.ReadFile(InFile);
13 }
14 void Person::WriteFile(ofstream& OutFile)
15 {
16     OutFile << ID << " " << Name << " " << Sex << " ";
17     Birthday.WriteFile(OutFile);
18 }
19 void Teacher::ReadFile(ifstream& InFile)
20 {
21     Person::ReadFile(InFile);
22     InFile >> Title >> Dept;
23 }
24 void Teacher::WriteFile(ofstream& OutFile)
25 {
26     Person::WriteFile(OutFile);
27     OutFile << Title << " " << Dept << " ";
28 }
29 void Student::ReadFile(ifstream& InFile)
30 {
31     Person::ReadFile(InFile);
32     InFile >> Grade >> Major;
33 }
34 
35 void Student::WriteFile(ofstream& OutFile)
36 {
37     Person::WriteFile(OutFile);
38     OutFile << Grade << " " << Major << " ";
39 }
40 ofstream& operator<<(ofstream& strefile, Person& obj)
41 {
42     obj.WriteFile(strefile);
43     strefile << endl;
44     return strefile;
45 }
46 ifstream& operator>>(ifstream& strefile,  Person& obj)
47 {
48     obj.ReadFile(strefile);
49     return strefile;
50 }
View Code