当前位置:   article > 正文

数据结构课设----运动会分数统计系统(C++版)(优化版)_数据结构运动会分数统计

数据结构运动会分数统计

目录

 

1.优化内容

2.部分代码

3.完整代码

4.运行截图


ps:如果要实验报告或者ppt可告诉我。

优化内容

优化内容

1.增加了修改功能

2.文件输入到文本文档为字符流

3.将各个菜单美化

部分代码

 菜单函数

  1. void menu(int n, int m, int w)
  2. {//n代表学校数,m代表男子数,w代表女子数
  3. int c;
  4. void input(int n, int m, int w);//输入功能
  5. void output(int n, int m, int w);//输出功能
  6. void sortput(int n, int m, int w);//排序输出
  7. void search(int n, int m, int w);//查询功能
  8. void modify(int n, int m, int w);//修改功能
  9. cout<<"\t\t***********欢迎使用***********"<<endl;
  10. cout<< "\t\t******************************" << endl;
  11. cout<<"\t\t***** 运动会分数统计系统 *****"<<endl;
  12. cout <<"\t\t** **"<< endl;
  13. cout<<"\t\t** 1.信息输入 **"<<endl;
  14. cout<<"\t\t** 2.统计输出 **" << endl;
  15. cout<<"\t\t** 3.排序输出 **" << endl;
  16. cout<<"\t\t** 4.信息查询 **"<<endl;
  17. cout<<"\t\t** 5.修改功能 **"<<endl;
  18. cout<<"\t\t** 6.退出系统 **"<< endl;
  19. cout<<"\t\t** **"<< endl;
  20. cout<<"\t\t******************************" << endl;
  21. cout<<"\t\t******************************" << endl;
  22. cout << endl;
  23. cout<<"======================================================="<<endl;
  24. cout << endl;
  25. cout<<"请输入您想要实现的功能(1--6):"<<endl;
  26. cin >> c;
  27. switch (c) {
  28. case 1:
  29. input(n, m, w);
  30. break;
  31. case 2:
  32. output(n, m, w);
  33. break;
  34. case 3:
  35. sortput(n, m, w);
  36. break;
  37. case 4:
  38. search(n, m, w);
  39. break;
  40. case 5:
  41. modify(n, m, w);
  42. break;
  43. case 6:
  44. cout<<"感谢使用,祝您天天开心!!"<<endl;
  45. exit(0);//正常退出
  46. default:
  47. cout<<"您输入有误,请重新输入!";
  48. menu(n, m, w);
  49. }
  50. }

 写入、写出、删除 文件

  1. //将信息写入文件中
  2. void savetofile(int n, int w, int m)
  3. {
  4. ofstream file("file.txt", ios::app | ios::in | ios::out | ios::binary);
  5. if (file.fail()) {
  6. cout << "打开失败" << endl;
  7. }
  8. for (int i = 0; i < n; i++) {
  9. for (int j = 0; j < w + m; j++)
  10. for (int z = 0; z < 5; z++) {
  11. {
  12. file <<"学校编号:" << a[i].snum <<" "<<"学校名字:" << a[i].sname<<" "<<"学校总分:" << a[i].score <<" "<<"男子总分:" <<a[i].mscore <<" " <<"女子总分:" <<a[i].wscore <<" "<<"项目编号:" <<a[i].t[j].inum <<" "<<"项目取前" << a[i].t[j].top <<"名" << " " << "项目名次:" << a[i].t[j].range[z] << " " << "项目总分:" << a[i].t[j].mark[z] << endl;
  13. }
  14. }
  15. }
  16. file.close();
  17. }
  18. //将信息从文件里取出
  19. void readfromfile(int n,int w,int m)
  20. {
  21. ifstream file("file.txt", ios::app | ios::in | ios::out | ios::binary);
  22. }
  23. //将信息从文件里删除
  24. void deletefile() {
  25. // string file_path = "file.txt";
  26. //remove(file_path.c_str());
  27. ofstream file("file.txt", ios_base::out | ios_base::trunc);
  28. file << "";
  29. file.close();
  30. }

 信息输入功能

  1. //信息输入功能
  2. void input(int n, int m, int w)
  3. {
  4. int i, j, s, k, q = 1;
  5. for (i = 0; i < n; i++) {
  6. cout<<"请输入学校的编号和学校的名字:"<<endl;
  7. cin >> a[i].snum>>a[i].sname;
  8. for (j = 0; j < m + w; j++) {//总的项目的输入
  9. cout << "请输入项目编号:";
  10. cin>> a[i].t[j].inum;
  11. if (a[i].t[j].inum % 2 == 0) {
  12. cout<<"编号为偶数取前三" << endl;
  13. cout << "获得的名次的个数(1--5):";
  14. }
  15. else if (a[i].t[j].inum % 2 == 1) {
  16. cout <<"编号为奇数的项目取前五"<<endl;
  17. cout << "获得的名次的个数(1--5):";
  18. }
  19. else {
  20. cout << "输入有误!程序退出....";
  21. return;
  22. }
  23. cin >> k;//输入获得名次的个数
  24. for (s = 0; s < k; s++) {
  25. if(a[i].t[j].inum % 2 == 0){
  26. cout<<"请输入获得的名次(1--3):";
  27. }
  28. else {
  29. cout<<"请输入获得的名次(1--5):";
  30. }
  31. cin >> a[i].t[j].range[s];//输入所获得的名次的信息
  32. }
  33. cout << endl;
  34. }
  35. }
  36. for (i = 0; i < n; i++) {
  37. //初始化分数
  38. a[i].score = 0;//学校总分
  39. a[i].mscore = 0;//男子总分
  40. a[i].wscore = 0;//女子总分
  41. }
  42. for (i = 0; i < n; i++) {
  43. for (j = 0; j < m + w; j++) {
  44. if (a[i].t[j].inum % 2 == 1) {
  45. a[i].t[j].top = 5;
  46. cout << "项目" << j + 1 << "取得是前:"<< a[i].t[j].top <<"名"<<endl;
  47. }
  48. else if (a[i].t[j].inum % 2 == 0) {
  49. a[i].t[j].top = 3;
  50. cout << "项目" << j + 1 << "取得是前:" << a[i].t[j].top << "名" << endl;;
  51. }
  52. for (s = 0; s < 5; s++) {
  53. if (a[i].t[j].top == 3) {
  54. switch (a[i].t[j].range[s]) {
  55. case 0:
  56. a[i].t[j].mark[s] = 0;
  57. break;
  58. case 1:
  59. a[i].t[j].mark[s] = 5;
  60. break;
  61. case 2:
  62. a[i].t[j].mark[s] = 3;
  63. break;
  64. case 3:
  65. a[i].t[j].mark[s] = 2;
  66. break;
  67. }
  68. }
  69. else if (a[i].t[j].top == 5) {
  70. switch (a[i].t[j].range[s]) {
  71. case 0:
  72. a[i].t[j].mark[s] = 0;
  73. break;
  74. case 1:
  75. a[i].t[j].mark[s] = 7;
  76. break;
  77. case 2:
  78. a[i].t[j].mark[s] = 5;
  79. break;
  80. case 3:
  81. a[i].t[j].mark[s] = 3;
  82. break;
  83. case 4:
  84. a[i].t[j].mark[s] = 2;
  85. break;
  86. case 5:
  87. a[i].t[j].mark[s] = 1;
  88. break;
  89. }
  90. }
  91. a[i].score = a[i].score + a[i].t[j].mark[s];//学校总分
  92. if (j < m) {
  93. a[i].mscore = a[i].mscore + a[i].t[j].mark[s];
  94. }
  95. else {//女子总分
  96. a[i].wscore = a[i].wscore + a[i].t[j].mark[s];
  97. }
  98. }
  99. }
  100. }
  101. cout<<"输入完毕!(返回菜单请输入1):";
  102. cin >> q;
  103. cout << endl;
  104. if (q != 1) {
  105. cout<<"不能再添加信息了!";
  106. }
  107. cout << endl;
  108. savetofile(n,w,m);//保存文件
  109. menu(n, m, w);
  110. }

 信息输出功能

  1. //信息输出功能
  2. void output(int n, int m, int w) /*2.统计输出*/
  3. {
  4. readfromfile(n,m,w);
  5. int i, j, s, q = 0;
  6. for (i = 0; i < n; i++) /*显示结果*/
  7. {
  8. cout << "学校编号:" << a[i].snum << " ";
  9. cout << "学校名字:" << a[i].sname << " ";
  10. cout << "学校总分:" << a[i].score << endl;
  11. cout << "男子总分:" << a[i].mscore <<" " << "女子总分:" << a[i].wscore << endl;
  12. for (j = 0; j < m + w; j++)
  13. {
  14. cout << "项目编号:" << a[i].t[j].inum <<" " << "所取名次取前:" << a[i].t[j].top<<"名"<< endl;
  15. for (s = 0; s < 5; s++)
  16. {
  17. if (a[i].t[j].range[s] != 0)
  18. cout<<"名次:"<< a[i].t[j].range[s] <<" " << "分数:"<< a[i].t[j].mark[s]<<" "<<endl;
  19. }
  20. }
  21. cout << endl;
  22. }
  23. cout<<"\n";
  24. cout<<"统计完毕!返回? 1是 2否"; /*返回菜单*/
  25. cin >> q;
  26. cout << endl;
  27. if (q != 1)
  28. cout<<"统计已经结束!";
  29. cout << endl;
  30. menu(n, m, w);
  31. }

 排序输出

  1. //排序输出
  2. void sortput(int n, int m, int w)//n为学校数,m为男子数,w为女子数
  3. {
  4. readfromfile(n,m,w);
  5. int c, i, j, k, q = 0;
  6. int temp[N]={};
  7. cout<<"\t\t***** 排序输出系统 *****"<< endl;
  8. cout<<"\t\t************************"<< endl;
  9. cout<<"\t\t** **"<< endl;
  10. cout<<"\t\t** 1.按学校编号输出 **"<< endl;
  11. cout<<"\t\t** 2.按学校总分输出 **"<<endl;
  12. cout<<"\t\t** 3.按男子总分输出 **"<<endl;
  13. cout<<"\t\t** 4.按女子总分输出 **"<<endl;
  14. cout<<"\t\t** **"<< endl;
  15. cout<<"\t\t************************"<< endl;
  16. cout<<"\t\t************************"<< endl;
  17. cout<<"======================================================="<<endl;
  18. cout << endl;
  19. do {
  20. cout<<"请选择您想实现的功能的编号(1--4):";
  21. cin >> c;
  22. switch (c) {
  23. case 1:
  24. for (i = 0; i < n; i++) {
  25. temp[i] = i;
  26. }
  27. //用的是冒泡排序输出
  28. for (i = 0; i < n; i++) {
  29. for (j = i + 1; j < n; j++) {
  30. if (a[temp[i]].snum > a[j].snum) {
  31. k = temp[i];
  32. temp[i] = temp[j];
  33. temp[j] = k;
  34. }
  35. }
  36. }
  37. for (i = 0; i < n; i++) {
  38. cout << "学校编号:" << a[temp[i]].snum <<" " << "学校名字" << a[temp[i]].sname << " " << "学校总分:" << a[temp[i]].score << endl;
  39. cout << "男子总分" << a[temp[i]].mscore << " " << "女子总分:" << a[temp[i]].wscore << endl;
  40. }
  41. break;
  42. case 2:
  43. for (i = 0; i < n; i++) {
  44. temp[i] = i;
  45. }
  46. for (i = 0; i < n; i++) {
  47. for (j = i + 1; j < n; j++) {
  48. if (a[temp[i]].score < a[j].score) {
  49. k = temp[i];
  50. temp[i] = temp[j];
  51. temp[j] = k;
  52. }
  53. }
  54. }
  55. for (i = 0; i < n; i++) {
  56. cout << "学校编号:" << a[temp[i]].snum << " " << "学校名字" << a[temp[i]].sname <<" " << "学校总分:" << a[temp[i]].score << endl;
  57. cout << "男子总分" << a[temp[i]].mscore << " " << "女子总分:" << a[temp[i]].wscore << endl;
  58. }
  59. break;
  60. case 3:
  61. for (i = 0; i < n; i++) {
  62. temp[i] = i;
  63. }
  64. for (i = 0; i < n; i++) {
  65. for (j = i + 1; j < n; j++) {
  66. if (a[temp[i]].mscore < a[j].mscore) {
  67. k = temp[i];
  68. temp[i] = temp[j];
  69. temp[j] = k;
  70. }
  71. }
  72. }
  73. for (i = 0; i < n; i++) {
  74. cout << "学校编号:" << a[temp[i]].snum << " " << "学校名字" << a[temp[i]].sname << " " << "学校总分:" << a[temp[i]].score << endl;
  75. cout << "男子总分" << a[temp[i]].mscore << " " << "女子总分:" << a[temp[i]].wscore << endl;
  76. }
  77. break;
  78. case 4:
  79. for (i = 0; i < n; i++) {
  80. temp[i] = i;
  81. }
  82. for (i = 0; i < n; i++) {
  83. for (j = i + 1; j < n; j++) {
  84. if (a[temp[i]].wscore < a[j].wscore) {
  85. k = temp[i];
  86. temp[i] = temp[j];
  87. temp[j] = k;
  88. }
  89. }
  90. }
  91. for (i = 0; i < n; i++) {
  92. cout << "学校编号:" << a[temp[i]].snum << " " << "学校名字" << a[temp[i]].sname << " " << "学校总分:" << a[temp[i]].score << endl;
  93. cout << "男子总分" << a[temp[i]].mscore << " " << "女子总分:" << a[temp[i]].wscore << endl;
  94. }
  95. break;
  96. default:
  97. cout<<"您的输入有误!请从新输入...";
  98. }
  99. cout<<"请选择 1.返回主菜单 0.继续";
  100. cin >> q;
  101. cout << endl;
  102. }
  103. while (0 == q);
  104. cout << endl;
  105. if (q != 0) {
  106. menu(n, m, w);
  107. }
  108. }

 查询功能

  1. //查询功能
  2. void search(int n, int m, int w)
  3. {
  4. readfromfile(n,m,w);
  5. int c, i, j, k, d, l, q = 0;
  6. cout<<"\t\t********查询系统********"<<endl;
  7. cout << "\t\t************************"<< endl;
  8. cout << "\t\t** **"<< endl;
  9. cout << "\t\t** 1.按学校编号查询 **"<<endl;
  10. cout << "\t\t** 2.按项目编号查询 **"<< endl;
  11. cout << "\t\t** **" << endl;
  12. cout << "\t\t************************"<< endl;
  13. cout << "\t\t************************"<< endl;
  14. cout << "=======================================================" << endl;
  15. cout << endl;
  16. do
  17. {
  18. k = -1; d = -1; l = -1;
  19. cout << "请选择要实现功能的编号(1--2):";
  20. cin >> c;
  21. switch (c) {
  22. case 1:
  23. cout << "要查询的学校编号:"; /*查找学校编号下标*/
  24. cin >> c;
  25. for (i = 0; i < n; i++) {
  26. if (c == a[i].snum) {
  27. k = i;
  28. }
  29. }
  30. if (-1 == k) {
  31. cout << "错误:这个学校没有参加此次运动会!" << endl;
  32. }
  33. else {
  34. cout << "要查询的项目编号:"; /*查找项目编号下标*/
  35. cin >> c;
  36. for (j = 0; j < m + w; j++) {
  37. if (c == a[k].t[j].inum) {
  38. d = j;
  39. }
  40. }
  41. if (-1 == d) {
  42. cout << "此次运动会没有这个项目" << endl;
  43. }
  44. else {
  45. cout << "这个项目取前" << a[k].t[d].top << "名,该学校的成绩如下:" << endl;
  46. for (i = 0; i < 5; i++) {
  47. if (a[k].t[d].range[i] != 0) {
  48. cout << "名次:" << a[k].t[d].range[i];
  49. }
  50. }
  51. }
  52. }
  53. break;
  54. case 2:
  55. cout << "要查询的项目编号:"; /*查找项目编号下标*/
  56. cin >> c;
  57. for (i = 0; i < n; i++) {
  58. for (j = 0; j < m + w; j++) {
  59. if (c == a[i].t[j].inum) {
  60. l = j;
  61. }
  62. if (-1 == l) {
  63. cout << "此次运动会没有该项目";
  64. }
  65. else {
  66. cout << "该项目取前a[0].t[l].top名,取得名次的学校" << endl;
  67. for (i = 0; i < n; i++) {
  68. for (j = 0; j < 5; j++) {
  69. if (a[i].t[l].range[j] != 0) {
  70. cout << "学校编号:" << a[i].snum << " " << ", 名次:" << a[i].t[l].range[j] << endl;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. break;
  78. default:
  79. cout << "输入错误,请重试!" << endl;
  80. }
  81. cout << "请选择:1.返回主菜单 0.继续";
  82. cin >> q;
  83. cout << endl;
  84. } while (0 == q);
  85. cout << endl;
  86. if (q != 0) {
  87. menu(n, m, w);
  88. }
  89. }

 修改功能

  1. //修改功能
  2. void modify(int n, int m, int w) {
  3. int size = sizeof(a) / sizeof(a[0]); // 数组长度
  4. int c = 0, delete_snum = 0, key1 = 0, key2 = 0, j = 0, i = 0, modify_snum = 0, alter_snum = 0, alter_inum = 0, temp = 0, k = 0;
  5. string alter_sname;
  6. readfromfile(n, m, w);
  7. deletefile(); //将之前的信息从文件里删除
  8. cout << "\t\t*****************修改系统****************" << endl;
  9. cout << "\t\t*****************************************" << endl;
  10. cout << "\t\t** **" << endl;
  11. cout << "\t\t** 1.利用学校编号删除学校全部信息 **" << endl;
  12. cout << "\t\t** 2.利用学校和项目编号删除项目信息 **" << endl;
  13. cout << "\t\t** 3.修改学校信息 **" << endl;
  14. cout << "\t\t** 4.修改项目信息 **" << endl;
  15. cout << "\t\t** **" << endl;
  16. cout << "\t\t*****************************************" << endl;
  17. cout << "\t\t*****************************************" << endl;
  18. cout << "=======================================================" << endl;
  19. cout << endl;
  20. cout << "请选择要实现功能的编号(1--4):";
  21. cin >> c;
  22. switch (c) {
  23. case 1: //利用学校编号删除学校全部信息
  24. cout << "要删除的学校编号:"; /*查找学校编号下标*/
  25. cin >> delete_snum;
  26. for (int i = 0; i < n; i++) {
  27. if (delete_snum == a[i].snum) {
  28. key1 = i;
  29. }
  30. }
  31. if (-1 == key1) {
  32. cout << "错误:这个学校没有参加此次运动会!" << endl;
  33. }
  34. //int size = sizeof(a) / sizeof(int);
  35. //delete& a[key1];
  36. //memmove(&arr[key1], &arr[key1 + 1], sizeof(int) * (size - key1 - 1));
  37. //memmove(&a[key1], &a[key1 + 1], sizeof(int) * (size - key1 - 1));
  38. //free(&a[key1]);
  39. for (int i = key1; i < size - 1; i++) {
  40. a[i] = a[i + 1];
  41. }
  42. size--;
  43. break;
  44. case 2: //利用学校和项目编号删除项目信息
  45. cout << "要删除的学校编号:"; /*查找学校编号下标*/
  46. cin >> delete_snum;
  47. for (i = 0; i < n; i++) {
  48. if (delete_snum == a[i].snum) {
  49. key1 = i;
  50. }
  51. }
  52. if (-1 == key1) {
  53. cout << "错误:这个学校没有参加此次运动会!" << endl;
  54. }
  55. else {
  56. cout << "要查询的项目编号:"; /*查找项目编号下标*/
  57. cin >> c;
  58. for (j = 0; j < m + w; j++) {
  59. if (delete_snum == a[key1].t[j].inum) {
  60. key2 = j;
  61. }
  62. }
  63. if (-1 == key2) {
  64. cout << "此次运动会没有这个项目" << endl;
  65. }
  66. }
  67. delete& a[key1].t[key2];
  68. break;
  69. case 3: //修改学校信息
  70. cout << "要修改的学校编号:"; /*查找学校编号下标*/
  71. cin >> modify_snum;
  72. for (i = 0; i < n; i++) {
  73. if (modify_snum == a[i].snum) {
  74. key1 = i;
  75. }
  76. }
  77. if (-1 == key1) {
  78. cout << "错误:这个学校没有参加此次运动会!" << endl;
  79. }
  80. cout << "\t\t**************************" << endl;
  81. cout << "\t\t** 请选择你想修改的信息 **" << endl;
  82. cout << "\t\t** **" << endl;
  83. cout << "\t\t** 1. 学校编号 **" << endl;
  84. cout << "\t\t** 2. 学校名字 **" << endl;
  85. cout << "\t\t** **" << endl;
  86. cout << "\t\t***************************" << endl;
  87. cin >> c;
  88. if (c == 1) {
  89. cout << "请输入新的学校编号(1-20):" << endl;
  90. cin >> alter_snum;
  91. a[key1].snum = a[alter_snum].snum;
  92. temp = key1;
  93. delete& a[key1];
  94. a[alter_snum] = a[temp];
  95. cout << "学校编号修改成功!" << endl;
  96. }
  97. else if (c == 2) {
  98. cout << "请输入新的学校名字:" << endl;
  99. cin >> alter_sname;
  100. a[alter_snum].sname = alter_sname;
  101. a[key1].sname = a[alter_snum].sname;
  102. cout << "学校名字修改成功!" << endl;
  103. }
  104. else {
  105. cout << "请输入1或2!" << endl;
  106. }
  107. break;
  108. case 4: //修改项目信息
  109. cout << "要修改的学校编号:"; /*查找学校编号下标*/
  110. cin >> modify_snum;
  111. for (i = 0; i < n; i++) {
  112. if (modify_snum == a[i].snum) {
  113. key1 = i;
  114. }
  115. }
  116. if (-1 == key1) {
  117. cout << "错误:这个学校没有参加此次运动会!" << endl;
  118. }
  119. else {
  120. cout << "要查询的项目编号:"; /*查找项目编号下标*/
  121. cin >> c;
  122. for (j = 0; j < m + w; j++) {
  123. if (delete_snum == a[key1].t[j].inum) {
  124. key2 = j;
  125. }
  126. }
  127. if (-1 == key2) {
  128. cout << "此次运动会没有这个项目" << endl;
  129. }
  130. }
  131. cout << "\t\t**************************" << endl;
  132. cout << "\t\t**请选择想修改项目的信息**" << endl;
  133. cout << "\t\t** **" << endl;
  134. cout << "\t\t** 1. 项目编号 **" << endl;
  135. cout << "\t\t** 2. 名次 **" << endl;
  136. cout << "\t\t** **" << endl;
  137. cout << "\t\t**************************" << endl;
  138. cout << "\t\t**************************" << endl;
  139. if (c == 1) {
  140. cout << "请输入修改后的项目编号:" << endl;
  141. cin >> alter_inum;
  142. a[key1].t[key2].inum = alter_inum;
  143. cout << "修改成功!" << endl;
  144. }
  145. else if (c == 2) {
  146. cout << "请输入修改后的获得项目名次的个数:" << endl;
  147. cin >> k;//输入获得名次的个数
  148. for (int s = 0; s < k; s++) {
  149. if (a[key1].t[key2].inum % 2 == 0) {
  150. cout << "请输入获得的名次(1--3):";
  151. }
  152. else {
  153. cout << "请输入获得的名次(1--5):";
  154. }
  155. cin >> a[key1].t[key2].range[s];//输入所获得的名次的信息
  156. }
  157. if (a[key1].t[key2].inum % 2 == 1) {
  158. k = 5;
  159. }
  160. else if (a[key1].t[key2].inum % 2 == 0) {
  161. k = 3;
  162. }
  163. for (int s = 0; s < 5; s++) {
  164. if (k == 3) {
  165. switch (a[key1].t[key2].range[s]) {
  166. case 0:
  167. a[key1].t[key2].mark[s] = 0;
  168. break;
  169. case 1:
  170. a[key1].t[key2].mark[s] = 5;
  171. break;
  172. case 2:
  173. a[key1].t[key2].mark[s] = 3;
  174. break;
  175. case 3:
  176. a[key1].t[key2].mark[s] = 2;
  177. break;
  178. }
  179. }
  180. else if (k == 5) {
  181. switch (a[i].t[j].range[s]) {
  182. case 0:
  183. a[key1].t[key2].mark[s] = 0;
  184. break;
  185. case 1:
  186. a[key1].t[key2].mark[s] = 7;
  187. break;
  188. case 2:
  189. a[key1].t[key2].mark[s] = 5;
  190. break;
  191. case 3:
  192. a[key1].t[key2].mark[s] = 3;
  193. break;
  194. case 4:
  195. a[key1].t[key2].mark[s] = 2;
  196. break;
  197. case 5:
  198. a[key1].t[key2].mark[s] = 1;
  199. break;
  200. }
  201. }
  202. for (int j = 0; j < w + m; j++) {
  203. for (int s = 0; s < 5; s++) {
  204. a[key1].score = a[key1].score + a[key1].t[j].mark[s];//学校总分
  205. if (j < m) {
  206. a[key1].mscore = a[key1].mscore + a[key1].t[j].mark[s];
  207. }
  208. else {//女子总分
  209. a[key1].wscore = a[key1].wscore + a[key1].t[j].mark[s];
  210. }
  211. }
  212. }
  213. }
  214. }
  215. }
  216. int q = 0;
  217. cout << "输入完毕!(返回菜单请输入1):";
  218. cin >> q;
  219. cout << endl;
  220. if (q != 1) {
  221. cout << "不能再添加信息了!";
  222. }
  223. cout << endl;
  224. savetofile(n, w, m);//保存文件
  225. menu(n, m, w);
  226. }

 主函数

  1. //主函数
  2. int main()
  3. {
  4. int n, m, w;//n为学校个数,m为男子数,w为女子数
  5. char sname[S];
  6. cout << "\t\t\t欢迎使用\t\t\t\t" << endl;
  7. cout << endl;
  8. cout << "\t***********运动会分数统计系统***********" << endl;
  9. cout << endl;
  10. cout << "请先输入运动会主要信息" << endl;
  11. cout << "输入学校个数:";
  12. cin >> n;
  13. cout<<"输入男子项目个数:";
  14. cin >> m;
  15. cout<<"输入女子项目个数:";
  16. cin >> w;
  17. menu(n, m, w);
  18. }

完整代码

完整代码

  1. #include<math.h>
  2. #include<process.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #define _CRT_SECURE_NO_WARNINGS
  6. using namespace std;
  7. #define N 20 //学校最大数目
  8. #define M 30 //男子项目最大数
  9. #define W 20 //女子项目最大数
  10. #define S 10000 //学校名字长度最大数
  11. //存放项目信息的结构体
  12. typedef struct
  13. {
  14. int inum;//项目编号
  15. int top;//取名次的数目
  16. int range[5];//名次
  17. int mark[5];//分数
  18. }itemnode;
  19. //存放学校信息的结构体
  20. typedef struct
  21. {
  22. int snum;//学校编号
  23. string sname;//学校名字
  24. int score;//学校总分
  25. int mscore;//男子总分
  26. int wscore;//女子总分
  27. itemnode t[M + W];//项目数组
  28. }snode;
  29. snode a[N];//定义一个学校数组
  30. //菜单函数
  31. void menu(int n, int m, int w)
  32. {//n代表学校数,m代表男子数,w代表女子数
  33. int c;
  34. void input(int n, int m, int w);//输入功能
  35. void output(int n, int m, int w);//输出功能
  36. void sortput(int n, int m, int w);//排序输出
  37. void search(int n, int m, int w);//查询功能
  38. void modify(int n, int m, int w);//修改功能
  39. cout<<"\t\t***********欢迎使用***********"<<endl;
  40. cout<< "\t\t******************************" << endl;
  41. cout<<"\t\t***** 运动会分数统计系统 *****"<<endl;
  42. cout <<"\t\t** **"<< endl;
  43. cout<<"\t\t** 1.信息输入 **"<<endl;
  44. cout<<"\t\t** 2.统计输出 **" << endl;
  45. cout<<"\t\t** 3.排序输出 **" << endl;
  46. cout<<"\t\t** 4.信息查询 **"<<endl;
  47. cout<<"\t\t** 5.修改功能 **"<<endl;
  48. cout<<"\t\t** 6.退出系统 **"<< endl;
  49. cout<<"\t\t** **"<< endl;
  50. cout<<"\t\t******************************" << endl;
  51. cout<<"\t\t******************************" << endl;
  52. cout << endl;
  53. cout<<"======================================================="<<endl;
  54. cout << endl;
  55. cout<<"请输入您想要实现的功能(1--6):"<<endl;
  56. cin >> c;
  57. switch (c) {
  58. case 1:
  59. input(n, m, w);
  60. break;
  61. case 2:
  62. output(n, m, w);
  63. break;
  64. case 3:
  65. sortput(n, m, w);
  66. break;
  67. case 4:
  68. search(n, m, w);
  69. break;
  70. case 5:
  71. modify(n, m, w);
  72. break;
  73. case 6:
  74. cout<<"感谢使用,祝您天天开心!!"<<endl;
  75. exit(0);//正常退出
  76. default:
  77. cout<<"您输入有误,请重新输入!";
  78. menu(n, m, w);
  79. }
  80. }
  81. //将信息写入文件中
  82. void savetofile(int n, int w, int m)
  83. {
  84. ofstream file("file.txt", ios::app | ios::in | ios::out | ios::binary);
  85. if (file.fail()) {
  86. cout << "打开失败" << endl;
  87. }
  88. for (int i = 0; i < n; i++) {
  89. for (int j = 0; j < w + m; j++)
  90. for (int z = 0; z < 5; z++) {
  91. {
  92. file <<"学校编号:" << a[i].snum <<" "<<"学校名字:" << a[i].sname<<" "<<"学校总分:" << a[i].score <<" "<<"男子总分:" <<a[i].mscore <<" " <<"女子总分:" <<a[i].wscore <<" "<<"项目编号:" <<a[i].t[j].inum <<" "<<"项目取前" << a[i].t[j].top <<"名" << " " << "项目名次:" << a[i].t[j].range[z] << " " << "项目总分:" << a[i].t[j].mark[z] << endl;
  93. }
  94. }
  95. }
  96. file.close();
  97. }
  98. //将信息从文件里取出
  99. void readfromfile(int n,int w,int m)
  100. {
  101. ifstream file("file.txt", ios::app | ios::in | ios::out | ios::binary);
  102. }
  103. //将信息从文件里删除
  104. void deletefile() {
  105. // string file_path = "file.txt";
  106. //remove(file_path.c_str());
  107. ofstream file("file.txt", ios_base::out | ios_base::trunc);
  108. file << "";
  109. file.close();
  110. }
  111. //信息输入功能
  112. void input(int n, int m, int w)
  113. {
  114. int i, j, s, k, q = 1;
  115. for (i = 0; i < n; i++) {
  116. cout<<"请输入学校的编号和学校的名字:"<<endl;
  117. cin >> a[i].snum>>a[i].sname;
  118. for (j = 0; j < m + w; j++) {//总的项目的输入
  119. cout << "请输入项目编号:";
  120. cin>> a[i].t[j].inum;
  121. if (a[i].t[j].inum % 2 == 0) {
  122. cout<<"编号为偶数取前三" << endl;
  123. cout << "获得的名次的个数(1--5):";
  124. }
  125. else if (a[i].t[j].inum % 2 == 1) {
  126. cout <<"编号为奇数的项目取前五"<<endl;
  127. cout << "获得的名次的个数(1--5):";
  128. }
  129. else {
  130. cout << "输入有误!程序退出....";
  131. return;
  132. }
  133. cin >> k;//输入获得名次的个数
  134. for (s = 0; s < k; s++) {
  135. if(a[i].t[j].inum % 2 == 0){
  136. cout<<"请输入获得的名次(1--3):";
  137. }
  138. else {
  139. cout<<"请输入获得的名次(1--5):";
  140. }
  141. cin >> a[i].t[j].range[s];//输入所获得的名次的信息
  142. }
  143. cout << endl;
  144. }
  145. }
  146. for (i = 0; i < n; i++) {
  147. //初始化分数
  148. a[i].score = 0;//学校总分
  149. a[i].mscore = 0;//男子总分
  150. a[i].wscore = 0;//女子总分
  151. }
  152. for (i = 0; i < n; i++) {
  153. for (j = 0; j < m + w; j++) {
  154. if (a[i].t[j].inum % 2 == 1) {
  155. a[i].t[j].top = 5;
  156. cout << "项目" << j + 1 << "取得是前:"<< a[i].t[j].top <<"名"<<endl;
  157. }
  158. else if (a[i].t[j].inum % 2 == 0) {
  159. a[i].t[j].top = 3;
  160. cout << "项目" << j + 1 << "取得是前:" << a[i].t[j].top << "名" << endl;;
  161. }
  162. for (s = 0; s < 5; s++) {
  163. if (a[i].t[j].top == 3) {
  164. switch (a[i].t[j].range[s]) {
  165. case 0:
  166. a[i].t[j].mark[s] = 0;
  167. break;
  168. case 1:
  169. a[i].t[j].mark[s] = 5;
  170. break;
  171. case 2:
  172. a[i].t[j].mark[s] = 3;
  173. break;
  174. case 3:
  175. a[i].t[j].mark[s] = 2;
  176. break;
  177. }
  178. }
  179. else if (a[i].t[j].top == 5) {
  180. switch (a[i].t[j].range[s]) {
  181. case 0:
  182. a[i].t[j].mark[s] = 0;
  183. break;
  184. case 1:
  185. a[i].t[j].mark[s] = 7;
  186. break;
  187. case 2:
  188. a[i].t[j].mark[s] = 5;
  189. break;
  190. case 3:
  191. a[i].t[j].mark[s] = 3;
  192. break;
  193. case 4:
  194. a[i].t[j].mark[s] = 2;
  195. break;
  196. case 5:
  197. a[i].t[j].mark[s] = 1;
  198. break;
  199. }
  200. }
  201. a[i].score = a[i].score + a[i].t[j].mark[s];//学校总分
  202. if (j < m) {
  203. a[i].mscore = a[i].mscore + a[i].t[j].mark[s];
  204. }
  205. else {//女子总分
  206. a[i].wscore = a[i].wscore + a[i].t[j].mark[s];
  207. }
  208. }
  209. }
  210. }
  211. cout<<"输入完毕!(返回菜单请输入1):";
  212. cin >> q;
  213. cout << endl;
  214. if (q != 1) {
  215. cout<<"不能再添加信息了!";
  216. }
  217. cout << endl;
  218. savetofile(n,w,m);//保存文件
  219. menu(n, m, w);
  220. }
  221. #if(1)//信息输出功能
  222. void output(int n, int m, int w) /*2.统计输出*/
  223. {
  224. readfromfile(n,m,w);
  225. int i, j, s, q = 0;
  226. for (i = 0; i < n; i++) /*显示结果*/
  227. {
  228. cout << "学校编号:" << a[i].snum << " ";
  229. cout << "学校名字:" << a[i].sname << " ";
  230. cout << "学校总分:" << a[i].score << endl;
  231. cout << "男子总分:" << a[i].mscore <<" " << "女子总分:" << a[i].wscore << endl;
  232. for (j = 0; j < m + w; j++)
  233. {
  234. cout << "项目编号:" << a[i].t[j].inum <<" " << "所取名次取前:" << a[i].t[j].top<<"名"<< endl;
  235. for (s = 0; s < 5; s++)
  236. {
  237. if (a[i].t[j].range[s] != 0)
  238. cout<<"名次:"<< a[i].t[j].range[s] <<" " << "分数:"<< a[i].t[j].mark[s]<<" "<<endl;
  239. }
  240. }
  241. cout << endl;
  242. }
  243. cout<<"\n";
  244. cout<<"统计完毕!返回? 1是 2否"; /*返回菜单*/
  245. cin >> q;
  246. cout << endl;
  247. if (q != 1)
  248. cout<<"统计已经结束!";
  249. cout << endl;
  250. menu(n, m, w);
  251. }
  252. #endif
  253. //排序输出
  254. void sortput(int n, int m, int w)//n为学校数,m为男子数,w为女子数
  255. {
  256. readfromfile(n,m,w);
  257. int c, i, j, k, q = 0;
  258. int temp[N]={};
  259. cout<<"\t\t***** 排序输出系统 *****"<< endl;
  260. cout<<"\t\t************************"<< endl;
  261. cout<<"\t\t** **"<< endl;
  262. cout<<"\t\t** 1.按学校编号输出 **"<< endl;
  263. cout<<"\t\t** 2.按学校总分输出 **"<<endl;
  264. cout<<"\t\t** 3.按男子总分输出 **"<<endl;
  265. cout<<"\t\t** 4.按女子总分输出 **"<<endl;
  266. cout<<"\t\t** **"<< endl;
  267. cout<<"\t\t************************"<< endl;
  268. cout<<"\t\t************************"<< endl;
  269. cout<<"======================================================="<<endl;
  270. cout << endl;
  271. do {
  272. cout<<"请选择您想实现的功能的编号(1--4):";
  273. cin >> c;
  274. switch (c) {
  275. case 1:
  276. for (i = 0; i < n; i++) {
  277. temp[i] = i;
  278. }
  279. //用的是冒泡排序输出
  280. for (i = 0; i < n; i++) {
  281. for (j = i + 1; j < n; j++) {
  282. if (a[temp[i]].snum > a[j].snum) {
  283. k = temp[i];
  284. temp[i] = temp[j];
  285. temp[j] = k;
  286. }
  287. }
  288. }
  289. for (i = 0; i < n; i++) {
  290. cout << "学校编号:" << a[temp[i]].snum <<" " << "学校名字" << a[temp[i]].sname << " " << "学校总分:" << a[temp[i]].score << endl;
  291. cout << "男子总分" << a[temp[i]].mscore << " " << "女子总分:" << a[temp[i]].wscore << endl;
  292. }
  293. break;
  294. case 2:
  295. for (i = 0; i < n; i++) {
  296. temp[i] = i;
  297. }
  298. for (i = 0; i < n; i++) {
  299. for (j = i + 1; j < n; j++) {
  300. if (a[temp[i]].score < a[j].score) {
  301. k = temp[i];
  302. temp[i] = temp[j];
  303. temp[j] = k;
  304. }
  305. }
  306. }
  307. for (i = 0; i < n; i++) {
  308. cout << "学校编号:" << a[temp[i]].snum << " " << "学校名字" << a[temp[i]].sname <<" " << "学校总分:" << a[temp[i]].score << endl;
  309. cout << "男子总分" << a[temp[i]].mscore << " " << "女子总分:" << a[temp[i]].wscore << endl;
  310. }
  311. break;
  312. case 3:
  313. for (i = 0; i < n; i++) {
  314. temp[i] = i;
  315. }
  316. for (i = 0; i < n; i++) {
  317. for (j = i + 1; j < n; j++) {
  318. if (a[temp[i]].mscore < a[j].mscore) {
  319. k = temp[i];
  320. temp[i] = temp[j];
  321. temp[j] = k;
  322. }
  323. }
  324. }
  325. for (i = 0; i < n; i++) {
  326. cout << "学校编号:" << a[temp[i]].snum << " " << "学校名字" << a[temp[i]].sname << " " << "学校总分:" << a[temp[i]].score << endl;
  327. cout << "男子总分" << a[temp[i]].mscore << " " << "女子总分:" << a[temp[i]].wscore << endl;
  328. }
  329. break;
  330. case 4:
  331. for (i = 0; i < n; i++) {
  332. temp[i] = i;
  333. }
  334. for (i = 0; i < n; i++) {
  335. for (j = i + 1; j < n; j++) {
  336. if (a[temp[i]].wscore < a[j].wscore) {
  337. k = temp[i];
  338. temp[i] = temp[j];
  339. temp[j] = k;
  340. }
  341. }
  342. }
  343. for (i = 0; i < n; i++) {
  344. cout << "学校编号:" << a[temp[i]].snum << " " << "学校名字" << a[temp[i]].sname << " " << "学校总分:" << a[temp[i]].score << endl;
  345. cout << "男子总分" << a[temp[i]].mscore << " " << "女子总分:" << a[temp[i]].wscore << endl;
  346. }
  347. break;
  348. default:
  349. cout<<"您的输入有误!请从新输入...";
  350. }
  351. cout<<"请选择 1.返回主菜单 0.继续";
  352. cin >> q;
  353. cout << endl;
  354. }
  355. while (0 == q);
  356. cout << endl;
  357. if (q != 0) {
  358. menu(n, m, w);
  359. }
  360. }
  361. //查询功能
  362. void search(int n, int m, int w)
  363. {
  364. readfromfile(n,m,w);
  365. int c, i, j, k, d, l, q = 0;
  366. cout<<"\t\t********查询系统********"<<endl;
  367. cout << "\t\t************************"<< endl;
  368. cout << "\t\t** **"<< endl;
  369. cout << "\t\t** 1.按学校编号查询 **"<<endl;
  370. cout << "\t\t** 2.按项目编号查询 **"<< endl;
  371. cout << "\t\t** **" << endl;
  372. cout << "\t\t************************"<< endl;
  373. cout << "\t\t************************"<< endl;
  374. cout << "=======================================================" << endl;
  375. cout << endl;
  376. do
  377. {
  378. k = -1; d = -1; l = -1;
  379. cout << "请选择要实现功能的编号(1--2):";
  380. cin >> c;
  381. switch (c) {
  382. case 1:
  383. cout << "要查询的学校编号:"; /*查找学校编号下标*/
  384. cin >> c;
  385. for (i = 0; i < n; i++) {
  386. if (c == a[i].snum) {
  387. k = i;
  388. }
  389. }
  390. if (-1 == k) {
  391. cout << "错误:这个学校没有参加此次运动会!" << endl;
  392. }
  393. else {
  394. cout << "要查询的项目编号:"; /*查找项目编号下标*/
  395. cin >> c;
  396. for (j = 0; j < m + w; j++) {
  397. if (c == a[k].t[j].inum) {
  398. d = j;
  399. }
  400. }
  401. if (-1 == d) {
  402. cout << "此次运动会没有这个项目" << endl;
  403. }
  404. else {
  405. cout << "这个项目取前" << a[k].t[d].top << "名,该学校的成绩如下:" << endl;
  406. for (i = 0; i < 5; i++) {
  407. if (a[k].t[d].range[i] != 0) {
  408. cout << "名次:" << a[k].t[d].range[i];
  409. }
  410. }
  411. }
  412. }
  413. break;
  414. case 2:
  415. cout << "要查询的项目编号:"; /*查找项目编号下标*/
  416. cin >> c;
  417. for (i = 0; i < n; i++) {
  418. for (j = 0; j < m + w; j++) {
  419. if (c == a[i].t[j].inum) {
  420. l = j;
  421. }
  422. if (-1 == l) {
  423. cout << "此次运动会没有该项目";
  424. }
  425. else {
  426. cout << "该项目取前a[0].t[l].top名,取得名次的学校" << endl;
  427. for (i = 0; i < n; i++) {
  428. for (j = 0; j < 5; j++) {
  429. if (a[i].t[l].range[j] != 0) {
  430. cout << "学校编号:" << a[i].snum << " " << ", 名次:" << a[i].t[l].range[j] << endl;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437. break;
  438. default:
  439. cout << "输入错误,请重试!" << endl;
  440. }
  441. cout << "请选择:1.返回主菜单 0.继续";
  442. cin >> q;
  443. cout << endl;
  444. } while (0 == q);
  445. cout << endl;
  446. if (q != 0) {
  447. menu(n, m, w);
  448. }
  449. }
  450. //修改功能
  451. void modify(int n, int m, int w) {
  452. int size = sizeof(a) / sizeof(a[0]); // 数组长度
  453. int c = 0, delete_snum = 0, key1 = 0, key2 = 0, j = 0, i = 0, modify_snum = 0, alter_snum = 0, alter_inum = 0, temp = 0, k = 0;
  454. string alter_sname;
  455. readfromfile(n, m, w);
  456. deletefile(); //将之前的信息从文件里删除
  457. cout << "\t\t*****************修改系统****************" << endl;
  458. cout << "\t\t*****************************************" << endl;
  459. cout << "\t\t** **" << endl;
  460. cout << "\t\t** 1.利用学校编号删除学校全部信息 **" << endl;
  461. cout << "\t\t** 2.利用学校和项目编号删除项目信息 **" << endl;
  462. cout << "\t\t** 3.修改学校信息 **" << endl;
  463. cout << "\t\t** 4.修改项目信息 **" << endl;
  464. cout << "\t\t** **" << endl;
  465. cout << "\t\t*****************************************" << endl;
  466. cout << "\t\t*****************************************" << endl;
  467. cout << "=======================================================" << endl;
  468. cout << endl;
  469. cout << "请选择要实现功能的编号(1--4):";
  470. cin >> c;
  471. switch (c) {
  472. case 1: //利用学校编号删除学校全部信息
  473. cout << "要删除的学校编号:"; /*查找学校编号下标*/
  474. cin >> delete_snum;
  475. for (int i = 0; i < n; i++) {
  476. if (delete_snum == a[i].snum) {
  477. key1 = i;
  478. }
  479. }
  480. if (-1 == key1) {
  481. cout << "错误:这个学校没有参加此次运动会!" << endl;
  482. }
  483. //int size = sizeof(a) / sizeof(int);
  484. //delete& a[key1];
  485. //memmove(&arr[key1], &arr[key1 + 1], sizeof(int) * (size - key1 - 1));
  486. //memmove(&a[key1], &a[key1 + 1], sizeof(int) * (size - key1 - 1));
  487. //free(&a[key1]);
  488. for (int i = key1; i < size - 1; i++) {
  489. a[i] = a[i + 1];
  490. }
  491. size--;
  492. break;
  493. case 2: //利用学校和项目编号删除项目信息
  494. cout << "要删除的学校编号:"; /*查找学校编号下标*/
  495. cin >> delete_snum;
  496. for (i = 0; i < n; i++) {
  497. if (delete_snum == a[i].snum) {
  498. key1 = i;
  499. }
  500. }
  501. if (-1 == key1) {
  502. cout << "错误:这个学校没有参加此次运动会!" << endl;
  503. }
  504. else {
  505. cout << "要查询的项目编号:"; /*查找项目编号下标*/
  506. cin >> c;
  507. for (j = 0; j < m + w; j++) {
  508. if (delete_snum == a[key1].t[j].inum) {
  509. key2 = j;
  510. }
  511. }
  512. if (-1 == key2) {
  513. cout << "此次运动会没有这个项目" << endl;
  514. }
  515. }
  516. delete& a[key1].t[key2];
  517. break;
  518. case 3: //修改学校信息
  519. cout << "要修改的学校编号:"; /*查找学校编号下标*/
  520. cin >> modify_snum;
  521. for (i = 0; i < n; i++) {
  522. if (modify_snum == a[i].snum) {
  523. key1 = i;
  524. }
  525. }
  526. if (-1 == key1) {
  527. cout << "错误:这个学校没有参加此次运动会!" << endl;
  528. }
  529. cout << "\t\t**************************" << endl;
  530. cout << "\t\t** 请选择你想修改的信息 **" << endl;
  531. cout << "\t\t** **" << endl;
  532. cout << "\t\t** 1. 学校编号 **" << endl;
  533. cout << "\t\t** 2. 学校名字 **" << endl;
  534. cout << "\t\t** **" << endl;
  535. cout << "\t\t***************************" << endl;
  536. cin >> c;
  537. if (c == 1) {
  538. cout << "请输入新的学校编号(1-20):" << endl;
  539. cin >> alter_snum;
  540. a[key1].snum = a[alter_snum].snum;
  541. temp = key1;
  542. delete& a[key1];
  543. a[alter_snum] = a[temp];
  544. cout << "学校编号修改成功!" << endl;
  545. }
  546. else if (c == 2) {
  547. cout << "请输入新的学校名字:" << endl;
  548. cin >> alter_sname;
  549. a[alter_snum].sname = alter_sname;
  550. a[key1].sname = a[alter_snum].sname;
  551. cout << "学校名字修改成功!" << endl;
  552. }
  553. else {
  554. cout << "请输入1或2!" << endl;
  555. }
  556. break;
  557. case 4: //修改项目信息
  558. cout << "要修改的学校编号:"; /*查找学校编号下标*/
  559. cin >> modify_snum;
  560. for (i = 0; i < n; i++) {
  561. if (modify_snum == a[i].snum) {
  562. key1 = i;
  563. }
  564. }
  565. if (-1 == key1) {
  566. cout << "错误:这个学校没有参加此次运动会!" << endl;
  567. }
  568. else {
  569. cout << "要查询的项目编号:"; /*查找项目编号下标*/
  570. cin >> c;
  571. for (j = 0; j < m + w; j++) {
  572. if (delete_snum == a[key1].t[j].inum) {
  573. key2 = j;
  574. }
  575. }
  576. if (-1 == key2) {
  577. cout << "此次运动会没有这个项目" << endl;
  578. }
  579. }
  580. cout << "\t\t**************************" << endl;
  581. cout << "\t\t**请选择想修改项目的信息**" << endl;
  582. cout << "\t\t** **" << endl;
  583. cout << "\t\t** 1. 项目编号 **" << endl;
  584. cout << "\t\t** 2. 名次 **" << endl;
  585. cout << "\t\t** **" << endl;
  586. cout << "\t\t**************************" << endl;
  587. cout << "\t\t**************************" << endl;
  588. if (c == 1) {
  589. cout << "请输入修改后的项目编号:" << endl;
  590. cin >> alter_inum;
  591. a[key1].t[key2].inum = alter_inum;
  592. cout << "修改成功!" << endl;
  593. }
  594. else if (c == 2) {
  595. cout << "请输入修改后的获得项目名次的个数:" << endl;
  596. cin >> k;//输入获得名次的个数
  597. for (int s = 0; s < k; s++) {
  598. if (a[key1].t[key2].inum % 2 == 0) {
  599. cout << "请输入获得的名次(1--3):";
  600. }
  601. else {
  602. cout << "请输入获得的名次(1--5):";
  603. }
  604. cin >> a[key1].t[key2].range[s];//输入所获得的名次的信息
  605. }
  606. if (a[key1].t[key2].inum % 2 == 1) {
  607. k = 5;
  608. }
  609. else if (a[key1].t[key2].inum % 2 == 0) {
  610. k = 3;
  611. }
  612. for (int s = 0; s < 5; s++) {
  613. if (k == 3) {
  614. switch (a[key1].t[key2].range[s]) {
  615. case 0:
  616. a[key1].t[key2].mark[s] = 0;
  617. break;
  618. case 1:
  619. a[key1].t[key2].mark[s] = 5;
  620. break;
  621. case 2:
  622. a[key1].t[key2].mark[s] = 3;
  623. break;
  624. case 3:
  625. a[key1].t[key2].mark[s] = 2;
  626. break;
  627. }
  628. }
  629. else if (k == 5) {
  630. switch (a[i].t[j].range[s]) {
  631. case 0:
  632. a[key1].t[key2].mark[s] = 0;
  633. break;
  634. case 1:
  635. a[key1].t[key2].mark[s] = 7;
  636. break;
  637. case 2:
  638. a[key1].t[key2].mark[s] = 5;
  639. break;
  640. case 3:
  641. a[key1].t[key2].mark[s] = 3;
  642. break;
  643. case 4:
  644. a[key1].t[key2].mark[s] = 2;
  645. break;
  646. case 5:
  647. a[key1].t[key2].mark[s] = 1;
  648. break;
  649. }
  650. }
  651. for (int j = 0; j < w + m; j++) {
  652. for (int s = 0; s < 5; s++) {
  653. a[key1].score = a[key1].score + a[key1].t[j].mark[s];//学校总分
  654. if (j < m) {
  655. a[key1].mscore = a[key1].mscore + a[key1].t[j].mark[s];
  656. }
  657. else {//女子总分
  658. a[key1].wscore = a[key1].wscore + a[key1].t[j].mark[s];
  659. }
  660. }
  661. }
  662. }
  663. }
  664. }
  665. int q = 0;
  666. cout << "输入完毕!(返回菜单请输入1):";
  667. cin >> q;
  668. cout << endl;
  669. if (q != 1) {
  670. cout << "不能再添加信息了!";
  671. }
  672. cout << endl;
  673. savetofile(n, w, m);//保存文件
  674. menu(n, m, w);
  675. }
  676. //主函数
  677. int main()
  678. {
  679. int n, m, w;//n为学校个数,m为男子数,w为女子数
  680. char sname[S];
  681. cout << "\t\t\t欢迎使用\t\t\t\t" << endl;
  682. cout << endl;
  683. cout << "\t***********运动会分数统计系统***********" << endl;
  684. cout << endl;
  685. cout << "请先输入运动会主要信息" << endl;
  686. cout << "输入学校个数:";
  687. cin >> n;
  688. cout<<"输入男子项目个数:";
  689. cin >> m;
  690. cout<<"输入女子项目个数:";
  691. cin >> w;
  692. menu(n, m, w);
  693. }

运行截图

运行截图

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/空白诗007/article/detail/812892
推荐阅读
相关标签
  

闽ICP备14008679号