<数据结构>运动会分数统计
2016-12-29 17:51
344 查看
#include<iostream> #include<iomanip> #include<string.h> #include<fstream> #include<stdlib.h> #include<ctype.h> #include<stdio.h> #include<conio.h> using namespace std; class School //学校 { private: char name[20]; int number; int boy; int girl; public: School *next; void School_add(); void School_sort(); // int School_getlong(School *first); void School_output(School *p); int School_isexist(int a); void School_show(int a); void School_search(int a); void School_addmark(int a, int b, int c); void School_order(School *temp, int type); }; class Sport //运动项目 { private: char name[20]; int isboy; //0为女项目,1为男项目 int is3; //0为取前五名,1为取前五名 int number; //项目编号 int first; // int second; // int third; // int fourth; // int fifth; // public: Sport *next; int Sport_isexist(int a); void Sport_add(); // int Sport_getlong(Sport *first); void Sport_output(Sport *p); void Sport_search(int a); }; School* head1; Sport* head2; void School::School_add() { School* p; int mark = 0; p = new School; cout << "请输入学校的名称:"; cin >> p->name; int c; while (mark != 1) { cout << "请输入学校编号:"; cin >> c; p->number = c; mark = 1; p->boy = 0; p->girl = 0; p->next = head1->next; head1->next = p; cout << "成功添加了一个学校" << endl; cout << "是否还要添加学校?(y/n)" << endl; char input; cin >> input; switch (input) { case 'y': mark = 0; School_add(); case 'n': mark = 1; return; } } delete p; } void School::School_output(School* p)//输出学校 { cout << "当前学校(名称) 编号 男团总分 女团总分 总分\t\n"; // School *p; p = head1; p = p->next; while (p) { cout << p->name << "\t\t" << p->number << "\t" << p->boy << "\t" << p->girl << " \t " << (p->girl + p->boy) << endl; p = p->next; } } int School::School_isexist(int a) { int b = 0; School* p; p = head1; p = p->next; while (p) { if (p->number == a) { return 1; } p = p->next; } return 0; } void School::School_show(int a)//输出所有学校 { School *p; p = head1; p = p->next; while (p) { if (p->number == a) { cout << p->name << " " << endl; return; } p = p->next; } cout << "无"; } void School::School_search(int a) { School* p; p = head1; p = p->next; while (p) { if (p->number == a) { cout << "学校名称:" << p->name << " " << "男子团体总分:" << p->boy << " " << "女子团体总分:" << p->girl << " " << "总分:" << (p->boy + p->girl) << " "; return; } p = p->next; } cout << "无此编号:" << endl; } void School::School_addmark(int a, int b, int c) //a为分数,b为学校编号,c=1表示男,c=0表示女 { School* p; p = head1; p = p->next; while (p) { if (p->number == b) { if (c == 1) { p->boy = p->boy + a; } else { p->girl = p->girl + a; } } p = p->next; } } void School::School_sort() //单独编写此排序函数。不难,有心即可。 { School* q, *small; School* temp1; temp1 = new School; temp1->next = NULL; q = head1; q = q->next; small = head1; small = small->next; temp1->girl = q->girl; q->girl = small->girl; small->girl = temp1->girl; temp1->boy = q->boy; q->boy = small->boy; small->boy = temp1->boy; strcpy_s(temp1->name, q->name); strcpy_s(q->name, small->name); strcpy_s(small->name, temp1->name); temp1->number = q->number; q->number = small->number; small->number = temp1->number; // } //此次设计,主要针对的是这一排序函数。 //将4处同段的代码另外独立编写成以上的一个函数School_sort()。如此,程序代码得到进一步精炼。 void School::School_order(School *temp, int type) { //type=0按总分,type=1按男总分,type=2按女总分,type=3按学校编号 School* q=NULL, *small=NULL; School* temp1; School sh; temp1 = new School; temp1->next = NULL; while (q&&small) { switch (type) { case 0: //按总分排序 for (q = head1; q = q->next; q != NULL) for (small = head1; small = small->next; small != NULL) { if ((q->boy + q->girl)<(small->boy + small->girl)) { sh.School_sort(); //调用排序函数School_sort(),不会是同样的大段代码到处都是。 } } break; case 1: //按男团体排序 for (q = head1; q = q->next; q != NULL) for (small = head1; small = small->next; small != NULL) { if (q->boy<small->boy) { sh.School_sort(); //调用排序函数School_sort(), } } break; case 2: //按女团体排序 for (q = head1; q = q->next; q != NULL) for (small = head1; small = small->next; small != NULL) { if (q->girl<small->girl) { sh.School_sort(); //调用排序函数School_sort(), } } break; case 3: for (q = head1; q = q->next; q != NULL) for (small = head1; small = small->next; small != NULL) { if (q->number<small->number) { sh.School_sort(); //调用排序函数School_sort(), } } break; default: cout << "error" << endl; break; } } } int Sport::Sport_isexist(int a) { int b = 0; Sport* p; p = head2; while (p) { if (p->number == a) { return 1; } p = p->next; } return 0; } void Sport::Sport_add() { Sport* p; // School sh; int mark = 0; p = new Sport; cout << "请输入项目名称:"; cin >> p->name; int c; while (mark != 1) { cout << "请输入项目编号:"; cin >> c; if (Sport_isexist(c)) { cout << "该编号已存在!"; } else { mark = 1; p->number = c; } } mark = 0; while (mark != 1) { cout << "请输入项目类型(0为女子项目,1为男子项目):"; cin >> c; // p->isboy=(int)(c-'0');//字符转换成数字 mark = 1; p->isboy = c; } mark = 0; while (mark != 1) { cout << "请输入项目名称情况(0为取前3名,1为取前5名):"; cin >> c; // p->is3=(int)(c-'0'); mark = 1; p->is3 = c; } mark = 0; School sh; while (mark != 1) { cout << "请输入第一名学校的编号:"; cin >> c; if (!sh.School_isexist(c)) { cout << "该学校不存在,请先添加!"; } else { mark = 1; p->first = c; if (p->is3 == '0') sh.School_addmark(5, c, p->isboy); else sh.School_addmark(7, c, p->isboy); } } mark = 0; while (mark != 1) { cout << "请输入第二名学校的编号:"; cin >> c; if (!sh.School_isexist(c)) { cout << "该学校不存在,请先添加!"; } else { mark = 1; p->second = c; if (p->is3 == '0') sh.School_addmark(3, c, p->isboy); else sh.School_addmark(5, c, p->isboy); } } mark = 0; while (mark != 1) { cout << "请输入第三名学校的编号:"; cin >> c; if (!sh.School_isexist(c)) { cout << "该学校不存在,请先添加"; } else { mark = 1; p->third = c; if (p->is3 == '0') sh.School_addmark(2, c, p->isboy); else sh.School_addmark(3, c, p->isboy); } } mark = 0; if (p->is3 == '1') { while (mark != 1) { cout << "请输入第四名学校的编号:"; cin >> c; if (!sh.School_isexist(c)) { cout << "该学校不存在,请先添加"; } else { mark = 1; p->fourth = c; sh.School_addmark(2, c, p->isboy); } } mark = 0; while (mark != 1) { cout << "请输入第五名学校的编号:"; if (!sh.School_isexist(c)) { cout << "该学校不存在,请先添加!"; } else { mark = 1; p->fifth = c; sh.School_addmark(1, c, p->isboy); } } } else { p->fourth = '0'; p->fifth = '0'; } p->next = head2->next; head2->next = p; cout << "成功添加了一个运动项目" << endl; } void Sport::Sport_output(Sport *p) //输出项目的情况 { p = head2; p = p->next; cout << "当前项目名称" << "\t" << "编号" << " " << "B/G" << " " << "3/5" << " " << "第一名" << " " << "第二名" << " " << "第三名" << " " << "第四名" << " " << "第五名" << " " << endl; School sh; while (p) { cout << p->name << "\t" << " " << p->number << " " << p->isboy << " " << p->is3 << " " << " "; sh.School_show(p->first); sh.School_show(p->second); sh.School_show(p->third); sh.School_show(p->fourth); sh.School_show(p->fifth); p = p->next; cout << "\n"; } cout << endl; } void Sport::Sport_search(int a) //搜索项目 { Sport *p; School sh; p = head2; p = p->next; while (p) { if (p->number == a) { cout << "项目名:" << p->name << endl << "项目类型:"; if (p->isboy == 1) { cout << "男子项目"; } else { cout << "女子项目"; } cout << endl << "第一名:"; sh.School_show(p->first); cout << endl << "第二名:"; sh.School_show(p->second); cout << endl << "第三名:"; sh.School_show(p->third); cout << endl << "第四名:"; sh.School_show(p->fourth); cout << endl << "第五名:"; sh.School_show(p->fifth); return; } p = p->next; } cout << "无此编号"; } void main() { system("color C"); head1 = new School; head1->next = NULL; head2 = new Sport; head2->next = NULL; //school_add(); School sh; Sport sp; School* p1; Sport* p2; p1 = head1; p1 = p1->next; p2 = head2; p2 = p2->next; int choose; char temp; int a = 1; while (a != 0) { cout << " " << endl; cout << " 欢迎使用运动会分数统计系统 " << endl; cout << " ----------------------------------------------------------" << endl; cout << " -----July制作/05/18---- " << endl; cout << " " << endl; cout << " 1.输入学校; 2.输入运动项目 " << endl; cout << " 3.按学校编号输出总分; 4.按学校总分排序; " << endl; cout << " 5.按男团体总分排序; 6.按女团体总分排序; " << endl; cout << " 7.按学校编号查询; 8.按项目编号查询; " << endl; cout << " 0.退出 " << endl; cout << " 注:输入运动项目之前请输入学校 " << endl; cout << " ----------------------------------------------------------" << endl; cout << " -------请选择(0-8):------ " << endl; cin >> choose; switch (choose) { case 1: sh.School_add(); break; case 2: sp.Sport_output(p2); sh.School_output(p1); sp.Sport_add(); break; case 3: sh.School_order(p1, 3); sh.School_output(p1); break; case 4: sh.School_order(p1, 0); sh.School_output(p1); break; case 5: sh.School_order(p1, 1); sh.School_output(p1); break; case 6: sh.School_order(p1, 2); sh.School_output(p1); break; case 7: cout << "请输入学校编号:"; cin >> temp; sh.School_search(temp); break; case 8: cout << "请输入项目编号:"; cin >> temp; sp.Sport_search(temp); break; case 0: a = 0; break; default: cout << "操作非法\n"; } } system("exit"); }
相关文章推荐
- 数据结构运动会分数统计实习报告源码
- 【嵙大OJ】<未完成:运行无误>Problem 1178: 分数统计
- 数据结构 运动会分数统计
- 数据结构-运动会分数统计
- 数据结构-运动会分数统计
- [置顶] 运动会分数统计(数据结构课程设计)
- 数据结构实习报告(运动会分数统计)
- 运动会分数统计
- Scala学习笔记<基本数据结构>
- 数据结构实例<七>(Left-Pad 左填充)容易
- 数据结构复习:用自己的方式实现List<T>(4/1晨更新)
- 定义分数类中<<和>>运算符重载,实现分数的输入输出,改造原程序中对运算结果显示方式,使程序读起来更自然。
- 数据结构 (1) ——线性表 <IT小鸟每日一遍>
- 用java源代码学数据结构<三>:ArrayList 详解
- 静态网页,JS代码 统计网站访问量<也支持html>
- 第九周任务三之定义分数类中<<和>>运算符重载,实现分数的输入输出
- 数位统计 sgu 390 <浅谈数位类问题>
- ②泡茶看<数据结构>,喜欢看源码-栈ADT
- (bzoj 3688 折线统计)<DP>
- C/C++版数据结构之树<一>