鱼C论坛

 找回密码
 立即注册
查看: 1574|回复: 3

[已解决]really need help !

[复制链接]
发表于 2018-6-27 14:30:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
课程题目:考勤统计程序
内容要求:使用文本命令行设计考勤统计程序。
要求使用文本命令行界面,用文件保存全班每个学生的考勤信息。能实现考勤信息的增、删、改、查和统计等功能。
最佳答案
2018-6-27 18:57:37
Test1.png
Test2.png
Test3.png
Test4.png

  1. #include <iostream>
  2. #include <fstream>
  3. #include <list>
  4. #include <algorithm>
  5. #include <string>

  6. using namespace std;

  7. const string BAIJIAXING[] = { "赵","钱","孙","李","周","吴","郑","王","冯",
  8.                                                           "陈","褚","卫","蒋","沈","韩","杨","朱","秦",
  9.                                                           "尤","许","何","吕","施","张","孔","曹","严",
  10.                                                           "华","金","魏","陶","姜","戚","谢","邹","喻" };


  11. class Student {
  12. public:
  13.         // 默认构造
  14.         Student(): Name("学生"),Age(18),Id(0),Late_number(0){}
  15.         // 获取方法
  16.         string &Get_Name() { return this->Name; } // 获取学生姓名
  17.         int &Get_Age() { return this->Age; } // 获取学生年龄
  18.         int &Get_Id() { return this->Id; } // 获取学生学号
  19.         int &Get_Late() { return this->Late_number; } // 获取学生迟到次数
  20.         // 设置方法
  21.         void Set_Name(string Name_) { this->Name = Name_; } // 设置学生姓名
  22.         void Set_Age(int Age_) { this->Age = Age; } // 获取学生年龄
  23.         void Set_Id(int Id) { this->Id = Id; } // 获取学生学号
  24.         void Set_Late(int Late) { this->Late_number = Late; } // 获取学生迟到次数
  25. private:
  26.         string Name; // 姓名
  27.         int Age;// 年龄
  28.         int Id; // 学号
  29.         int Late_number; // 考勤的类型应该有哪些!我就只写个迟到次数了
  30. };

  31. // 回调 排序规则
  32. bool Mycompare(Student &v1, Student &v2) {
  33.         return v1.Get_Late() > v2.Get_Late();
  34. }

  35. class Late{
  36. public:
  37.         Late(int val) {
  38.                 for (int i = 0; i < val; i++) {
  39.                         Student s;
  40.                         s.Set_Name((s.Get_Name()) += BAIJIAXING[rand() % 35]); // 初始化学生姓名
  41.                         s.Set_Id(i); // 初始化学号
  42.                         Student_list.push_back(s);
  43.                 }
  44.         }
  45.         void Student_sort() { // 排序
  46.                 // 按照迟到次数,从大到小排
  47.          Student_list.sort(Mycompare);
  48.         }

  49.         void Student_Add(int Id, int val) {  // 增加迟到次数
  50.                 for (list<Student>::iterator i = Student_list.begin(); i != Student_list.end(); i++) {
  51.                         if (i->Get_Id() == Id) {
  52.                                 i->Set_Late(i->Get_Late() += val);
  53.                         }
  54.                 }
  55.         }

  56.         bool Student_Delete(int Id, int val) { // 删除迟到次数
  57.                 for (list<Student>::iterator i = Student_list.begin(); i != Student_list.end(); i++) {
  58.                         if (i->Get_Id() == Id) {
  59.                                 if ((i->Get_Late() - val) < 0) {
  60.                                         return false;
  61.                                 }
  62.                                 else {
  63.                                         return true;
  64.                                 }
  65.                         }
  66.                 }
  67.         }

  68.         int Student_Seek(int Id) {  //查询迟到次数
  69.                 for (list<Student>::iterator i = Student_list.begin(); i != Student_list.end(); i++) {
  70.                         if (i->Get_Id() == Id) {
  71.                                 return i->Get_Late();
  72.                         }
  73.                 }
  74.         }

  75.         bool Student_Keep() { // 保存资料
  76.                 ofstream s_("D:\\Student.txt", ios::out);
  77.                 if (s_) {
  78.                         for (list<Student>::iterator i = Student_list.begin(); i != Student_list.end(); i++) {
  79.                                 s_ << "学生: " << i->Get_Name() << endl;
  80.                                 s_ << "学号: " << i->Get_Id() << endl;;
  81.                                 s_ << "年龄: " << i->Get_Age() << endl;
  82.                                 s_ << "迟到次数: " << i->Get_Late() << endl;
  83.                                 s_ << "=====================================" << endl;
  84.                                
  85.                         }
  86.                         return true;
  87.                 }
  88.                 else {
  89.                         return false;
  90.                 }
  91.                 s_.close();
  92.         }
  93. private:
  94.         list<Student> Student_list;
  95. };




  96. // 业务层
  97. void Fun0() {
  98.         cout << "\n" << endl;
  99.         cout << "\t\t" << "欢迎使用学生考勤系统" << endl;
  100.         cout << "\t\t" << "1. 增加学生迟到次数" << endl;
  101.         cout << "\t\t" << "2. 减少学生迟到次数" << endl;
  102.         cout << "\t\t" << "3. 查询学生迟到次数" << endl;
  103.         cout << "\t\t" << "4. 保存学生考勤信息" << endl;
  104.         cout << "\t\t" << "5. 退出学生考勤信息" << endl;

  105. }

  106. bool Fun2(int v1, int v2) {
  107.         return v1 < v2;
  108. }


  109. void Fun1() {
  110.         int Student_sum = 0;
  111.         cout << "请告诉我,本班有多少名学生: ";
  112.         cin >> Student_sum;
  113.         Late s(Student_sum);

  114.         //  这里我就当做都是正经用户了,就不判断值的非法性了。
  115.         int val;
  116.         while (true) {
  117.                 Fun0();
  118.                 cin >> val;
  119.                 switch (val)
  120.                 {
  121.                 case 1:
  122.                 {
  123.                         system("cls");
  124.                         int val, id;
  125.                         cout << "请输入学生的学号和增加迟到的次数: ";
  126.                         cin >> id >> val;
  127.                         while (Fun2(Student_sum, id)) {
  128.                                 cout << "请正确输入学号: ";
  129.                                 cin >> id;
  130.                         }
  131.                         s.Student_Add(id, val);
  132.                         cout << "操作成功!" << endl;
  133.                 }
  134.                 break;
  135.                 case 2:
  136.                 {
  137.                         system("cls");
  138.                         int val, id;
  139.                         cout << "请输入学生的学号和要减少迟到的次数: ";
  140.                         cin >> id >> val;
  141.                         while (Fun2(Student_sum, id)) {
  142.                                 cout << "请正确输入学号: ";
  143.                                 cin >> id;
  144.                         }
  145.                         if (s.Student_Delete(id, val)) {
  146.                                 cout << "操作成功" << endl;
  147.                         }
  148.                         else {
  149.                                 cout << "操作失败" << endl;
  150.                         }
  151.                 }
  152.                 break;
  153.                 case 3:
  154.                 {
  155.                         system("cls");
  156.                         int id, sum;
  157.                         cout << "请输入欲查找学生的学号:";
  158.                         cin >> id;
  159.                         while (Fun2(Student_sum, id)) {
  160.                                 cout << "请正确输入学号: ";
  161.                                 cin >> id;
  162.                         }
  163.                         sum = s.Student_Seek(id);
  164.                         cout << "学号:" << id << "学生 共迟到" << sum << "次!" << endl;
  165.                 }
  166.                 break;
  167.                 case 4:
  168.                 {
  169.                         system("cls");
  170.                         for (int i = 0; i < Student_sum; i++) {
  171.                                 if (s.Student_Keep()) {
  172.                                         cout << "操作成功" << endl;
  173.                                 }
  174.                                 else {
  175.                                         cout << "操作失败!" << endl;
  176.                                 }
  177.                         }
  178.                 }
  179.                         break;
  180.                 case 5: return; break;
  181.                 default:
  182.                         cout << "输入错误" << endl;
  183.                         system("cls");
  184.                         break;
  185.                 }
  186.         }
  187. }


  188. int main() {

  189.         Fun1();

  190.         system("pause");
  191. }
