码迷,mamicode.com
首页 > 其他好文 > 详细

学生成绩信息管理

时间:2017-06-20 13:30:20      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:let   ios   public   continue   超出   log   不为   tla   res   

/*

题目:学生成绩管理系统

功能:学生成绩管理系统,每个学生是一个记录,包括学号,姓名,性别,3门课程成绩。系统

要求实现以下功能:

1、信息录入:录入学生成绩信息(包括学生学号、姓名、各门课程的成绩等);

2、信息查询:输入学号,查询学生各门课程的成绩,并显示。

3、排序:按各门课程的成绩平均分进行排序,并显示。

4、信息删除与修改——输入学号,删除该学生的成绩信息。

*/

 

#include<iostream>

#include <string>

#include<iomanip>

using namespace std;

 

class StudentData

{//建立学生类

public:

         string name;  double average;

         double math, english, chinese, chemistry, biology, physics, number;

         StudentData *next;

         StudentData *pre;

         void insertdate()

         {       cin >> chinese >> math >> english >> physics >> chemistry >> biology;        }

         void setlang() { cin >> chinese; }

         void setmath() { cin >> math; }

         void setenglish() { cin >> english; }

         void setphysics() { cin >> physics; }

         void setchemistry() { cin >> chemistry; }

         void setbiology() { cin >> biology; }//输入各科成绩  

} ;

 

struct  linklist

{//带头指针和尾指针的双向链表

         StudentData *head, *present;//头指针和当前指针

         void insert_one();

         void delete_data();

         void setdata();

         bool check();

         void creat();

         void output();

         void setmore();

         void averagerank();

}X;

 

void linklist::output()

{//打印链表,输出学生信息

         cout << "        姓名        学号    语文    数学    英语    物理    化学    生物       平均分" << endl;

         present = head;

         while (present->next != NULL)

         {//不取尾结点,尾节点为空

                  present->average = (present->chinese + present->math + present->english + present->physics + present->chemistry + present->biology) / 6;

                  cout << setw(12)<< present->name << setw(12) << present->number << setw(8) << present->chinese << setw(8) << present->math << setw(8) << present->english

                          << setw(8) << present->physics << setw(8) << present->chemistry << setw(8) << present->biology << setw(16) << present->average <<endl;

                  present = present->next;

         }

}

 

void linklist::creat()

{//创建空结点

         present = new StudentData;

         head = present;

         present->next = NULL;     

         present->pre = NULL;

}

 

void linklist::insert_one()

{

         present = new StudentData;

         head->pre = present;

         present->next = head;

         head = present;

         present->pre = NULL;//新加一个学生数据加在表头

         cout << "请输入学生姓名: ";

         cin >> present->name;

         cout << "请输入学号:";

         cin >> present->number;

         cout << "请一次输入语文,数学,英语,物理,化学,生物各科成绩:" << endl;  

         present->insertdate();        //输入成绩

}

 

void linklist::delete_data()

{//删除学生信息

         //string studentnam;

         int sigh = 0;

         cout << "请输入要删除的学生学号: ";

         if (check())

         { 

                  if (present->pre == NULL)

                  {

                          head = present->next;

                          delete present;

                          present = head;

                  }

                  if (present->pre != NULL)

                  {

                          present->pre->next = present->next;

                          present->next->pre = present->pre;

                          head = present->pre;

                          delete present;

                  }

                  cout << "删除数据成功!" << endl; 

         }

         else cout << "删除失败。" << endl;  

}

 

bool linklist::check()

{//按学号查找并输出学生信息

         present = head;

         int idnumber;

         cin >> idnumber;

         while (present->next != NULL)

         {

                  if (idnumber == present->number)

                  {

                          present->average = (present->chinese + present->math + present->english + present->physics + present->chemistry + present->biology) / 6;

                          cout << "        姓名        学号    语文    数学    英语    物理    化学    生物         平均分" << endl;

                          cout << setw(12) << present->name << setw(12) << present->number << setw(8) << present->chinese << setw(8) << present->math << setw(8) << present->english

                                   << setw(8) << present->physics << setw(8) << present->chemistry << setw(8) << present->biology << setw(16) << present->average << endl;

                          return true;

                  }

                  else

                  {

                          present = present->next;

                          continue;

                  }

         }

         cout << "查无此人!" << endl;

         return false;

}

 

void linklist::setdata()

