C++实现学生成绩管理系统最新版

学生成绩管理系统,供大家参考,具体内容如下

一、问题描述及功能要求

(1)输入同学的学号,姓名,三门科成绩(应用数学、大学英语、计算机应用基础)

(2)可以计算出每个学生三门课的平均成绩。

(3)可通过输入姓名、学号查询成绩,也可通过姓名修改学生信息,也可通过主界面删除学生信息,以及清楚所有信息

二、代码实现 带有注释

废话不说,直接代码,欢迎指正。
大家CV可能有不兼容的情况,可以跟我滴滴,尽可能解决问题地回复。

#include 
#include 
#include 
using namespace std;

#define null NULL

class student
{
    private:
        friend class studentMessage;
        student *next; //节点指针
        string name; //学生姓名
        int age; //年纪
        int id; //学号
        double score[3]; //三科成绩
        double total; //总分
        double average; //平均成绩
    public:
        student(string _name,int _age,int _id,double *_score)
        {
            name = _name;
            age = _age;
            id = _id;
            score[0] = _score[0];
            score[1] = _score[1];
            score[2] = _score[2];
            total = score[0]+score[1]+score[2];
            average = total/3;
            next = NULL;
        }
        student() //为studentMessage初始化头结点用
        {
            name = "null";
            age = 0;
            id = 0;
            score[0]=score[1]=score[2]=0;
            total = 0;
            average = 0;
            next = NULL;
        }
        ~student(){}
        void swap(student*);
};


void student::swap(student *q)
{
    string _name;
    int _age,_id;
    double _score[3],_total,_average;

    _name = name;
    name = q->name;
    q->name = _name;

    _age = age;
    age = q->age;
    q->age = _age;

    _id = id;
    id = q->id;
    q->id = _id;

    _score[0] = score[0];
    score[0] = q->score[0];
    q->score[0] = _score[0];

    _score[1] = score[1];
    score[1] = q->score[1];
    q->score[1] = _score[1];

    _score[2] = score[2];
    score[2] = q->score[2];
    q->score[2] = _score[2];

    _total = total;
    total = q->total;
    q->total = _total;

    _average = average;
    average = q->average;
    q->average = _average;
}






class studentMessage
{
    private:
      student *first; //头指针
      int num; //信息中的学生人数
    public:
        studentMessage()
        {
            num = 0; //初始化学生人数为0
            first = new student;  //初始化头结点
        }
        ~studentMessage(){delete first;}

        /*管理系统常规操作*/
        void Insret(void); //插入
        void Display(void); //显示
        void Delete(void); //删除
        void Search(void); //搜索
        void Change(void); //改动
        void sortByLesson1(void); //按成绩一来排序
        void sortByLesson2(void); //按成绩二来排序
        void sortByLesson3(void); //按成绩三来排序
        void sortByTotal(void); //按总分来排序
        void SearchByid(void); //按照学号查找
        void SearchByname(void); //按照姓名查找
        int menu(void); //初始的菜单
        void clear(void); //清空列表
};


int studentMessage::menu(void)
{
    int ch;
    cout<<"**********************************************************************"<> ch;
    cout<<"\n\n\n"<>name;
    cout<<"请输入学生年龄: ";
    cin>>age;
    cout<<"请输入学生学号: ";
    cin>>id;
    cout<<"下面请输入学生三门课程成绩: ";
    cout<>score[0];
    cout<<"请输入第二门课的成绩: ";cin>>score[1];
    cout<<"请输入第三门课的成绩: ";cin>>score[2];
    cout<next != NULL)
    {
        p = p->next;
    }
    p->next = newstu;
    newstu->next = null;
    num++;
}



void studentMessage::Display(void)
{
    if(num == 0)
    {
        cout<<"当前记录中无学生..."<next;
        while(p != null)
        {
            cout<<"姓名:"<name<<"  ";
            cout<<"年龄:"<age<<"  ";
            cout<<"学号:"<id<<"  ";
            cout<<"三门课程成绩: "<score[0]<<" "<score[1]<<" "<score[2]<<"  ";
            cout<<"总分:"<total<<"  ";
            cout<<"平均分:"<average<next;
        }
    }
}


void studentMessage::Delete(void)
{
    student *p = first;
    student *pre = first;
    while(p->next != NULL)
    {
        pre = p;
        p = p->next;
    }
    pre->next = NULL;
    delete p;
    num--;
}


