鱼C论坛

 找回密码
 立即注册
查看: 2180|回复: 1

求0大神的帮忙,程序改错和完善,刚刚学不大动

[复制链接]
发表于 2017-6-12 12:21:01 | 显示全部楼层 |阅读模式

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

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

x
C++成绩管理
        成绩记录薄,每个学生信息包括:学号、姓名、成绩
        实现的功能:
                输入学生成绩
                按学号或姓名查询成绩
                添加成绩记录
                修改指定姓名的学生成绩
                显示输出60分以下,60~79,80~89,90分以上各分数段的学生信息。
                找出最低成绩和最高成绩
                计算平均分
#include <iomanip>
#include <iostream>
#include <fstream>
#include <vector>
#include <conio.h>
#include <stdlib.h>
#include <string>
#include <process.h>
#include <algorithm>
#include <stdio.h>
using namespace std;

struct student //相当于类的公有类型
{
char name[10];         ///   姓名
char  xuehao[10];         ///   学号
float  score;         ///   分数
student *next;
};
///////////-------定义类-----------------------////////////

class studentmassage
{
    student *p1,*p2,*end,*head;
public:

  ~studentmassage() /////----析构函数------------------------
{

while(head)
{
  p1=head->next;
  delete head;
  head=p1;
}
}
//成员函数
void ShowMenu();  //菜单
void Input(student *p);  //输入学生信息
student *find(student *head,char *p);  //按照学号或姓名查询学生成绩记录(可查找多个同名数据)
void findgd();            //  找出最低成绩和最高成绩
student *input(student *head);         //  增加学生成绩记录
student *showfs(student *head);   //显示输出学生分数段信息
void average();                      //计算平均分
friend void total(student*head);
//student *getNext(){return next;}
student *insert(student *head);   //修改成绩
student*Inputs(); //用于添加数据的子函数
void output (student *head);
void delay()  
    {  
        int n = 1000000000;  
        while (n--)  
            ;  
    }  
student *FindItem(char * name)  //查找姓名
    {  
        for (student * p = head; p->next != end; p = p->next)//匹配成功则返回上一个指针,不成功就返回空   
        if (!strcmp(p->next->name, name))return p;  
        return NULL;  
    }  
    student *FindID(char * xuehao)  //查找学号
    {  
        for (student * p = head; p->next != end; p = p->next)//匹配成功则返回上一个指针,不成功就返回空   
        if (!strcmp(p->next->xuehao, xuehao))return p;  
        return NULL;  
    }  
};//----------------------------------------------------
void studentmassage::ShowMenu()  //菜单
{  
    cout << "********************************************************************************" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓〓  ☆   学 生 成 绩 管 理 系  统     ☆  〓〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓★★★★★         ★★★★★★★         ★★★★★〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓★  ☆          1.输入学生成绩        ☆  ★〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓★  ☆          2.按照学号或姓名查询成绩☆★〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓★  ☆          3.添加成绩记录        ☆  ★〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓★  ☆          4.修改指定姓名的学生成绩☆★〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓★  ☆          5.显示输出60分以下,60-79,80-89,90分以上各分数段的学生信息☆★〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓★  ☆          6.找出最低成绩和最高成绩☆★〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓★  ☆          7.计算平均分          ☆  ★〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "〓〓〓〓〓〓〓〓〓★  ☆          0.安全退出系统        ☆  ★〓〓〓〓〓〓〓〓〓" << endl;  
    cout << "\n\t\t\n\t\t请选择:";  
}  
////----------------///////
void studentmassage::Input(student *p)//输入学生成绩
{
   cout<<setw(6)<<"姓名"<<setw(8)<<" 学号"<<setw(8)<<"c++"<<endl;
   cin>>p->name >>p->xuehao;
   cin >>p->score;
}
void studentmassage::output (student *head)//用于输出
{ p1=head;
while(p1!=NULL)
{
   cout<<setw(6)<<p1->name<<setw(8)
   <<p1->xuehao<<setw(8)<<p1->score<<endl;
   p1=p1->next ;
}
}
student*studentmassage::find(student *head,char *p) //按照学号或姓名查询学生成绩记录
{
        char name[10], xuehao[10];  
    int x;  
    student * p = NULL;  
    cout << "\n\t\t*********************************\n";  
    cout << "\t\t※ 1.按学生的姓名查找\n\t\t※ 2.按学生学号查找";  
    cout << "\n\t\t*********************************\n请选择:";  
    cin >> x;  
    switch (x)  
    {  
    case 1:{cout << "\t\t请输入要查找的学生的姓名:"; cin >> name;  
        if (p = FindItem(name))  
        {  
            p->Next->output();  
            delay();  
            cout << "输入任意字符!继续……";  
            getchar();  
        }  
        else  
        {  
            cout << "\t\t没有找到该姓名的学生!" << '\n' << endl;  
            delay();  
            cout << "输入任意字符!继续……";  
            getchar();  
        }  
    }break;  
    case 2:  
    {  
              cout << "\t\t请输入要查找的学生的学号:"; cin >> xuehao;  
              if (p = FindID(xuehao))  
              {  
                  p->Next->output();  
                  delay();  
                  cout << "输入任意字符!继续……";  
                  getchar();  
              }  
              else  
              {  
                  cout << "\t\t没有找到该学好的学生!" << '\n' << endl;  
                  delay();  
                  cout << "输入任意字符!继续……";  
                  getchar();  
              }  
    }break;  
    }  

}
student *studentmassage::input(student *head)   //  增加学生成绩记录
{  p1=new student; //动态分配内存
   p2=head;
   Input(p1); //调用函数 增加数据
  if(head ==NULL)
  {
   head=p1;
   p1->next =NULL;
    return head;
  }
  while(p2->next !=NULL)
            p2=p2->next;
       p2->next=p1;
        p1->next=NULL;
                cout << "添加成功!" << endl;  
        cout << "输入任意字符(按任意键)!继续……";  
        getchar();
     return head;
}
student* studentmassage::insert(student *head)  //修改指定姓名的学生成绩  
{  
    char name1[10];
    student  *p = NULL;  
    cout << "\t\t请输入要修改的人的姓名:"; cin >> name1;  
        if (p=FindItem(name1)) //调用查找函数
        {
        cout << "\t\t已找到学生的信息,请输入新的成绩!" << endl;
                Input(p);  //调用输入函数
        cout << "修改成功!" << endl;  
        cout << "输入任意字符!继续……";  
        getchar();  
    }  
    else  
    {  
        cout << "\t\t没有找到!" << endl;   
        cout << "输入任意字符!继续……";  
        getchar();  
    }  
        return head;
}
student* studentmassage::insert(student *head)  //修改指定姓名的学生成绩  
{  
    char name1[10];
    student * p = NULL;  
    cout << "\t\t请输入要修改的人的姓名:"; cin >> name1;  
        if (p=FindItem(name1)) //调用查找函数
        {
        cout << "\t\t已找到学生的信息,请输入新的成绩!" << endl;
                p->next->Input(p);  //调用输入函数
        cout << "修改成功!" << endl;  
        cout << "输入任意字符!继续……";  
        getchar();  
    }  
    else  
    {  
        cout << "\t\t没有找到!" << endl;   
        cout << "输入任意字符!继续……";  
        getchar();  
    }  
        return head;
}
student *studentmassage::showfs(student *head)      //显示输出学生分数段信息
{
        int n=0;
        char ch;
        cout<<"A->60分以下;B->60~70分之间;C->70~80分之间;D->80~90分之间;E->90~100分之间:"<<endl; cin>>ch;
        switch(ch)
        {
    case 'A':while(head)
                         {
                       if(head->score<=60)  {head->Input();n++;} head=head->next();break;
                         }
        case 'B':while(head)
                         {
                                 if(head->score>60&&head->score<=70)  {head->Input();n++;} head=head->next;break;
                         }
        case 'C': while(head)
                          {
                                  if(head->score>70&&head->score<=80)  {head->Input();n++;} head=head->next;break;
                          }
        case 'D': while(head)
                          {
                                  if(head->score>80&&head->score<=90)  {head->Input();n++;} head=head->next;break;
                          }
        case 'E': while(head)
                          {
                                  if(head->score>90&&head->score<=100)  {head->Input();n++;} head=head->next;break;
                          }
                          default:
                          cout<<"该分段内没有您要找的学生信息!"<<endl;
        }
        cout << "输入任意字符!继续……";  
        getchar();  
        return head;       
}
void studentmassage::average()//计算平均分
{
        student *p1=next;//student链表头指针赋给p1
        double count=0;
        double sum;
        if(p1==NULL)
                cout<<"无学生信息!"<<endl;
        else
        {
                while(p1)
                {
                        count++;
                        sum=sum+p1->score;
                        p1=p1->next;
                }
        cout<<"\n\t\t平均分:"<<(sum/count)<<endl;
        }
        getchar();
}
void studentmassage::findgd()//显示最高分和最低分
{
        student *p1=next;//student链表头指针赋给p1
        double count=0;
        double max=0,min=0;
        if(p1==NULL)
                cout<<"无学生信息!"<<endl;
        else
        {
                while(p1)
                {
                        count++;
                        if(p1->score>max)max=p1->score;
                        else min=p1->score;
                        p1=p1->next;
                }
                cout<<"\n\t\t最高分: "<<max<<endl;
        cout<<"\n\t\t最低分: "<<min<<endl;
        }
        getchar();
}
void error()
{
  cout<<"错误,这还是一个空系统,请输入数据"<<endl;
  getchar();

}
///////////////////------------main函数--------//////////////////-----------
int main(void)
{  
        studentmassage stus;
    student *head=NULL;
    student *pd; //临时指针, 用于查找函数
    char choice; //用于存放用户的选择项
  char name[10]; //查找,删除记录的 key
   stus.ShowMenu();
  int n=0;
  cin>>choice;
if(choice=='0')  //安全退出
  {   cout<<"谢谢使用,再见"<<endl;
   exit(0);
  }
  switch(choice)
  {
  case '1':
   head=stus.Input(head); break;
  case '5':
  if(head==NULL)
  {
      error();
          break;
  }
   cout<<head->xuehao<<"学号"<<head->name<<" 姓名"
   <<head->score<<"c++分数"<<endl;
   stus.showfs(head);
   getchar();break;
  case '7':
  if(head==NULL)
  {
  error();
  break;
  }
   //stus.average(head);
  stus.average();
   getchar();break;
  case '2':
  if(head ==NULL)
  {
  error(); //调用函数输出错误信息
  break;
  }
   cout<<"请输入想要查找的学生姓名"<<endl;
      cin>>name;
   pd=head;
   cout<<head->xuehao<<"学号"<<head->name<<" 姓名"
   <<head->score<<"c++分数"<<endl;
  while(pd)   // 循环调用函数, 用于输出多个的同名学生成绩
  {  
  pd=stus.find (pd,name);
     if(pd==NULL)
break;
  pd=pd->next ; //指针指向当前以找到的下一个节点,用于查找多个学生
  }
  getchar();
   break;
  case '4':
  if(head==NULL)
  {
  error();
  break;
  }
     cout<<"请输入想要删除学生姓名"<<endl;
   cin>>name;
   head=stus.insert(head);
   getchar();
   break;
   case '3':
     if(head==NULL)
{
error();
break;
}
         stus.findgd();
        head=stus.input(head);
         break;
case '6':
if(head==NULL)
{
error();
break;
}
        stus.findgd();
        cout<<"最高分和最低分"<<endl;
       getchar();break;
      default :
    cout<<" 对不起,您的输入有误,请重新输入。\n";
    getchar(); break;
  }
  getchar();
return 0;
}

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

使用道具 举报

发表于 2017-6-17 22:48:02 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-7-1 19:00

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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