栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++学生管理系统

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++学生管理系统

C++学生管理系统 student.h头文件
#pragma once
#include
#include
#include
#include
#include
#include
using namespace std;
void Creat_Student();
class student {
private:
	int id;
	string name;
	int age;
	string sex;
	string classes;
	float English;
	float math;
	float Chinese;
public:
	student();
	student(int _id,string _name,int _age,string _sex,string _cla,float _en,float _math,float _ch):id(_id),
		age(_age),name(_name),sex(_sex),classes(_cla),English(_en),math(_math),Chinese(_ch){}
	void friend Creat_Student();
	void friend In_File();
	int getid()const;
	string getname()const;
	int getage()const;
	string getclasses()const;
	float getEnglish()const;
	float getmath()const;
	string getsex()const;
	float getChinese()const;

	void  setid(int _id);
	void  setname(string _name);
	void  setage(int _a);
	void  setclasses(string _cl);
	void  setEnglish(float _en);
	void  setmath(float mt);
	void  setsex(string _sex);
	void setChinese(float ch);

};

#student.cpp文件
#include"student.h"

student::student()
{
     id=0;
     name="NULL";
    age=0;
    sex="NULL";
    classes="NULL";
    English=0.0;
    math=0.0;
    Chinese=0.0;
}
int student::getid()const
{
    return id;
}
string student::getname()const
{
    return name;
}
int student::getage()const
{
    return age;
}
string student::getclasses()const
{
    return classes;
}
float student::getEnglish()const
{
    return English;
}
float student::getmath()const
{
    return math;
}
string student::getsex()const
{
    return sex;
}
float student::getChinese()const
{
    return Chinese;
}

void  student::setid(int _id)
{
    id=_id;
}
void  student::setname(string _name)
{
    name= _name;
}
void  student::setage(int _a)
{
     age=_a;
}
void  student::setclasses(string _cl)
{
    classes=_cl;
}
void  student::setEnglish(float _en)
{
     English=_en;
}
void  student::setmath(float mt)
{
    math=mt;
}
void  student::setsex(string _sex)
{
     sex= _sex;
}
void student::setChinese(float ch)
{
    Chinese = ch;
}
主界面
#include"student.h"
#include
#include
using namespace std;
student STU[100];
student InStu[100];
void Delete_Student();
void In_File();
void Sort_Student();
void Statistics_Student();
void Find_Student();
void Out_File();
void Print_Student();
void Change_Student();
void Ffindfile(); 
 void  Mfindfile();
 void dfindfile();
 //成绩排序功能
 void change(student& a1, student& a2);
int stunum;

