C++实现学生信息管理系统

#include <iostream>
#include <string>
using namespace std;
//todo 使用链表和Student 类的学生管理系统

class Student
{
private:
    string name;
    string sex;
    double all_grades, avr_grades;

public:
    static int total; //静态成员变量
    static double all_chinese_grades;
    static double all_math_grades;
    static double all_english_grades;
    double chinese, math, english;

public:
    int id;
    Student *next;
    Student *pre;
    void Set(string name, string sex, double chinese, double math, double english, Student *pre);
    void Calculate();
    void Display();
    void ShowAll();
};
int Student::total = 0;
double Student::all_chinese_grades = 0;
double Student::all_math_grades = 0;
double Student::all_english_grades = 0;
void Student::Calculate()
{
    all_grades = chinese + math + english;
    avr_grades = all_grades / 3;
}
void Student::Display()
{
    cout << "----------------------------" << endl;
    cout << "name:" << this->name << endl;
    cout << "id:" << this->id << endl;
    cout << "sex:" << this->sex << endl;
    cout << "chinese:" << this->chinese << endl;
    cout << "math:" << this->math << endl;
    cout << "english:" << this->english << endl;
    cout << "all_grades:" << this->all_grades << endl;
    cout << "avr_grades:" << this->avr_grades << endl;
    cout << "----------------------------" << endl;
}
void Student::Set(string name, string sex, double chinese, double math, double english, Student *pre)
{
    this->name = name;
    this->sex = sex;
    this->chinese = chinese;
    this->math = math;
    this->english = english;
    all_chinese_grades += chinese;
    all_english_grades += english;
    all_math_grades += math;
    Calculate();
    id = total++;
    next = NULL;
    this->pre = pre;
}
void Student::ShowAll()
{
    cout << "all_chinese:" << all_chinese_grades << endl;
    cout << "all_math:" << all_math_grades << endl;
    cout << "all_english:" << all_english_grades << endl;
}
void Show()
{
    cout << "1.Display all information" << endl;
    cout << "2.Add a Student" << endl;
    cout << "3.Delete a Student" << endl;
    cout << "4.Quit" << endl;
}
int main()
{
    //todo 声明变量
    string name;
    string sex;
    double chinese, math, english;
    //todo -----------构造头结点-------------------------
    Student *first_stu = new Student(); //todo first_student 不包含任何信息
    Student *head_stu = new Student();
    first_stu->next = head_stu;
    head_stu->Set("ck", "boy", 1, 1, 1, first_stu);
    Student *stu = head_stu;
    Student *p;
    //todo -----------------------------
    int temp; //todo 输入删除学生的学号
    int mode = 0;
    while (mode != 4)
    {
        Show();
        cin >> mode;
        switch (mode)
        {
        case 1:
        {
            p = first_stu->next;
            while (p != NULL)
            {
                p->Display();
                p = p->next;
            }
            p->ShowAll();
            break;
        }

        case 2:
        {
            cout << "请依次输入该学生的姓名,性别,语文,数学,英语成绩" << endl;
            Student *new_stu = new Student();
            cin >> name >> sex >> chinese >> math >> english;
            stu->next = new_stu;
            new_stu->Set(name, sex, chinese, math, english, stu); //todo 最后一个参数是把新建的结点的前驱点找到
            stu = new_stu;
            break;
        }
        case 3:
        {
            cout << "请输入删除学生信息的学号" << endl;
            cin >> temp;
            p = head_stu;
            if (temp > Student::total)
            {
                cout << "找不到这个学号" << endl;
                break;
            }
            while (p != NULL)
            {
                if (p->id == temp)
                {
                    p->pre->next = p->next;
                    while (p->next != NULL)
                    {
                        p = p->next;
                        p->id--;
                        Student::all_chinese_grades -= p->chinese;
                        Student::all_english_grades -= p->english;
                        Student::all_math_grades -= p->math;
                    }
                    break;
                }
                p = p->next;
            }
            break;
        }
        case 4:
        {
            return 0;
        }
        default:
        {
            cout << "重新输入" << endl;
            break;
        }
        }
    }
    return 0;
}

 

修正了已发现的所有错误.欢迎大家下载试用.. 一、项目名称:学校学生信息管理系统。 二、项目目标:实现对学校学生的信息管理——信息的建立和维护、信息的检索。 三、主要功能: 1.信息的输入:建立学生档案文件。 2.信息维护: 添加:增加新学生; 修改:学生信息的改变; 删除:学生减少。 3.信息处理 按要求检索学生信息; 按要求统计信息。 四、界面系统 1.系统管理员进入 (请输入密码) 2.一级菜单 (1 信息维护 2 信息检索 3 信息统计 4 退出) 3. 二级菜单 信息维护 (1 建立学生成绩文件 2 添加学生记录 3 删除学生记录 4 修改学生记录 5 返回上级菜单) 信息检索 (1 按班级查找 2 返回上级菜单) 信息统计 (1 成绩统计 2 返回上级菜单) 五、主要功能说明: 1.用口令(密码)形式验证管理员身份(可输入三次),合法者可进入,否则程序结束。 2.有关功能说明 1)建立学生成绩表(模块a) 建立新的学生成绩文件; 建立若干学生记录,包括姓名、学号、班级、课程编号、成绩。 2)添加学生记录(模块b) 在已存在的学生成绩文件中添加新记录。 3)删除学生记录(模块c) 在学生成绩文件中删除有三门课程不及格的学生记录; 删除前,逐条显示符合删除条件的学生姓名、成绩,确认后再删除。 4)修改学生信息(模块d) 输入学生学号,在学生成绩文件中找出该学生记录; 在屏幕上逐条显示该学生的各条记录; 每显示一条,询问是否修改,如果“Y”,输入修改后数据, 将文件原记录删除,保存新的记录; 5)按姓名和班级查找(模块e) 输入姓名显示相应信息。 6)信息统计(模块f) 同时按照班级和课程统计每门课程、每个班级的平均成绩,最高分、最低分; 在屏幕上先依次显示各门课程,对应的各个班级的统计数据。 7)退出信息管理系统,返回操作系统。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值