void studentMessage::Search(void)
{
    int temp = 0;
    cout<<"请输入查找的条件,有如下选项..."<>temp;
    switch(temp)
    {
        case 1: SearchByid(); break;
        case 2: SearchByname(); break;
        default: cout<<"输入有误..."<> _id;
    student *p = first->next;
    while(p != null)
    {
        if(p->id == _id)
        {
            flag = 1;
            cout<<"下面是查找匹配结果:"<name<<"  ";
            cout<<"年龄:"<age<<"  ";
            cout<<"学号:"<id<<"  ";
            cout<<"三门课程成绩: "<score[0]<<" "<score[1]<<" "<score[2]<<"  ";
            cout<<"总分:"<total<<"  ";
            cout<<"平均分:"<average<next;
    }
    if(flag == 0)
    {
        cout<<"抱歉,记录中没有查找匹配项..."<> _name;
    student *p = first->next;
    while(p != null)
    {
        if(p->name == _name)
        {
            flag = 1;
            cout<<"下面是查找匹配结果:"<name<<"  ";
            cout<<"年龄:"<age<<"  ";
            cout<<"学号:"<id<<"  ";
            cout<<"三门课程成绩: "<score[0]<<" "<score[1]<<" "<score[2]<<"  ";
            cout<<"总分:"<total<<"  ";
            cout<<"平均分:"<average<next;
    }

    if(flag == 0)
    {
        cout<<"抱歉,记录中没有查找匹配项..."<> _name;
    student *p = first->next;
    while(p != null)
    {
        if(p->name == _name)
        {
            flag = 1;
            cout<<"该学生当前信息如下:"<name<<"  ";
            cout<<"年龄:"<age<<"  ";
            cout<<"学号:"<id<<"  ";
            cout<<"三门课程成绩: "<score[0]<<" "<score[1]<<" "<score[2]<<"  ";
            cout<<"总分:"<total<<"  ";
            cout<<"平均分:"<average<> temp;
            switch(temp)
            {
                case 1:
                    {
                        cout<<"请输入新的学号:";cin>>_id;
                        p->id = _id;
                    }
                    break;
                case 2:
                    {
                        cout<<"请输入新的年龄:";cin>>_age;
                        p->age = _age;
                    }
                    break;
                case 3:
                    {
                        cout<<"请按指示修改课程成绩..."<> course;
                        if(course == 1)
                        {
                            cout<<"请输入修改后的第一门课的成绩:"; cin >> p->score[0];
                        }
                        course = 0;

                        cout<<"是否需要修改第二门课程成绩?(需要输入【1】不需要输入【0】)"<> course;
                        if(course == 1)
                        {
                            cout<<"请输入修改后的第二门课的成绩:"; cin >> p->score[1];
                        }
                        course = 0;

                        cout<<"是否需要修改第三门课程成绩?(需要输入【1】不需要输入【0】)"<> course;
                        if(course == 1)
                        {
                            cout<<"请输入修改后的第三门课的成绩:"; cin >> p->score[2];
                        }
                        course = 0;

                        p->total = p->score[0]+p->score[1]+p->score[2];
                        p->average = p->total/3;

                        cout<<"修改后的信息如下: "<name<<"  ";
                        cout<<"年龄:"<age<<"  ";
                        cout<<"学号:"<id<<"  ";
                        cout<<"三门课程成绩: "<score[0]<<" "<score[1]<<" "<score[2]<<"  ";
                        cout<<"总分:"<total<<"  ";
                        cout<<"平均分:"<average<next;
    }
    if(flag == 0)
        cout<<"当前记录中没有次学生..."<next;
    while(p->next != null)
    {
        student *q = p->next;
        while(q != null)
        {
            if(p->score[0] > q->score[0])
            {
                p->swap(q);
            }
            q = q->next;
        }
        p = p->next;
    }
}

//按照科目二排序
void studentMessage::sortByLesson2(void)
{
    student *p = first->next;
    while(p->next != null)
    {
        student *q = p->next;
        while(q != null)
        {
            if(p->score[1] > q->score[1])
            {
                p->swap(q);
            }
            q = q->next;
        }
        p = p->next;
    }
}

//按照科目三排序
void studentMessage::sortByLesson3(void)
{
    student *p = first->next;
    while(p->next != null)
    {
        student *q = p->next;
        while(q != null)
        {
            if(p->score[2] > q->score[2])
            {
                p->swap(q);
            }
            q = q->next;
        }
        p = p->next;
    }
}

//按照总成绩排序
void studentMessage::sortByTotal(void)
{
    student *p = first->next;
    while(p->next != null)
    {
        student *q = p->next;
        while(q != null)
        {
            if(p->total > q->total)
            {
                p->swap(q);
            }
            q = q->next;
        }
        p = p->next;
    }
}

void studentMessage::clear(void)
{
    student *p = first->next;
    while(p != null)
    {
        first->next = p->next;
        p->next = null;
        delete p;
        p = first->next;
    }
}



int main()
{
    studentMessage stulist;
    int ch;
    while(ch = stulist.menu())
    {
        switch(ch)
        {
            case 1: stulist.Display(); break;
            case 2: stulist.Insret(); break;
            case 3: stulist.Search(); break;
            case 4: stulist.Change(); break;
            case 5: stulist.Delete(); break;
            case 6: stulist.clear(); break;
            default: cout<<"请按要求输入..."< 
 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(C++实现学生成绩管理系统最新版)