复制代码

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-27 15:17:38 | 显示全部楼层
现在这些老师出的都是些什么题, 昨天看到一个要餐厅的, 今天看到一个要考勤的。。我猜的没错的话,你这个也要求那C++写吧,,
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-6-27 15:28:01 | 显示全部楼层
风过无痕丶 发表于 2018-6-27 15:17
现在这些老师出的都是些什么题, 昨天看到一个要餐厅的, 今天看到一个要考勤的。。我猜的没错 ...

额?什么餐厅的
的确要拿c++写
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-6-27 18:57:37 | 显示全部楼层    本楼为最佳答案   
Test1.png
Test2.png
Test3.png
Test4.png

  1. #include <iostream>
  2. #include <fstream>
  3. #include <list>
  4. #include <algorithm>
  5. #include <string>

  6. using namespace std;

  7. const string BAIJIAXING[] = { "赵","钱","孙","李","周","吴","郑","王","冯",
  8.                                                           "陈","褚","卫","蒋","沈","韩","杨","朱","秦",
  9.                                                           "尤","许","何","吕","施","张","孔","曹","严",
  10.                                                           "华","金","魏","陶","姜","戚","谢","邹","喻" };


  11. class Student {
  12. public:
  13.         // 默认构造
  14.         Student(): Name("学生"),Age(18),Id(0),Late_number(0){}
  15.         // 获取方法
  16.         string &Get_Name() { return this->Name; } // 获取学生姓名
  17.         int &Get_Age() { return this->Age; } // 获取学生年龄
  18.         int &Get_Id() { return this->Id; } // 获取学生学号
  19.         int &Get_Late() { return this->Late_number; } // 获取学生迟到次数
  20.         // 设置方法
  21.         void Set_Name(string Name_) { this->Name = Name_; } // 设置学生姓名
  22.         void Set_Age(int Age_) { this->Age = Age; } // 获取学生年龄
  23.         void Set_Id(int Id) { this->Id = Id; } // 获取学生学号
  24.         void Set_Late(int Late) { this->Late_number = Late; } // 获取学生迟到次数
  25. private:
  26.         string Name; // 姓名
  27.         int Age;// 年龄
  28.         int Id; // 学号
  29.         int Late_number; // 考勤的类型应该有哪些!我就只写个迟到次数了
  30. };

  31. // 回调 排序规则
  32. bool Mycompare(Student &v1, Student &v2) {
  33.         return v1.Get_Late() > v2.Get_Late();
  34. }

  35. class Late{
  36. public:
  37.         Late(int val) {
  38.                 for (int i = 0; i < val; i++) {
  39.                         Student s;
  40.                         s.Set_Name((s.Get_Name()) += BAIJIAXING[rand() % 35]); // 初始化学生姓名
  41.                         s.Set_Id(i); // 初始化学号
  42.                         Student_list.push_back(s);
  43.                 }
  44.         }
  45.         void Student_sort() { // 排序
  46.                 // 按照迟到次数,从大到小排
  47.          Student_list.sort(Mycompare);
  48.         }

  49.         void Student_Add(int Id, int val) {  // 增加迟到次数
  50.                 for (list<Student>::iterator i = Student_list.begin(); i != Student_list.end(); i++) {
  51.                         if (i->Get_Id() == Id) {
  52.                                 i->Set_Late(i->Get_Late() += val);
  53.                         }
  54.                 }
  55.         }

  56.         bool Student_Delete(int Id, int val) { // 删除迟到次数
  57.                 for (list<Student>::iterator i = Student_list.begin(); i != Student_list.end(); i++) {
  58.                         if (i->Get_Id() == Id) {
  59.                                 if ((i->Get_Late() - val) < 0) {
  60.                                         return false;
  61.                                 }
  62.                                 else {
  63.                                         return true;
  64.                                 }
  65.                         }
  66.                 }
  67.         }

  68.         int Student_Seek(int Id) {  //查询迟到次数
  69.                 for (list<Student>::iterator i = Student_list.begin(); i != Student_list.end(); i++) {
  70.                         if (i->Get_Id() == Id) {
  71.                                 return i->Get_Late();
  72.                         }
  73.                 }
  74.         }

  75.         bool Student_Keep() { // 保存资料
  76.                 ofstream s_("D:\\Student.txt", ios::out);
  77.                 if (s_) {
  78.                         for (list<Student>::iterator i = Student_list.begin(); i != Student_list.end(); i++) {
  79.                                 s_ << "学生: " << i->Get_Name() << endl;
  80.                                 s_ << "学号: " << i->Get_Id() << endl;;
  81.                                 s_ << "年龄: " << i->Get_Age() << endl;
  82.                                 s_ << "迟到次数: " << i->Get_Late() << endl;
  83.                                 s_ << "=====================================" << endl;
  84.                                
  85.                         }
  86.                         return true;
  87.                 }
  88.                 else {
  89.                         return false;
  90.                 }
  91.                 s_.close();
  92.         }
  93. private:
  94.         list<Student> Student_list;
  95. };




  96. // 业务层
  97. void Fun0() {
  98.         cout << "\n" << endl;
  99.         cout << "\t\t" << "欢迎使用学生考勤系统" << endl;
  100.         cout << "\t\t" << "1. 增加学生迟到次数" << endl;
  101.         cout << "\t\t" << "2. 减少学生迟到次数" << endl;
  102.         cout << "\t\t" << "3. 查询学生迟到次数" << endl;
  103.         cout << "\t\t" << "4. 保存学生考勤信息" << endl;
  104.         cout << "\t\t" << "5. 退出学生考勤信息" << endl;

  105. }

  106. bool Fun2(int v1, int v2) {
  107.         return v1 < v2;
  108. }


  109. void Fun1() {
  110.         int Student_sum = 0;
  111.         cout << "请告诉我,本班有多少名学生: ";
  112.         cin >> Student_sum;
  113.         Late s(Student_sum);

  114.         //  这里我就当做都是正经用户了,就不判断值的非法性了。
  115.         int val;
  116.         while (true) {
  117.                 Fun0();
  118.                 cin >> val;
  119.                 switch (val)
  120.                 {
  121.                 case 1:
  122.                 {
  123.                         system("cls");
  124.                         int val, id;
  125.                         cout << "请输入学生的学号和增加迟到的次数: ";
  126.                         cin >> id >> val;
  127.                         while (Fun2(Student_sum, id)) {
  128.                                 cout << "请正确输入学号: ";
  129.                                 cin >> id;
  130.                         }
  131.                         s.Student_Add(id, val);
  132.                         cout << "操作成功!" << endl;
  133.                 }
  134.                 break;
  135.                 case 2:
  136.                 {
  137.                         system("cls");
  138.                         int val, id;
  139.                         cout << "请输入学生的学号和要减少迟到的次数: ";
  140.                         cin >> id >> val;
  141.                         while (Fun2(Student_sum, id)) {
  142.                                 cout << "请正确输入学号: ";
  143.                                 cin >> id;
  144.                         }
  145.                         if (s.Student_Delete(id, val)) {
  146.                                 cout << "操作成功" << endl;
  147.                         }
  148.                         else {
  149.                                 cout << "操作失败" << endl;
  150.                         }
  151.                 }
  152.                 break;
  153.                 case 3:
  154.                 {
  155.                         system("cls");
  156.                         int id, sum;
  157.                         cout << "请输入欲查找学生的学号:";
  158.                         cin >> id;
  159.                         while (Fun2(Student_sum, id)) {
  160.                                 cout << "请正确输入学号: ";
  161.                                 cin >> id;
  162.                         }
  163.                         sum = s.Student_Seek(id);
  164.                         cout << "学号:" << id << "学生 共迟到" << sum << "次!" << endl;
  165.                 }
  166.                 break;
  167.                 case 4:
  168.                 {
  169.                         system("cls");
  170.                         for (int i = 0; i < Student_sum; i++) {
  171.                                 if (s.Student_Keep()) {
  172.                                         cout << "操作成功" << endl;
  173.                                 }
  174.                                 else {
  175.                                         cout << "操作失败!" << endl;
  176.                                 }
  177.                         }
  178.                 }
  179.                         break;
  180.                 case 5: return; break;
  181.                 default:
  182.                         cout << "输入错误" << endl;
  183.                         system("cls");
  184.                         break;
  185.                 }
  186.         }
  187. }


  188. int main() {

  189.         Fun1();

  190.         system("pause");
  191. }
复制代码

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-3 16:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表