【无标题】C++实现简单的学生信息的增删改查功能

C++实现简单的学生信息的增删改查功能

C++实现增删改查

简单实现一个学生系统的增删改查功能,仅供参考
以下是代码实现:


#include<iostream>
#include<vector>
using namespace std;

class Student{
public:
    string name;
    int age;
    int scores;
    Student(string n,int a,int s)
    {
        this->name = n;
        this->age = a;
        this->scores = s;
    }
};

void addstudent(vector<Student> &students)
{
    string name;
    int age,scores;
    cout<<"请输入姓名:"<<endl;
    cin>>name;
    cout<<"请输入年龄:"<<endl;
    cin>>age;
    cout<<"请输入成绩:"<<endl;
    cin>>scores;
    students.push_back(Student(name,age,scores));
}



void showInformation(vector<Student> &students)
{
    for(int i = 0;i<students.size();i++)
    {
        cout<<"姓名:"<<students[i].name<<" 年龄:"<<students[i].age<<" 成绩:"<<students[i].scores<<endl;

    }
}

void deleInfo(vector<Student>&students)
{
    string name;
    cout<<"请输入要删除学生的姓名"<<endl;
    cin>>name;

    for(auto it= students.begin();it!=students.end();++it)
    {
        if(it->name == name)
        {
            students.erase(it);
            cout<<"删除成功"<<endl;
            return ;
        }
    }
    cout<<"未找到学生"<<endl;
}

void changeInfomation(vector<Student> &students)
{
    string name;
    int scores;
    cout<<"请输入要修改人的姓名"<<endl;
    cin>>name;
    for(auto &stu:students)
    {
        if(stu.name == name)
        {
            cout<<"请输入要修改的成绩"<<endl;
            cin>>scores;
            stu.scores = scores;
            cout<<"修改成功"<<endl;
            return;
        }
        cout<<"未找到学生"<<endl;
    }
    

}


int main()
{
    vector<Student> student;
    
    student.push_back(Student("aaaa",1,1));

    while(true)
    {
        cout<<"**********"<<endl;
        cout<<"1.增加学生"<<endl;
        cout<<"2.显示信息"<<endl;
        cout<<"3.删除学生信息"<<endl; 
        cout<<"4.修改学生信息"<<endl;  
        cout<<"**********"<<endl;
        cout<<" "<<endl;

        int choise;
        cin>>choise;
        switch(choise)
        {
            case 1:
                addstudent(student);
                break;
            case 2:
                showInformation(student);
                break;
            case 3:
                deleInfo(student);
                break;
            case 4:
                changeInfomation(student);
                break;

        }
    }
    system("pause");
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值