| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 248 人关注过本帖, 1 人收藏
标题:学生成绩管理系统,求助,帮忙看看怎么改
只看楼主 加入收藏
TongLee
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-6-12
结帖率:100%
  已结贴   问题点数:20  回复次数:4   
学生成绩管理系统,求助,帮忙看看怎么改
各位大神求帮忙~~成绩排序运行不了,不会改~~总成绩改成平均分也不会



#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
class student      
{
    friend class studentMessage;
    student      *next;
    char         name[30];
    char         num[30];
    double       score[6];
public:
    student()
    {
        strcpy(name, "null");
        strcpy(num, "null");
        for (int i = 0; i < 6; ++i) score[i] = 0;
    }
    student(const student &a)
    {
        strcpy(name, a.name);
        strcpy(num, a.num);
        for (int i = 0; i < 6; ++i)
            score[i] = a.score[i];
    }
    student &input()
    {
        cout << "姓名:";  cin >> name;
        cout << "学号:";  cin >> num;
        for (int i = 0; i < 5; ++i)
        {
            cout << "输入第" << (i + 1) << "门成绩:";
            cin >> score[i];
            score[5] += score[i];
        }
        return *this;
    }
    student* get_next()
    {
        return next;
    }
    void print()
    {
        printf("%8s %10s ", name, num);
        for (int i = 0; i < 6; ++i) printf(" %6.2f ", score[i]);
        printf("\n");
    }
    void Swap()
    {
        char temp[30];
        strcpy(temp, name);
        strcpy(name, next->name);
        strcpy(next->name, temp);
 
        strcpy(temp, num);
        strcpy(num, next->num);
        strcpy(next->num, temp);
 
        for (int i = 0; i < 6; ++i)
        {
            int tmp = score[i];
            score[i] = next->score[i];
            next->score[i] = tmp;
        }
    }
};
class studentMessage
{
protected:
    student *first;
    student *last;
public:
    studentMessage()
    {
        first = last = new student;
    }
    ~studentMessage()
    {
        Clear();
        delete first;
    }
    studentMessage &Append();         
    student *Find(const char *x);     
    void Query();                       
    studentMessage &Delete();           
    studentMessage &Clear();            
    studentMessage &Sort();            
    void print();                       
    int menu();                        
};
studentMessage &studentMessage::Append()
{
    student x;
    x.input();
    student *ptr = last;
    *ptr = x;
    last = new student;
    ptr->next = last;
    return *this;
}
studentMessage &studentMessage::Delete()
{
    char x[30];
    cout << "输入要删除的信息(学号或姓名)\n";
    cin >> x;
    student *ptr = Find(x);
 
    if (ptr == last)
    {
        cout << "未找到相关信息\n";
        return *this;
    }
    ptr->print();
    cout << "是否删除此信息?(是输入1,否输入0)";
    cin >> x;
    if (*x == '1')
    {
        if (ptr == first)
        {
            first = first->next;
            delete first;
        }
        else
        {
            student *temp = first;
            while (temp->next != ptr) temp = temp->next;
            temp->next = ptr->next;
            delete ptr;
        }
        cout << "已删除\n";
    }
    else
    {
        cout << "已取消\n";
    }
    return *this;
}
studentMessage &studentMessage::Clear()
{
    char ch[30];
    cout << "将删除所有信息。确认请按Y";
    cin >> ch;
    if (*ch != 'Y' && *ch != 'y')
    {
        cout << "已取消\n";
        return *this;
    }
    student *ptr = first;
    while (ptr != last)
    {
        student *next = ptr->next;
        delete ptr;
        ptr = next;
    }
    first = last;
    return *this;
}
void studentMessage::print()
{
    if (first == last)
    {
        cout << "暂无信息\n";
        return ;
    }
    cout << "---------------------------------成绩列表------------------------------" << endl;
    cout << "序号  姓名      学号      成绩1   成绩2   成绩3   成绩4   成绩5  总成绩" << endl;
    int no = 1;
    student *ptr = first;
    while (ptr != last)
    {
        printf("%3d:", no++);
        ptr->print();
        ptr = ptr->next;
    }
}
student *studentMessage::Find(const char *x)
{
    student *ptr = first;
    while (ptr != last)
    {
        if (strcmp(ptr->name, x) == 0 || strcmp(ptr->num, x) == 0)
            break;
        ptr = ptr->next;
    }
    return ptr;
}
void studentMessage::Query()
{
    char x[30];
    cout << "输入你要查询的信息(学号或姓名)";
    cin >> x;
    student *ptr = Find(x);
    if (ptr == last)
    {
        cout << "没有查询到相关信息\n";
    }
    else
    {
        ptr->print();
    }
}
studentMessage &studentMessage::Sort()
{
    int x;
    cout << "输入你想按照哪门课的成绩来排序?((1-5)总成绩输入6):";
    cin >> x;
    x--;
    student *ptr, *cnt = last;
    while (cnt != first)
    {
        ptr = first;
        while (ptr->next != cnt)
        {
            if (ptr->next->score[x] > ptr->score[x])
            {
                ptr->Swap();
            }
            ptr = ptr->next;
        }
        cnt = ptr;
    }
    return *this;
}
int studentMessage::menu()
{
    cout << "===============================\n";
    cout << "      学生成绩管理系统\n\n";
    cout << "      1.添加信息\n";
    cout << "      2.显示所有学生成绩\n";
    cout << "      3.查询信息\n";
    cout << "      4.删除信息\n";
    cout << "      5.成绩排序\n";
    cout << "      6.删除所有信息\n";
    cout << "      0.退出\n";
    cout << "===============================\n";
 
    int ch;
    cin >> ch;
    return ch;
}
int main()
{
    studentMessage ls;
    int ch;
    while (ch = ls.menu())
    {
        switch(ch)
        {
            case 2: ls.print(); break;
            case 1: ls.Append(); break;
            case 3: ls.Query(); break;
            case 4: ls.Delete(); break;
            case 5: ls.Sort(); break;
            case 6: ls.Clear(); break;
        }
    }
    return 0;
}
2018-06-12 12:44
TongLee
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-6-12
  得分:0 
附件: 您没有浏览附件的权限,请 登录注册
2018-06-12 12:48
幻紫灵心
Rank: 4
来 自:山咔咔里面
等 级:业余侠客
威 望:2
帖 子:40
专家分:215
注 册:2018-3-30
  得分:14 
怎么一个接一个来改作业的。。。
2018-06-12 13:33
TongLee
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-6-12
  得分:0 
回复 3楼 幻紫灵心
实在不会改了~~
2018-06-12 13:42







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038807 second(s), 8 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved