ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:20.11KB ,
资源ID:10390233      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10390233.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C大作业学生信息管理系统附代码.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C大作业学生信息管理系统附代码.docx

1、C大作业学生信息管理系统附代码 学生信息管理系统(附代码)题目要求:设计一个类CStudent,类中包含一个学生的基本数据如下:编号,姓名,性别,年龄,数学成绩,计算机成绩,外语成绩。 并假设编号为整数,且从1号往后连续编码;姓名为字符串,性别为字符。如: 1 LiPing m 18 89 98 94请采用binary文件形式,并使用随机读写处理方式,对自定义CStudent类的对象数据进行存储与读写处理(即是说,总按具有连续编码的编号 num为“序”来对文件中的各对象数据进行随机读写处理)。并设计该类的成员函数,而且对输出运算符“”进行重载,使该运算符能够完成将一个学生的信息输出到屏幕上。要

2、求成员函数完成以下功能:(1) 从键盘输入一个学生的有关信息,并将它们存入到数据文件中(按编号来确定写出位置)。(2) 按编号对学生信息进行检索并将检索结果显示在屏幕上。(3) 按姓名对学生信息进行检索并将检索结果显示在屏幕上。(4) 计算某编号学生的总成绩与平均成绩。(5) 列出所有总成绩超过n分的性别为s同学的有关信息(n,s由用户从键盘输入)。 Code: 1. /* 2. *名称: student.cpp * 3. *描述: 学生管理程序 * 4. *功能: 添加,修改,按条件查询学生信息 * 5. *环境: Fedora Linux 11 & GCC & x86 * 6. *备注:

3、davelv第一次Class于2010-01-10 * 7. *更新: 新建了可复用的搜索模板searchframe * 8. */ 9. 10. #include 11. #include 12. #include 13. #include 14. #include 15. 16. using namespace std; 17. #define CIN_LEN 1024/缓冲区长度 18. #define data/数据文件名 19. / 20. / 结构和类 / 21. / 22. struct data/学生个人信息 23. 24. int id;/学号 25. char name20

4、;/名字 26. char major20;/专业 27. char sex;/性别 28. double ch,en,ma;/成绩 29. int grade;/年级 30. ; 31. 32. class CStudent 33. 34. protected: 35. bool altered;/是否修改 36. data info;/学生信息 37. public: 38. static int nowid ;/新学生自增id 39. static void displayhead();/显示表头 40. static void displayshorthead();/显示短表头 41.

5、 CStudent();/构造 42. void displayinfo();/显示全部学生信息 43. void displayshortinfo();/显示学生短信息 44. double getsum();/取总成绩 45. double getave();/取得平均分 46. double getch();/取语文成绩 47. double geten();/取外语成绩 48. double getma();/取数学成绩 49. int set(bool isnew);/设置学生信息 50. int getgrade();/取年级 51. int getid();/取学号 52. bo

6、ol isaltered();/取是否修改 53. char getsex();/取性别 54. char* getname();/取姓名 55. char* getmajor();/取专业 56. data* getinfo();/取学生全部信息 57. /定义友元函数以便重载运算符 58. friend ostream& operator(istream&,CStudent&); 60. 61. ; 62. 63. int CStudent:nowid = 1;/初始化类静态成员 64. 65. CStudent:CStudent()/基类构造 66. 67. info.id=CStude

7、nt:nowid+;/子增id 68. strcpy(info.name,None);/名字 69. info.ch=0;/语文成绩 70. info.en=0;/外语成绩 71. info.ma=0;/数学成绩 72. info.grade=1;/年级 73. altered=false;/未被修改 74. 75. 76. int CStudent:getgrade() 77. 78. return info.grade; 79. 80. 81. double CStudent:getsum() 82. 83. return info.ch+info.en+info.ma; 84. 85.

8、double CStudent:getave() 86. 87. return (info.ch+info.en+info.ma)/3; 88. 89. double CStudent:getch() 90. 91. return info.ch; 92. 93. 94. double CStudent:geten() 95. 96. return info.en; 97. 98. 99. double CStudent:getma() 100. 101. return info.ma; 102. 103. 104. int CStudent:getid() 105. 106. return

9、info.id; 107. 108. 109. char CStudent:getsex() 110. 111. return info.sex; 112. 113. 114. char * CStudent:getname() 115. 116. return info.name; 117. 118. bool CStudent:isaltered() 119. 120. return altered; 121. 122. data *CStudent:getinfo() 123. 124. return &info; 125. 126. void CStudent:displayinfo(

10、) 127. 128. cout*thistgetsum()tgetave()endl;/利用重载运算符输出 129. 130. void CStudent:displayshortinfo() 131. 132. cout *thisendl; 133. 134. void CStudent:displayhead() 135. 136. coutnt学号t姓名t性别t专业t年级t中文t英文t数学t总分t平均分n; 137. 138. void CStudent:displayshorthead() 139. 140. coutnt学号t姓名t性别t专业t年级t中文t英文t数学n; 141.

