学生管理系统的CRUD

news/2024/10/5 5:24:27

include

using namespace std;

typedef struct Studnet { //初始化结构体变量

int ID;
double math_scores;
double english_scores;
double computer_scores;
double total_scores;

}Student;

void Input_student_score(int size, Student* stu); //输入所有学生信息

void Output_student_score(Student s); //输出所有学生信息

void select_student(int ID, Student* stu, int size); //通过ID查找,输出学生信息

void update_student_score(int ID, int size, double math_scores, double english_scores,
double computer_scores, Student* stu); //通过ID查找,更新学生信息

void delete_student_score(int ID, int size, Student* stu); //通过ID查找,删除学生信息

int main()
{
int size;
cout << "Please input the number of students:" << endl;
cin >> size;

Student stu[10];	//定义一个足够数量的结构体数组Input_student_score(size, stu);	//开始输入学生信息while (true) {cout << "----------------------------------------------------------------" << endl;cout << "输入: 1.查找学生信息 2.更新学生信息 3.删除学生信息	4.输出所有学生信息 5.退出系统" << endl;cout << "-" << endl;int choice;cin >> choice;switch (choice) {case 1:int ID;cout << "请输入要查找的学生ID:" << endl;cin >> ID;select_student(ID, stu, size);break;case 2:cout << "请输入要更新的学生ID:" << endl;cin >> ID;double math_scores, english_scores, computer_scores;cout << "请输入新的数学成绩:" << endl;cin >> math_scores;cout << "请输入新的英语成绩:" << endl;cin >> english_scores;cout << "请输入新的计算机成绩:" << endl;cin >> computer_scores;update_student_score(ID, size, math_scores, english_scores, computer_scores, stu);break;case 3:cout << "请输入要删除的学生ID:" << endl;cin >> ID;delete_student_score(ID, size, stu);break;case 4:for (int i = 0; i < size; i++) {if (stu[i].ID!= 0) {Output_student_score(stu[i]);}}break;case 5:return 0;default:cout << "输入错误(或不符合规则),请重新输入!" << endl;break;}
}return 0;

}

void Input_student_score(int size, Student* stu)
{
for (int i = 0; i < size; i++) {
cout << "Please input the ID of student " << i + 1 << ":" << endl;
cin >> stu[i].ID;
cout << "Please input the math scores of student " << i + 1 << ":" << endl;
cin >> stu[i].math_scores;
cout << "Please input the english scores of student " << i + 1 << ":" << endl;
cin >> stu[i].english_scores;
cout << "Please input the computer scores of student " << i + 1 << ":" << endl;
cin >> stu[i].computer_scores;
cout << endl << endl;
stu[i].total_scores = stu[i].math_scores + stu[i].english_scores + stu[i].computer_scores;
}
}

void Output_student_score(Student s)
{
cout << "ID:" << s.ID << endl;
cout << "Math Scores:" << s.math_scores << endl;
cout << "English Scores:" << s.english_scores << endl;
cout << "Computer Scores:" << s.computer_scores << endl;
cout << "Total Scores:" << s.total_scores << endl;
}

void select_student(int ID, Student* stu, int size)
{
for (int i = 0; i < size; i++) {
if (stu[i].ID == ID) {
Output_student_score(stu[i]);
return;
}
}
}

void update_student_score(int ID, int size, double math_scores, double english_scores,
double computer_scores, Student* stu)
{
for (int i = 0; i < size; i++) {
if (stu[i].ID == ID) {
stu[i].math_scores = math_scores;
stu[i].english_scores = english_scores;
stu[i].computer_scores = computer_scores;
stu[i].total_scores = math_scores + english_scores + computer_scores;
return;
}
}
}

void delete_student_score(int ID, int size, Student* stu)
{
for (int i = 0; i < size; i++) {
if (stu[i].ID == ID) {
stu[i].ID = 0;
stu[i].math_scores = 0;
stu[i].english_scores = 0;
stu[i].computer_scores = 0;
stu[i].total_scores = 0;
return; //删除后,将该位置的ID置为0,其他信息不变
}
}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hjln.cn/news/44209.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

C语言中关于Base64编码的基础原理

Base64编码简述: 1.Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打印字符来表示二进制数据的方法。 2.Base64,就是包括小写字母a-z、大写字母A-Z、数字0-9、符号"+"、"/"一共64个字符的字符集,(任何符号都可以转…

09-盒子模型

盒子模型01 认识盒子模型02 盒子模型的四边03 盒子边框04 盒子内边距-padding 通常用于设置边框和内容之间的间距 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible&quo…

试了下ocr

pdf能看了,拓展的驱动下,想着是否可以ORC呢,识别到文字内容更有帮助。 按网搜的顺序,开始是用pytesseract,pip安装顺利,但运行不了,提示找不到pytesseract,按网上的帮助下载win安装包,选上中文包,再试,可以运行了,就是中文基本识别不了,也不知哪里改善,只得作罢。…

fastjson1

@目录前言分析复制文件清空文件出现问题和分析问题解决分析问题再次出现问题再次分析最终结果读取文件分析poc拓宽场景极限环境poc优化修改再次优化poc的分析写入文件SafeFileOutputStream写文件java8无依赖读文件在commons-io库下的写入文件原因利用链分析组合poc出现问题和分…

解决运行loadRunner报错无法进行代理的错误

选择第二个,不设置代理,可以实现回放不会报错,但是今日运行遇到错误,无法实现全部的录制脚本回访完毕,卡住打开网址处的脚本。直接运行完毕,不会报错。

LiteDb

目录封装的代码相关参考本文记录LiteDb的使用,建议初学者使用时先根据官方的文档进行学习。LiteDb官网LiteDb DocLiteDb Package LiteDb API 封装的代码LiteDbWrapper.cs/// <summary>/// 官网:http://www.litedb.org//// GitHub:https://github.com/mbdavid?tab=repo…

winform窗体关闭之前弹出确认框

需要使用到窗体的 FormClosing 事件 private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) {DialogResult dialogResult = MessageBox.Show("是否确认关闭窗口", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if (…

Oh My Posh 安装与使用

Oh My Posh 安装与使用 目录Oh My Posh 安装与使用IntroductionInstallationThemes配置使用主题安装字体建议FAQ本文介绍 Windows Terminal. 集成 Oh My Posh . Introduction Oh My Posh 介绍。 Introduction | Oh My PoshInstallation Windows Terminal 安装 Oh My Posh. Wind…