int main()
{
    while(1)
    {
        system("color 5E");
        system("date/t");
        system("time/t");
        cout << "*===============================================================================================*" << endl;
        cout << "**&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&欢迎使用学生管理系统&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&**" << endl;
        cout << "**                                    1.新增学生信息                                           **" << endl;
        cout << "**                                    2.删除学生信息                                           **" << endl;
        cout << "**                                    3.导入学生信息(已经保存于文件的信息)                     **" << endl;
        cout << "**                                    4.学生信息排序                                           **" << endl;
        cout << "**                                    5.学生信息统计                                           **" << endl;
        cout << "**                                    6.学生信息查找                                           **" << endl;
        cout << "**                                    7.学生信息保存                                           **" << endl;
        cout << "**                                    8.显示学生信息                                           **" << endl;
        cout << "**                                    9.修改学生信息                                           **" << endl;
        cout << "**                                    0.    退出                                               **" << endl;
        cout << "**&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&**" << endl;
        cout << "*===============================================================================================*" << endl;
        cout << "请输入您要选择的服务种类:(‘0’~‘9’)n";
        int num;
        cin >> num;
        switch (num)
        {
        case 1:system("CLS"); Creat_Student(); system("pause"); break;//CLS为清屏函数,pause 为暂停
        case 2:system("CLS"); Delete_Student(); system("pause"); break;
        case 3:system("CLS"); In_File(); system("pause"); break;
        case 4:system("CLS"); Sort_Student(); system("pause"); break;
        case 5:system("CLS"); Statistics_Student(); system("pause"); break;
        case 6:system("CLS"); Find_Student(); system("pause"); break;
        case 7:system("CLS"); Out_File(); system("pause"); break;
        case 8:system("CLS"); Print_Student(); system("pause"); break;
        case 9:system("CLS"); Change_Student(); system("pause"); break;
        case 0:system("CLS"); cout << "谢谢使用!"; exit(0); system("pause");
        default:system("CLS"); printf("无效输入!nn"); system("pause");

        }
    }
    return 0;
}
创建学生文件
//创建学生文件
void Creat_Student()
{
    cout << "请输入要添加的学生数量:" << endl;
    int num;
    cin >> num;
    student* stu = new student[num];
    for (int i = 0; i < num; i++)
    {
        cout << "请输入第" << i + 1 << "位学生的姓名:";
        cin >> stu[i].name;

        cout << "请输入第" << i + 1 << "位学生的学号:";
        cin >> stu[i].id;

        
        
       
        cout << "请输入第" << i + 1 << "位学生的性别:";
        cin >> stu[i].sex;

        cout << "请输入第" << i + 1 << "位学生的年龄:";
        cin >> stu[i].age;
        cout << "请输入第" << i + 1 << "位学生的班级:";
        cin >> stu[i].classes;
        cout << "请输入第" << i + 1 << "位学生的英语成绩:";
        cin >> stu[i].English;

        cout << "请输入第" << i + 1 << "位学生的语文成绩:";
        cin >> stu[i].Chinese;

        cout << "请输入第" << i + 1 << "位学生的数学成绩:";
        cin >> stu[i].math;

        STU[stunum++] = stu[i];
        printf("%d", STU[stunum - 1].id);
    }
}
删除学生信息
void Delete_Student()
{
    int num;
    do {
        cout << "请输入要删除的学生信息对应的序号:";

        cin >> num;
        int j = num - 1;
        cout << num << "t" << STU[j].getname() << "t""t" << STU[j].getid() << endl;
        cout << "是否确定删除该学生信息【1】是;【0】否:";

        cin >> num;
        for (int i = j; i < stunum; i++)
        {
            STU[i] = STU[i + 1];
        }
        stunum--;

        cout << "是否继续删除学生信息:【1】是;【0】否:";
        cin >>num;
    } while (num != 0);
}
从文件读取信息
/友元函数访问类 从文件读取信息
void In_File() 
{
    //char buffer[250];
    ifstream infile("student.txt", ios::in);
    if (!infile.is_open())
    {
        cout << "文件打开失败!n";
    }
    else
    {
      
        while (!infile.eof())
        {
            infile >> STU[stunum].name >> STU[stunum].id >> STU[stunum].sex >> STU[stunum].age >> STU[stunum].classes >> STU[stunum].English >> STU[stunum].Chinese >> STU[stunum].math;
            cout<< STU[stunum].name <<"t" << STU[stunum].id << "t" << STU[stunum].sex << "t" << STU[stunum].age << "t" << STU[stunum].classes << "t" << 
                STU[stunum].English << "t" << STU[stunum].Chinese << "t" << STU[stunum].math << endl;
            
            stunum++;
        }
    }

}
//删除学生信息
//删除学生信息
void Delete_Student()
{
    int num;
    do {
        cout << "请输入要删除的学生信息对应的序号:";

        cin >> num;
        int j = num - 1;
        cout << num << "t" << STU[j].getname() << "t""t" << STU[j].getid() << endl;
        cout << "是否确定删除该学生信息【1】是;【0】否:";

        cin >> num;
        for (int i = j; i < stunum; i++)
        {
            STU[i] = STU[i + 1];
        }
        stunum--;

        cout << "是否继续删除学生信息:【1】是;【0】否:";
        cin >>num;
    } while (num != 0);



}
学生信息统计
//学生信息统计
void Statistics_Student() {
    int n;
    int english_num = 0;
    int english_standard = 0;
    int english_average = 0;

    int math_num = 0;
    int math_standard = 0;
    int math_average = 0;

    int ch_num = 0;
    int ch_standard = 0;
    int ch_average = 0;
    do
    {

        cout << "请输入想要统计的科目【1】数学;【2】英语;【3】语文;";
        cin >> n;
        switch (n) {
        case 1:

            for (int i = 0; i < stunum; i++)
                math_average += STU[i].getmath();
            math_average /= stunum;
            for (int i = 0; i < stunum; i++)
                math_standard += (STU[i].getmath() - math_average) * (STU[i].getmath() - math_average);
            math_standard = sqrt(math_standard / stunum);
            for (int i = 0; i < stunum; i++)
            {
                if (STU[i].getmath() >= 60)
                    math_num++;
                else
                    continue;
            }
            cout << "数学平均分为:" << math_average << endl;
            cout << "数学标准差为:" << math_standard << endl;
            cout << "数学及格人数为:" << math_num << endl;
            break;
        case 2:

            for (int i = 0; i < stunum; i++)
                english_average += STU[i].getEnglish();
            english_average /= stunum;
            for (int i = 0; i < stunum; i++)
                english_standard += (STU[i].getEnglish() - english_average) * (STU[i].getEnglish() - english_average);
            english_standard = sqrt(english_standard / (stunum));
            for (int i = 0; i < stunum; i++)
            {
                if (STU[i].getEnglish() >= 60)
                    english_num++;
                else
                    continue;
            }
            cout << "英语平均分为:" << english_average << endl;
            cout << "英语标准差为:" << english_standard << endl;
            cout << "英语及格人数为:" << english_num << endl;
            break;
        case 3:

            for (int i = 0; i < stunum; i++)
                ch_average += STU[i].getChinese();
            ch_average /= stunum;
            for (int i = 0; i < stunum; i++)
                ch_standard += (STU[i].getChinese() - ch_average) * (STU[i].getChinese() - ch_average);
            ch_standard = sqrt(ch_standard / stunum);
            for (int i = 0; i < stunum; i++)
            {
                if (STU[i].getChinese() >= 60)
                    ch_num++;
                else
                    continue;
            }
            cout << "语文平均分为:" << ch_average << endl;
            cout << "语文标准差为:" << ch_standard << endl;
            cout << "语文及格人数为:" << ch_num << endl;
            break;
       
        default:
            break;
        }
            cout << "是(1)否(0)继续统计:";
            cin >> n;
        } while (n);

}```
##查找界面

```cpp
void Find_Student()
{
    int n;
    cout << "请输入查找方式:【1】单个查找;【2】范围查找;【3】模糊查找;";
    cin >> n;
    switch (n) {
    case 1:
        dfindfile(); break;
    case 2:
        Ffindfile(); break;
    
    default:
        break;

    }
}

