大学生C++课程设计—学生信息管理系统

C++课程设计—学生信息管理系统

虽然老套,但是很经典,于是就把自己写的代码放上面了,以后或许还能看到当初的幼稚

该课程设计含有两个模块:

  • 教师权限模块
  • 学生权限模块

学生权限模块含有:

1 .增加 2 .显示 3.追加 4.查找 学生信息功能

教师权限模块含有:

1.增加 2.显示 3.追加 4.查找 5 .修改 6.删除 学生信息功能

用到的主要知识:

( 1 )类 ( 2 )继承( 3 )结构体( 4 )循环( 5 )数组( 6 )函数

实现各功能模块的主线:

  • 输入密码,进入不同权限的菜单界面
  • 进入菜单界面,做出不同的选择,调用相关函数,进入不同功能模块
  • 进行不同的功能模块,进行操作之后,实现相应功能
  • 退出系统

缺点:

  • 首先必须输入一些学生信息,才能进行各种操作
  • 没有添加文件,将学生信息保存入文件
  • 不能动态实现学生信息的输入,浪费内存空间

代码如下:

<strong>#include<iostream>
#include<cstring>
#include<string>
#include<fstream>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<conio.h>
#include<windows.h>
using namespace std;
class student
{
private:
    long long  num;
    char name[20];
    char sex[6];
    int age;
    char  phone[20];
public:
    static int NUM;
    student() {}
    ~student() {}
    void input();
    friend void readin();
    friend   void show();
    friend   void mood();
    friend  void del();
    friend  void soort();
    friend   void save();
    friend  void findyou();
    friend void clear1();
} zhuo_yue[100];
int student::NUM=0;
void readin()
{
    ifstream in("inf.txt",ios::binary);
    int i=1;
    while(!in.eof())
    {
        in.read((char*) &zhuo_yue[i],sizeof(zhuo_yue[i]));
        i++;
    }
    in.close();
    student::NUM=i-2;
}
void show()
{
    if(student::NUM==0)
        cout<<endl<<endl<<setw(10)<<"暂无学生信息";
    else
    {
        cout<<"学生信息显示"<<endl<<endl;
        cout<<"学号"<<setw(15)<<"姓名"<<setw(15)
            <<"性别"<<setw(15)<<"年龄"<<setw(15)<<"电话"
            <<endl;
        for(int i=1; i<=student::NUM; i++)
        {
            cout<<zhuo_yue[i].num<<setw(15)<<zhuo_yue[i].name<<setw(15)
                <<zhuo_yue[i].sex<<setw(15)<<zhuo_yue[i].age<<setw(15)<<zhuo_yue[i].phone
                <<endl;
        }
    }
    cout<<endl<<setw(40)<<"按任意键退出";
    getch();
}
void mood()
{
    long long L;
    cout<<"请输入欲修改的学号:";
    cin>>L;
    cout<<endl<<setw(40)<<"确认修改(y/n)";
    if(getch()=='y')
    {
        system("cls");
        for(int i=1; i<=student::NUM; i++)
            if(L==zhuo_yue[i].num)
            {
                cout<<"学生信息修改"<<endl<<endl;
                cout<<"学号:";
                cin>>zhuo_yue[i].num;
                cout<<endl<<endl;
                cout<<"姓名:";
                cin>>zhuo_yue[i].name;
                cout<<endl<<endl;
                cout<<"性别:";
                cin>>zhuo_yue[i].sex;
                cout<<endl<<endl;
                cout<<"年龄:";
                cin>>zhuo_yue[i].age;
                cout<<endl<<endl;
                cout<<"电话:";
                cin>>zhuo_yue[i].phone;
                cout<<endl<<endl;
                break;
            }
        cout<<endl<<setw(40)<<"已修改,按任意键退出";
        getch();
    }
    else
        return;
}
void del()
{
    int sum=0;
    cout<<setw(50)<<"[1]按学号删除                 [2]按姓名删除"<<endl;
    if(getch()=='1')
    {
        cout<<"请输入学号:";
        long long it;
        cin>>it;
        cout<<endl<<setw(30)<<"您确定删除此学生吗?(y/n)";
        if(getch()=='y')
        {
            system("cls");
            for(int i=1; i<=student::NUM; i++)
            {
                if(zhuo_yue[i].num==it)
                {
                    for(int j=i+1; j<=student::NUM; j++)
                        zhuo_yue[j-1]=zhuo_yue[j];
                    student::NUM--;
                    sum++;
                    break;
                }
            }
            cout<<"共删除"<<sum<<"人";
        }
        else
            return;
    }
    else  if(getch()=='2')
    {
        char name1[20];
        cout<<"请输入姓名:";
        cin>>name1;
        cout<<endl<<setw(30)<<"您确定删除此学生吗?(y/n)";
        if(getch()=='y')
        {
            system("cls");
            for(int i=1; i<=student::NUM; i++)
            {
                if(strcmp(zhuo_yue[i].name,name1)==0)
                {
                    for(int j=i+1; j<=student::NUM; j++)
                        zhuo_yue[j-1]=zhuo_yue[j];
                    student::NUM--;
                    sum++;
                }
            }
            cout<<"共删除"<<sum<<"人";
        }
        else
            return;
    }
    cout<<endl<<endl<<setw(40)<<"按任意键结束";
    getch();
}
void soort()
{
    cout<<setw(50)<<"[1]按学号排序                 [2]按年龄排序"<<endl;
    if(getch()=='1')
    {
        for(int i=1; i<student::NUM; i++)
            for(int j=1; j<student::NUM-i+1; j++)
            {
                if(zhuo_yue[j].num>zhuo_yue[j+1].num)
                {
                    student it=zhuo_yue[j];
                    zhuo_yue[j]=zhuo_yue[j+1];
                    zhuo_yue[j+1]=it;
                }
            }
        cout<<endl<<setw(50)<<"已排序,按任意键退出";
        getch();
    }
    else  if(getch()=='2')
    {
        for(int i=1; i<student::NUM; i++)
            for(int j=1; j<student::NUM-i+1; j++)
            {
                if(zhuo_yue[j].age>zhuo_yue[j+1].age)
                {
                    student it=zhuo_yue[j];
                    zhuo_yue[j]=zhuo_yue[j+1];
                    zhuo_yue[j+1]=it;
                }
            }
        cout<<endl<<setw(50)<<"已排序,按任意键退出";
        getch();
    }
}
void student::input()
{
LI:
    NUM++;
    cout<<"学生信息输入"<<endl<<endl;
    cout<<"学号:";
    cin>>zhuo_yue[NUM].num;
    cout<<endl<<endl;
    cout<<"姓名:";
    cin>>zhuo_yue[NUM].name;
    cout<<endl<<endl;
    cout<<"性别:";
    cin>>zhuo_yue[NUM].sex;
    cout<<endl<<endl;
    cout<<"年龄:";
    cin>>zhuo_yue[NUM].age;
    cout<<endl<<endl;
    cout<<"电话:";
    cin>>zhuo_yue[NUM].phone;
    cout<<endl<<endl;
    cout<<"已输入,是否继续  (y/n)";
    if(getch()=='y')
    {
        system("cls");
        goto LI;
    }
    else return;
}
void save()
{
    ofstream out("inf.txt",ios::binary);
    cout<<endl<<setw(40)<<"已保存,按任意键退出";
    for(int i=1; i<=student::NUM; i++)
    {
        out.write((char*)&zhuo_yue[i],sizeof(zhuo_yue[i]));
    }
    out.close();
    getch();
}
void findyou()
{
    int sum=0;
    cout<<setw(50)<<"[1]按学号查找                 [2]按姓名查找"<<endl;
    if(getch()=='1')
    {
        cout<<"请输入学号:";
        long long it;
        cin>>it;
        cout<<endl<<setw(30)<<"您确定查看此学生吗?(y/n)";
        if(getch()=='y')
        {
            system("cls");
            cout<<"查看学生信息"<<endl<<endl;
            for(int i=1; i<=student::NUM; i++)
            {
                if(zhuo_yue[i].num==it)
                {
                    cout<<setw(20)<<"学号:"<<zhuo_yue[i].num<<endl
                        <<setw(20)<<"姓名:"<<zhuo_yue[i].name<<endl
                        <<setw(20)<<"性别:"<<zhuo_yue[i].sex<<endl
                        <<setw(20)<<"年龄:"<<zhuo_yue[i].age<<endl
                        <<setw(20)<<"电话:"<<zhuo_yue[i].phone<<endl;
                    cout<<"---------------------------------------"<<endl<<endl;
                    sum++;
                }
            }
            cout<<"共显示"<<sum<<"人";
        }
        else
            return;
    }
    else  if(getch()=='2')
    {
        char name1[20];
        cout<<"请输入姓名:";
        cin>>name1;
        cout<<endl<<setw(30)<<"您确定查看具有此姓名的学生吗?(y/n)";
        if(getch()=='y')
        {
            system("cls");
            cout<<"查看学生信息"<<endl<<endl;
            for(int i=1; i<=student::NUM; i++)
            {
                if(strcmp(zhuo_yue[i].name,name1)==0)
                {
                    cout<<setw(20)<<"学号:"<<zhuo_yue[i].num<<endl
                        <<setw(20)<<"姓名:"<<zhuo_yue[i].name<<endl
                        <<setw(20)<<"性别:"<<zhuo_yue[i].sex<<endl
                        <<setw(20)<<"年龄:"<<zhuo_yue[i].age<<endl
                        <<setw(20)<<"电话:"<<zhuo_yue[i].phone<<endl;
                    cout<<"---------------------------------------"<<endl<<endl;
                    sum++;
                }
            }
            cout<<"共显示"<<sum<<"人";
        }
        else
            return;
    }
    cout<<endl<<endl<<setw(40)<<"按任意键结束";
    getch();
}
char mainmenu()
{
    cout<<"\n\n           欢迎进入学生信息管理系统 "<<endl<<endl;
    cout<<"\n\n          [1]管理员            [2]学生"<<endl<<endl;
    char ff=getch();
    return ff;
}
void adminmainmenu()
{
    cout<<"\n\n           欢迎进入学生信息管理系统(管理者) "<<endl<<endl
        <<endl
        <<endl
        <<"            1: 录入学生信息 "<<endl<<endl
        <<"            2: 显示学生信息 "<<endl<<endl
        <<"            3: 修改学生信息 "<<endl<<endl
        <<"            4: 删除学生信息 "<<endl<<endl
        <<"            5: 查找学生信息 "<<endl<<endl
        <<"            6: 保存学生信息 "<<endl<<endl
        <<"            7: 排序学生信息"<<endl<<endl
        <<"            8: 返回初始页面"<<endl<<endl
        <<"            0: 退出系统"<<endl;
}
void mainmenu1()
{
    cout<<"\n\n           欢迎进入学生信息管理系统(学生) "<<endl<<endl
        <<endl
        <<endl
        <<"            1: 显示学生信息 "<<endl<<endl
        <<"            2: 查找学生信息 "<<endl<<endl
        <<"            3: 排序学生信息"<<endl<<endl
        <<"            4: 返回初始页面"<<endl<<endl
        <<"            0: 退出系统"<<endl;
}
void clear1()
{
    fstream cl;
    cl.open("inf.txt",ios::out);
    cl.close();
    cout<<"销毁成功";
    exit(1);
}
int main()
{
LIIIII:
    readin();
    system("cls");
    char get =  mainmenu();
    if(get=='1')
    {
        char adminname[20],mima[20];
        ifstream in;
        ofstream out;
        in.open("admin.txt",ios::in);
        if(!in)
        {
            cout<<"无管理员账号,请先设定:"<<endl<<endl;
FF:
            cout<<"输入账号名:";
            cin>>adminname;
            cout<<"输入密码:";
            cin>>mima;
            cout<<"确定创建(y/n)";
            char fff=getch();
            if(fff=='y')
            {
                out.open("admin.txt",ios::app);
                out<<adminname<<' '<<mima<<' ';
                system("cls");
                cout<<"                          已创建,按任意键返回";
                getch();
                out.close();
                goto LIIIII;
            }
            else if(fff=='n')
                goto LIIIII;
        }
        else
        {
            system("cls");
            cout<<"                 已存在用户"<<endl<<endl;
            cout<<"是否新建管理员账户(y/n)";
            char gr=getch();
            if(gr=='y')
            {
                system("cls");
                goto FF;
            }
ss1:
            system("cls");
            cout<<"登录账号:";
            cin>>adminname;
            cout<<"输入密码:";
            cin>>mima;
            char adminname1[20],mima1[20];
            int flog=0;
            while(!in.eof())
            {
                in>>adminname1>>mima1;
                if(!strcmp(adminname,adminname1)&&!strcmp(mima1,mima))
                {
                    flog=0;
                    break;
                }
            }
            if(flog==0)
            {
                system("cls");
                cout<<"            登陆成功         按任意键继续";
                getch();
            }
            else
            {
                cout<<"密码错误"<<endl<<endl;
                cout<<"[1]返回初始界面      [2]重新输入密码";
                char gg=getch();
                if(gg=='1')
                    goto LIIIII;
                else
                {
                    system("cls");
                    goto ss1;
                }
            }
        }
        while(1)
        {
            adminmainmenu();
            char ch;
            ch=getchar();
            system("CLS");
            switch(ch)
            {
            case '1':
                zhuo_yue[student::NUM].input();
                break;
            case '2':
                show();
                break;
            case '3':
                mood();
                break;
            case '4':
                del();
                break;
            case '5':
                findyou();
                break;
            case '6':
                save();
                break;
            case '7':
                soort();
                break;
            case '8':
                goto LIIIII;
            case 'F':
                clear1();
            case '0':
                cout<<"\n\n\n\n                      谢谢使用~~";
                exit(1);
            }
        }
    }
    else if(get=='2')
    {
        char stuname[20],stumima[20];
        ifstream in;
        ofstream out;
        in.open("student.txt",ios::in);
        if(!in)
        {
            cout<<"无学生账号,请先设定:"<<endl<<endl;
LL:
            cout<<"输入账号名:";
            cin>>stuname;
            cout<<"输入密码:";
            cin>>stumima;
            cout<<"确定创建(y/n)";
            char fff=getch();
            if(fff=='y')
            {
                out.open("student.txt",ios::app);
                out<<stuname<<' '<<stumima<<' ';
                system("cls");
                cout<<"                          已创建,按任意键返回";
                getch();
                out.close();
                goto LIIIII;
            }
            else if(fff=='n')
                goto LIIIII;
        }
        else
        {
            system("cls");
            cout<<"                 已存在用户"<<endl<<endl;
            cout<<"是否新建账户(y/n)";
            char gr=getch();
            if(gr=='y')
            {
                system("cls");
                goto LL;
            }
sss:
            system("cls");
            cout<<"登录账号:";
            cin>>stuname;
            cout<<"输入密码:";
            cin>>stumima;
            char stuname1[20],stumima1[20];
            int flog=1;
            while(!in.eof())
            {
                in>>stuname1>>stumima1;
                if(!strcmp(stuname,stuname1)&&!strcmp(stumima1,stumima))
                {
                    flog=0;
                    break;
                }
            }
            if(flog==0)
            {
                system("cls");
                cout<<"            登陆成功         按任意键继续";
                getch();
            }
            else if(flog==1)
            {
                system("cls");
                cout<<"密码错误"<<endl<<endl;
                cout<<"[1]返回初始界面      [2]重新输入密码";
                char gg=getch();
                if(gg=='1')
                    goto LIIIII;
                else
                {
                    system("cls");
                    goto  sss;
                }
            }
            in.close();
        }
        while(1)
        {
            mainmenu1();
            char ch;
            ch=getchar();
            system("CLS");
            switch(ch)
            {
            case '1':
                show();
                break;
            case '2':
                findyou();
                break;
            case '3':
                soort();
                break;
            case 'F':
                clear1();
            case '4':
                goto LIIIII;
            case '0':
                cout<<"\n\n\n\n                      谢谢使用~~";
                exit(1);
            }
        }
    }
}
</strong>

