//** student.h ** #include iostream.h #include string.h #ifndef STUDENT #define STUDENT class Student{ //大学生类 protected: char pName[20]; unsigned int uID; float grade; public: Student(char* pS, unsigned num, float g) { strcpy(pName,pS); uID=num; grade=g; } virtual void display(ostream out); }; ostream operator(ostream out, Student st); #endif //** student.cpp ** #include student.h #include iomanip.h #include iostream.h void Student::display(ostream out) { out setiosflags(ios::left)setw(20)pName uID , setiosflags(ios::right) setw(4)grade; } //插入操作符 ostream operator(ostream out, Student st) { st.display(out); out endl; return out; } //******************** //** master.h ** //******************** #include student.h #include iostream.h //硕士生类 class MasterStudent: public Student{ protected: char type; public: MasterStudent(char* pS, unsigned num, float g, char t) :Student(pS,num,g),type(t){} void display(ostream out); }; //master.cpp #include iostream.h #include master.h void MasterStudent::display(ostream out) { Student::display(out); out , type; } //*********************** //** ch19_15.cpp ** //*********************** #include fstream.h #include student.h #include master.h int main() { ofstream out(e:\\bctemp\\abc.txt); Student s1(Dill Arnson, 12567, 3.5); MasterStudent s2(Welch Shammas, 12667, 4.1, A); MasterStudent s3(Portel Braumbel, 12579, 3.8, B); out s1; out s2; out s3; } * 19.9 文件操作 运行结果可以在打开的文件中看到: e:\type abc.txt Dill Arnson 12567, 3.5 Welch Shammas 12667, 4.1, A Portel Braumbel 12579, 3.8, B * 19.9 文件操作 2.文件输入:读文件 如果要打开一个文件用于输入,可以用ifstream类。假定文件abc.txt中的内容为: Dill Arnson 12567,3.5 Welch Shammas 12667,4.1,A P
您可能关注的文档
- 第18章商品检验、索赔、不可抗力和仲裁试卷.ppt
- 第十三章文学风格辨析.ppt
- 班组长技能提升训练最新.ppt
- 班组长培训最新.ppt
- 第十三章学习障碍儿童的教育(方俊明特殊教育学)辨析.ppt
- 第十三章预算管理体制辨析.ppt
- 第十三章罪数辨析.ppt
- 第十四单元人民解放战争的胜利辨析.ppt
- 第19讲-归纳推理和类比推理试卷.ppt
- 第十四课人生价值与劳动奉献辨析.ppt
- 全过程工程管理造价咨询工程监理项目服务方案投标方案(技术部分).doc
- 招标代理服务投标技术服务方案(技术方案).doc
- AI大模型与AIGC技术在公安领域的应用解决方案(99页 PPT).pptx
- 工业4.0智能制造数字工厂规划方案.pptx
- 树立社会主义核心价值观.docx
- 三年(2023-2025)中考历史真题分类汇编(全国)专题21 科技文化与社会生活(解析版).docx
- 2025年中考道德与法治真题完全解读(吉林卷).pdf
- 2025年中考道德与法治真题完全解读(安徽卷).pdf
- 三年(2023-2025)中考历史真题分类汇编(全国)专题14 人民解放战争(解析版).pdf
- 三年(2023-2025)广东中考历史真题分类汇编:专题03 中国近代史(八年级上册)(解析版).docx
原创力文档

文档评论(0)