{//修改学生成绩

         int subject;

         cout << "请输入学生的学号: ";

         if (check())

         {       while (1)

           {//设置个循环修改成绩,按0或者超出选项退出循环

                          cout << " 1.语文                          2.数学" << endl

                                   << " 3.英语                         4.物理" << endl

                                   << " 5.化学                         6. 生物" << endl

                          << " 0.返回上级菜单                          " << endl;

                          cout << "请输入需要修改的科目编号及成绩: ";

                          cin >> subject;

                          switch (subject)

                          {

                          case 1:present->setlang();break;

                          case 2:present->setmath();break;

                          case 3:present->setenglish();break;

                          case 4:present->setphysics();break;

                          case 5:present->setchemistry();break;

                          case 6:present->setbiology();break;

                          case 0:cout << "回到上级菜单" << endl;;return;

                          default:

                          {

                                   cout << "回到上级菜单。" << endl;//这行可以不要

                                   return;

                          }

                          }

                          cout << "修改成功!" << endl;

                  }

         }

}

 

void linklist::setmore()

{//通过循环次数来控制插入人数

         cout << "请输入添加学生人数: ";

         int n;

         cin >> n;

         while (n--) insert_one();

}

 

void linklist::averagerank()

{//注意链表的尾结点是默认值,因为在创建链表的时候是在空节点上逆序创建的

         int  h = 0, k = 0;  present = head;

L:

         while (present->next->next != NULL)

         {

                  h = k;       

                  if (present->average <= present->next->average)

                  {

                          present = present->next;

                  }//无需互换              

                  if (present->average > present->next->average&&present->pre == NULL)

                  {

                          k++;

                          present->next = present->next->next;

                          present->next->pre->next = present;

                          present->pre = present->next->pre;

                          present->next->pre = present;

                          present->pre->pre = NULL;

                  }//头节点处链表间互换

                  if(present->average > present->next->average&&present->pre != NULL)

                  {  

                          if (present->next->next != NULL)

                          {//最后一个空结点不纳入考虑

                                   k++;

                                   present->pre->next = present->next;

                                   present->next = present->next->next;

                                   present->pre->next->next = present;

                                   present->pre->next->pre = present->pre;

                                   present->pre = present->pre->next;

                                   present->next->pre = present;

                          }

                  }

                  while (h != k)

                  {//若一次完整循环下来没有顺序变化,退出

                          while (present->pre != NULL) { present = present->pre; } goto L;

                  }

         }

         while (present->pre != NULL) { present = present->pre; }

         head = present;//因为头结点不为空,修改完后可能会被改变,此处从新定位头结点

         cout << "        姓名        学号    语文    数学    英语    物理    化学    生物                平均分" << endl;

         do{

                  present->average = (present->chinese + present->math + present->english + present->physics + present->chemistry + present->biology) / 6;

                          cout << setw(12) << present->name << setw(12) << present->number << setw(8) << present->chinese << setw(8) << present->math << setw(8) << present->english

                          << setw(8) << present->physics << setw(8) << present->chemistry << setw(8) << present->biology << setw(16) << present->average << endl;

                  present = present->next;

         } while (present->next != NULL);  

}

 

int main()

{

         cout << "                                                    " << endl;

         cout << "                             学生信息管理系统                     " << endl;

         cout << "                                                    " << endl;

         cout << "   1.添加一个学生信息                                   2.查询学生信息" << endl;

         cout << "   3.删除学生信息                                           4.将学生信息列表输出" << endl;

         cout << "   5.修改学生成绩                                           6.批量输入任意个数学生信息" << endl;;

         cout << "   7.按各门成绩平均分进行排序                   0.退出系统                         " << endl;

         cout << "                                                    " << endl;

 

         X.creat();//先建空表

         while (true) {

                  int choise;

                  cout << endl<<"请输入相应操作序号: " ;

                  cin >> choise;

                  switch (choise)

                  {

                  case 1:                X.insert_one();break;

                  case 2:

                  {      

                          cout << "请输入查询学生的学号: ";

                          X.check(); break;

                  }

                  case 3:       X.delete_data();break;

                  case 4:       X.output();break;

                  case 5:       X.setdata();break;

                  case 6:       X.setmore();break;

                  case 7:       X.averagerank();break;

                  case 0:

                          break;

                  default:

                          cout << "对不起,有关功能正在开发!" << endl;break;

                  }

                  if (!choise) break;

         }

         return 0;

}

学生成绩信息管理

标签:let   ios   public   continue   超出   log   不为   tla   res   

原文地址:http://www.cnblogs.com/zhangkeqian/p/7053692.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!