这里给大家分享一份Python全套学习资料,包括学习路线、软件、源码、视频、面试题等等,都是我自己学习时整理的,希望可以对正在学习或者想要学习Python的朋友有帮助!

CSDN大礼包:全网最全《全套Python学习资料》免费分享🎁

😝有需要的小伙伴,可以点击下方链接免费领取或者V扫描下方二维码免费领取🆓

👉CSDN大礼包🎁:全网最全《Python学习资料》免费分享(安全链接,放心点击)👈

1️⃣零基础入门

① 学习路线

对于从来没有接触过Python的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
在这里插入图片描述

② 路线对应学习视频

还有很多适合0基础入门的学习视频,有了这些视频,轻轻松松上手Python~在这里插入图片描述

③练习题

每节视频课后,都有对应的练习题哦,可以检验学习成果哈哈!
在这里插入图片描述
因篇幅有限,仅展示部分资料

2️⃣国内外Python书籍、文档

① 文档和书籍资料

在这里插入图片描述

3️⃣Python工具包+项目源码合集

①Python工具包

学习Python常用的开发软件都在这里了!每个都有详细的安装教程,保证你可以安装成功哦!
在这里插入图片描述

②Python实战案例

光学理论是没用的,要学会跟着一起敲代码,动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。100+实战案例源码等你来拿!
在这里插入图片描述

③Python小游戏源码

如果觉得上面的实战案例有点枯燥,可以试试自己用Python编写小游戏,让你的学习过程中增添一点趣味!
在这里插入图片描述

4️⃣Python面试题

我们学会了Python之后,有了技能就可以出去找工作啦!下面这些面试题是都来自阿里、腾讯、字节等一线互联网大厂,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。
在这里插入图片描述
在这里插入图片描述

5️⃣Python兼职渠道

而且学会Python以后,还可以在各大兼职平台接单赚钱,各种兼职渠道+兼职注意事项+如何和客户沟通,我都整理成文档了。
在这里插入图片描述
在这里插入图片描述
上述所有资料 ⚡️ ,朋友们如果有需要 📦《全套Python学习资料》的,可以扫描下方二维码免费领取 🆓
😝有需要的小伙伴,可以点击下方链接免费领取或者V扫描下方二维码免费领取🆓

👉CSDN大礼包🎁:全网最全《Python学习资料》免费分享(安全链接,放心点击)👈

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值