学生信息管理系统

学生信息管理系统

#include<iostream>
#include<algorithm>
#include<windows.h>
#include<fstream>
#include<string>
using namespace std;

class student
{
private:
    string stu_ID;
    string stu_Name;
    float stu_Score;
public:
    void Set_ID(string ID);
    void Set_Name(string Name);
    void Set_Score(float Score);
    string Show_ID();
    string Show_Name();
    float Show_Score();
};

void student::Set_ID(string ID)
{
    stu_ID = ID;
}
void student::Set_Name(string Name)
{
    stu_Name = Name;
}
void student::Set_Score(float Score)
{
    stu_Score = Score;
}
string student::Show_ID()
{
    return stu_ID;
}
string student::Show_Name()
{
    return stu_Name;
}
float student::Show_Score()
{
    return stu_Score;
}


int Init(student info[],int n)
{
    string ID;
    string Name;
    float Score;
    
    ifstream in("C:\\Users\\Lenovo\\Desktop\\student.txt");
    while (! in.eof())
    {
       in >> ID >> Name >> Score;
       info[n].Set_ID(ID);
       info[n].Set_Name(Name);
       info[n].Set_Score(Score);
       n++;
    }
    
    in.close();
    return n;
}


int Insert_Student(student info[],int n)
{
    string ID;
    string Name;
    float Score;
    
    cout << "请输入要添加学生的ID,Name,Score:" << endl;
    
    loop:
    cin >> ID >> Name >> Score ;
    for (int i=0;i<n;i++)
    {
        if (info[i].Show_ID() == ID)
        {
            cout << "改学号已被注册,请你重新出入:" << endl;
            goto loop;
        }
    }

    info[n].Set_ID(ID);
    info[n].Set_Name(Name);
    info[n].Set_Score(Score);
    
    cout << "添加成功!" << endl;
    n++;
    return n;
}


void Show_info(student info[],int n)
{
    string ID;
    cout << "请输入你要查询的学号:" << endl;
    
    loop:
    cin >> ID;
    for (int i=0;i<n;i++)
    {
        if (ID == info[i].Show_ID())
        {
            cout << info[i].Show_ID() << "\t" ;
            cout << info[i].Show_Name() << "\t" ;
            cout << info[i].Show_Score() << endl;
            return ;
        }
    }
    
    cout << "对不起,你输入的学号并不存在。请你重新输入学号:" << endl;
    goto loop;
}


int  Delet_Student(student info[],int n)
{
    cout << "下面是去全部学生的信息情况:" << endl;
    for (int i=0;i<n;i++)
    {
        cout << info[i].Show_ID() << "\t" ;
        cout << info[i].Show_Name() << "\t" ;
        cout << info[i].Show_Score() << endl;
    }
    
    cout << "请输入你要删除的学号:" << endl;
    string delID;
    loop:
    cin >> delID ;
    for (int i=0;i<n;i++)
    {
        if (delID == info[i].Show_ID())
        {
            cout << "删除成功!" << endl;
            for (int j=i;j<n-1;j++)
                info[j] = info[j+1];
            n--;
            return n;
        }
    }

    cout << "对不起,你要删除的学号并不存在。请你重新输入要删除的学号:" << endl;
    goto loop;
}


void Save_info(student info[],int n)
{
    ofstream out ("C:\\Users\\Lenovo\\Desktop\\student.txt");
    
    for (int i=0;i<n;i++)
    {
        out << info[i].Show_ID() << '\t';
        out << info[i].Show_Name() << '\t';
        out << info[i].Show_Score() << endl;
    }
    
    cout << "保存成功!" << endl;
    out.close();
}


void Main_Menu()
{
    system("cls");
    cout << endl;
    cout << "1.添加学生信息:" << endl << endl;
    cout << "2.查询学生信息:" << endl << endl;
    cout << "3.删除学生信息:" << endl << endl;
    cout << "4.保存修改:" << endl << endl;
    cout << "5.操作结束,退出系统" << endl << endl;
    cout << endl;
    cout << "请输入指令:";
}


int main()
{
    int n = 0;
    student info[100];
    n = Init(info,n);
    int order;
    while (true)
    {
        Main_Menu();
        
        cin >> order;
        
        if ( order == 1)
            n = Insert_Student(info,n);
            
        if ( order == 2)
            Show_info(info,n);
            
        if ( order == 3)
            n = Delet_Student(info,n);
            
        if ( order == 4)
            Save_info(info,n);
            
        if ( order == 5)
            break;
            
        system("pause");
    }
    return 0;
}
  • 7
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值