输出文件
void Out_File() 
{
    ofstream out("student.txt", ios::out);
    if (!out.is_open())
    {
        cout << "打开txt文件失败!n";
    }
    else
    {
        
        for (int i = 0; i < stunum; i++)
        {
            if (STU[i].getid() != 0)
            {
                out <<  STU[i].getname() << "t"  << STU[i].getid()<< "t" << STU[i].getsex() << "t"<< STU[i].getage() << "t"
                    << STU[i].getclasses() << "t" << STU[i].getEnglish() <<"t"<< STU[i].getChinese() << "t" << STU[i].getmath() << endl;
            }
                

        }
        stunum = 0;
       
        out.close();
    }


}

##输出学生信息

void Print_Student() {
    int sum;

    cout << "序号" << "t" << "学号" << "t" << "t" << "t" << "姓名" << "t" << "t" << "数学" << "t" << "t" << "语文" << "t" "t" << "英语" <
        sum = STU[j].getmath() + STU[j].getChinese() + STU[j].getEnglish();
        cout << j + 1 << "t" << STU[j].getid() << "t" << "t" << STU[j].getname()<< "t" "t" << STU[j].getmath()<< "t" << "t" << STU[j].getChinese()<< "t" << "t" << STU[j].getEnglish() << "t" << "t" << sum << endl;
    }

}
修改信息
void Change_Student() {
    int n, k, j;
    int id;
    int score;
    string _name;
    cout << "请输入想要改动的信息对应的学生序号:";
    cin >> j;
    j--;
    cout << j + 1 << "t" << STU[j].getid() << "t" << STU[j].getname() << "t" "t" << STU[j].getmath() << "t" << "t" << STU[j].getEnglish()<< "t" << "t" << STU[j].getChinese()<< endl;
    do
    {
        cout << "请输入改动内容(学号【0】;姓名【1】;数学【2】;英语【3】;语文【4】):";
        cin >> k;
        switch (k)
        {
        case 0:
            cin >>id;
            STU[j].setid(id);
            break;
        case 1:
            cin >> _name;
            STU[j].setname(_name);
            break;
        case 2:
           
        case 3:
            cin >> score;
            STU[j].setEnglish(score);
            break;
        case 4:
            cin >> score;
            STU[j].setEnglish(score);
            break;
        }
        cout << j + 1 << "t" << STU[j].getid() << "t" << STU[j].getname() << "t" "t" << STU[j].getmath() << "t" << "t" << STU[j].getEnglish() << "t" << "t" << STU[j].getChinese() << endl;
        cout << "修改成功,是【1】否【0】继续对该学生信息进行改动:";
        cin >> n;
    } while (n != 0);
   }
