当前位置:编程学习 > C/C++ >>

C++学生成绩排名系统

2、设计一个学生成绩排名系统,该系统的主要功能如下:
1)  具备对成绩的管理功能(添加、删除、排序)
2)  具备对成绩的统计功能(最高分,最低分,平均分,及格率等)
3)  具备按学号、姓名、或课程名查询成绩的功能。
备注:成绩记录以下信息:班级,学号,姓名,课程名,成绩(百分制)。可以用能表示学生成绩的结构体数组存储数据。

这个号没积分···改日一定奉上···谢谢了···急呀·

答案:#include <iostream>
#include <string>
using namespace std;

class Node
{
public:
 string banji;//班级
 string xuehao;
 string name;
 string kcm;//课程名
 int score;
 int index;
 Node *next;

 Node()
 {
  index = 0;
  next = NULL;
 }
 Node(string _banji, string _xuehao, string _name, string _kcm, int _score, Node *_next)
 {
  banji = _banji;
  xuehao = _xuehao;
  name = _name;
  kcm = _kcm;
  score = _score;
  next = _next;
  index = 0;
 }
};

class Manage
{
public:
 Manage();
 void app();
 void del(string &_xuehao);
 void sort();
 void stat();//统计
 void search(string &_xuehao);

private:
 Node *head, *tail;
};

Manage::Manage()
{
 head = tail = NULL;
}

void Manage::app()
{
 Node *u;
 string banji;//班级
 string xuehao;
 string name;
 string kcm;//课程名
 int score;
 char ch;
 cout << "  班级  学号  姓名  课程名  成绩" << endl;
 do
 {
  cin >> banji;
  cin >> xuehao;
  cin >> name;
  cin >> kcm;
  cin >> score;
  u = new Node(banji, xuehao, name, kcm, score, NULL);
  if (head == NULL)
  {
   head = u;
   tail = u;
  }
  else
  {
   tail->next = u;
   tail = u;
  }

  cout << "是否继续(y/n)";
  cin >> ch;
 } while (ch == 'y');
}

void Manage::search(string &_xuehao)
{
 Node *u;
 cout << "查找结果:" << endl;
 cout << "  班级  学号  姓名  课程名  成绩" << endl;
 for (u = head; u != NULL; u = u->next)
 {
  if (u->xuehao == _xuehao)
  {
   cout << u->banji << "  " << u->xuehao << " " <<
   u->name << " " << u->kcm << " " << u->score << endl;
  break;
  }
 }
 if (u == NULL)
  cout << "不存在查找对象!" << endl;
}

void Manage::del(string &_xuehao)
{
 Node *u;
 Node *p;
 if (head == NULL)
 {
  cout << "error" << endl;
  exit(0);
 }
 else
 {
  for (u = head; u != NULL; u = u->next)
  {
   if (u->xuehao == _xuehao)
   {
    if (u == head)
    {
     head = head->next;
     break;
    }
    else
    {
     p = u->next;
     break;
    }
    p = u;
   }  
  }
 }
}

void Manage::stat()
{
 double aver, max, min, percent;
 Node *u;
 int countAll = 0, count = 0;
 min = max = head->score;
 for (u = head; u; u = u->next)
 {
  aver += u->score;
  if (u->score >= max)
   max = u->score;
  if (min > u->score)
   min = u->score;
  if (u->score >= 60.0)
   count++;
  countAll++;
 }

 aver = aver / countAll;
 percent = count / countAll;
 cout << "平均分:" << aver << endl;
 cout << "最高成绩:" << max << endl;
 cout << "最低成绩:" << min << endl;
 cout<< "及格率:" << percent << endl;  
}


void Manage::sort()
{
 Node *temp, *temp2;
 double s;
 for(temp=head ;temp;temp=temp->next)
 {   
   s = temp->score;
    if (head->next != NULL)
     for(temp2 = head,temp->index=1; temp2; temp2=temp2->next)
      if(temp2->score > s)
       temp->index++;
 }

 cout << "  班级  学号  姓名  课程名  成绩" << endl;
 int count = 0;
 for (Node *u = head; u; u = u->next)
  count++;
 for (int i = 1; i <= count; i++)
  for (Node *s = head; s; s = s->next)
   if (s->index == i)
    cout << s->banji << " " << s->xuehao << " " <<
    s->name << " " << s->kcm << " " << s->score << endl;
}


int main()
{

 Manage m;
 int operChoice;
 do
 {
  cout<<endl;
  cout<<"                *************************"<<endl;
  cout<<"                *      主   菜  单      *"<<endl;
  cout<<"                *                       *"<<endl;
  cout<<"                * (1) 统计学生成绩      *"<<endl;
  cout<<"                *                       *"<<endl;
  cout<<"                * (2) 删除学生成绩记录  *"<<endl;
  cout<<"                *                       *"<<endl;
  cout<<"                * (3) 增加学生成绩记录  *"<<endl;
  cout<<"                *                       *"<<endl;
  cout<<"                * (4) 查询学生成绩记录  *"<<endl;
  cout<<"                *                       *"<<endl;
  cout&

上一个:关于C++的一个问题
下一个:在C++中用什么语句来替代goto

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,