11、 142. int CStudent:set(bool isalter) 143. 144. cout输入学生信息:n; 145. displayshorthead(); 146. if (isalter) 147. displayshortinfo(); 148. couttinfo.id *this;/从标准输入获取学生信息 151. altered=true;/已修改 152. 153. if(cin.fail() 154. 155. cout录入失败n; 156. cin.clear(); 157. cin.ignore(CIN_LEN,n);/这两行是用来清空输入缓冲 158. re

12、turn -1; 159. 160. else 161. 162. cout录入成功n; 163. return 1; 164. 165. 166. 167. /重载输出符 168. ostream &operator(ostream& out,const CStudent &right) 169. 170. /输出学生的全部信息 171. out tright.info.idtright.info.nametright.info.sext 172. right.info.majortright.info.gradetright.info.cht 173. right.info.ent(ist

13、ream& in,CStudent& right) 178. 179. /输入除ID外的其他信息 180. in right.info.nameright.info.sexright.info.major 181. right.info.graderight.info.chright.info.enright.info.ma; 182. return in; 183. 184. 185. / 186. / 初始化函数 / 187. / 188. int initial(vector &stu) 189. 190. fstream 输入文件 191. CStudent *p; 192. 193.

14、 (, fstream:in|fstream:binary);/二进制输入打开 194. 195. if (!文件是否打开成功 196. return -1; 197. while( ()!=EOF )/是否到文件末尾 198. 199. p=new CStudent();/新建一个学生对象 200. (char*) p-getinfo(),sizeof(data);/读入学生对象 201. if()/检查读入是否失败 202. return -2; 203. stu.push_back(p);/对象加入vector 204. 205. if(!stu.empty()/如果从文件读入了对象 2

15、06. CStudent:nowid = stu.back()-getid()+1;/则自增id设置为最后一个学生id+1 207. ();/关闭 208. return stu.size();/返回对象个数 209. 210. / 211. / 信息增加函数 / 212. / 213. void insert(vector &stu) 214. 215. char c=y;/输入控制字符 216. 217. int flag = 1;/标志位,1表示新增成功 218. 219. CStudent *p=new CStudent(); 220. 221. while(c != n)/是否继续新

16、增 222. 223. flag = p-set(false);/设置学生信息 224. if( flag = 1 )/如果设置成功 225. 226. stu.push_back(p);/对象加入vector 227. p = new CStudent();/新建下一个对象 228. 229. cout getid(); 252. 253. / 254. / 按姓名比较函数 / 255. / 256. int comparebyname(const void *a, const void *b ) 257. 258. return strcmp(const char *)a, (const

17、char *)(CStudent *)b)-getname(); 259. 260. / 261. / 按年级比较函数 / 262. / 263. int comparebygrade(const void *a, const void *b) 264. 265. return (*(const int *)a - (CStudent *)b)-getgrade(); 266. 267. / 268. / 按总分和性别比较函数 / 269. / 270. int comparebymarkandsex(const void *a, const void *b) 271. 272. double

18、 mark; 273. char sex; 274. sscanf(const char*)a,%lf%c,&mark,&sex); 275. return !( 276. ( (CStudent*)b)-getsum() = mark ) 277. & ( (sex =n) | (sex = (CStudent*)b)-getsex() ) 278. ); 279. 280. 281. 282. / 283. / 搜索模板 / 284. / 285. template 286. void searchframe(const char *info, T &condition ,vector &

19、stu, int (*compare)(const void *a, const void *b) ,bool isalter) 287. 288. char c=y; 289. int flag; 290. while(c != n) 291. 292. cin.clear(); 293. 294. if(info != NULL) 295. 296. cout 输入infocondition; 299. 300. 301. if(cin.fail() 302. 303. cout 输入错误n; 304. 305. else 306. 307. /遍历vector查找 308. for(ve

20、ctor:size_type ix =flag=0; ix!=stu.size(); +ix) 309. /判断是name是否相等 310. if(compare(&condition,stuix) = 0) 311. 312. if( isalter ) 313. stuix-set(isalter); 314. else 315. 316. if(flag = 0) 317. CStudent:displayhead(); 318. stuix-displayinfo(); 319. 320. flag = 1; 321. 322. 323. if (flag = 0)/没有查到 324.

21、 325. cout没有; 326. if(info = NULL) 327. cout符合条件; 328. else 329. coutinfo为condition; 330. cout的学生n; 331. 332. 333. cout 是否继续(any/n)?; 334. cin.clear(); 335. cin.ignore(CIN_LEN,n); 336. cin.get(c); 337. 338. 339. 340. / 341. / 信息检索函数 / 342. / 343. void fetch(vector &stu) 344. 345. int choose,id,grade

22、; 346. char name20,markandsex20; 347. 348. while (true) 349. 350. cout nt1.显示全部学生信息n 351. t2.按学号查学生信息n 352. t3.按姓名查学生信息n 353. t4.按年级查学生信息n 354. t5.按成绩和性别查询n 355. t6.返回上级菜单nn; 356. lchoose: 357. coutchoose; 360. switch(choose) 361. 362. case 1 :searchframe(NULL,choose,stu,comparebynone,false); break; 363. case 2 :searchframe(学号,id,stu,comparebyid,false); break; 364. case 3 :searchframe(姓名,name,stu,comparebyname,false); break; 365. case 4 :searchframe(年级,grade,stu,comparebygrade,false); break; 366. c

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1