排序
void Sort_Student()
{
    int num;
    int N = 1;
    cout << "请选择排序方式:【0】总成绩;【1】数学成绩;【2】英语成绩;【3】语文成绩;" << endl;
    cin >> num;
    student b;
    switch (num)
    {
    case 0:
        cout << "本次不支持总成绩排序,请重新选择;" << endl;
        
        break;
    case 1:
        for (int i = 0; i  i; j--)
                if (STU[i].getmath() < STU[j].getmath())
                    change(STU[i], STU[j]);
        break;
    case 2:
        for (int i = 0; i < stunum; i++)
            for (int j = stunum - 1; j > i; j--)
                if (STU[i].getEnglish() < STU[j].getEnglish())
                    change(STU[i], STU[j]);
        break;
    case 3:
        for (int i = 1; i < stunum; i++)
            for (int j =stunum; j > i; j--)
                if (STU[i].getChinese()  
单个查找功能 
//单个查找学生信息
void dfindfile()
{
    int n = 1;
    string name;
    int ID1;
    int find;
    int j;
    cout << "学生序号【1】,学号【2】或者姓名【3】:";
    cin >> n;
    switch (n)
    {
    case 1:
        cout << "请输入学生序号:";
        cin >> find;
        j = find - 1;
        break;
    case 2:
        cout << "请输入学生学号:";
        cin >> ID1;
        for (int i = 0; i < stunum; i++)
        {
            if (STU[i].getid() == ID1)
            {
                j = i;
                break;
            }
            else if (STU[i].getid() != ID1 && i < stunum - 1)
                continue;
            else
            {
                cout << "无此学号,请重新输入:";
                cin >> ID1;
                i = -1;
            }
        }break;
    case 3:
        cout << "请输入学生姓名:";
        cin >> name;
        for (int i = 0; i 
            if (STU[i].getname() == name)
            {
                j = i;
                break;
            }
            else if (STU[i].getname() != name && i < stunum - 1)
                continue;
            else
            {
                cout << "无此人,请重新输入:";
                cin >> name;
                i = -1;
            }
        }
        break;
    default:
        break;
    }
    cout << "序号" << "t" << "学号" << "t" << "t" << "姓名" << "t" << "t" << "数学" << "t" << "t" << "英语" << "t" "t" << "物理" << "t" "t" << "总分" << endl;
    cout << j + 1 << "t" << STU[j].getid() << "t" << STU[j].getname() << "t" "t" << STU[j].getmath()<< "t" << "t" << STU[j].getEnglish() << "t" << "t" <<
        STU[j].getChinese()<< "t" << "t" << STU[j].getmath()+ STU[j].getEnglish()+ STU[j].getChinese() << endl;
  
}

交换数据
//成绩排序功能
void change(student& a1, student& a2) {
    student b;
    b = a1;
    a1 = a2;
    a2 = b;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/957826.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号