用C++写一个学生考勤管理系统课程设计
时间: 2023-08-14 13:04:31 浏览: 285
C++学生考勤系统课程设计
5星 · 资源好评率100%
好的,下面是一个简单的学生考勤管理系统的设计和实现,使用C++编写:
```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<conio.h>
#define MAX 1000
using namespace std;
struct Student {
char name[20];
int id;
int attendence_num;
int late_num;
int leave_num;
int truant_num;
};
Student stu[MAX];
int num = 0;
void add_student() {
cout << "请输入学生姓名:";
cin >> stu[num].name;
cout << "请输入学生学号:";
cin >> stu[num].id;
stu[num].attendence_num = 0;
stu[num].late_num = 0;
stu[num].leave_num = 0;
stu[num].truant_num = 0;
num++;
cout << "添加成功!" << endl;
}
void show_student() {
if (num == 0) {
cout << "无学生信息!" << endl;
return;
}
cout << "学号\t姓名\t出勤次数\t迟到次数\t请假次数\t旷课次数" << endl;
for (int i = 0; i < num; i++) {
cout << stu[i].id << "\t" << stu[i].name << "\t" << stu[i].attendence_num << "\t\t"
<< stu[i].late_num << "\t\t" << stu[i].leave_num << "\t\t" << stu[i].truant_num << endl;
}
}
void modify_attendence() {
if (num == 0) {
cout << "无学生信息!" << endl;
return;
}
int id;
cout << "请输入学生学号:";
cin >> id;
for (int i = 0; i < num; i++) {
if (stu[i].id == id) {
cout << "请选择操作:1.出勤 2.迟到 3.请假 4.旷课" << endl;
int option;
cin >> option;
switch (option) {
case 1:
stu[i].attendence_num++;
break;
case 2:
stu[i].late_num++;
break;
case 3:
stu[i].leave_num++;
break;
case 4:
stu[i].truant_num++;
break;
default:
cout << "无效操作!" << endl;
break;
}
cout << "修改成功!" << endl;
return;
}
}
cout << "查无此人!" << endl;
}
void search_student() {
if (num == 0) {
cout << "无学生信息!" << endl;
return;
}
int id;
cout << "请输入学生学号:";
cin >> id;
for (int i = 0; i < num; i++) {
if (stu[i].id == id) {
cout << "学号\t姓名\t出勤次数\t迟到次数\t请假次数\t旷课次数" << endl;
cout << stu[i].id << "\t" << stu[i].name << "\t" << stu[i].attendence_num << "\t\t"
<< stu[i].late_num << "\t\t" << stu[i].leave_num << "\t\t" << stu[i].truant_num << endl;
return;
}
}
cout << "查无此人!" << endl;
}
int main() {
int option;
while (1) {
cout << "请选择操作:1.添加学生信息 2.显示学生信息 3.修改考勤信息 4.查询学生信息 5.退出程序" << endl;
cin >> option;
switch (option) {
case 1:
add_student();
break;
case 2:
show_student();
break;
case 3:
modify_attendence();
break;
case 4:
search_student();
break;
case 5:
cout << "程序已退出!" << endl;
return 0;
default:
cout << "无效操作!" << endl;
break;
}
cout << "按任意键继续..." << endl;
getch();
system("cls");
}
return 0;
}
```
本系统实现了以下功能:
1. 添加学生信息
2. 显示学生信息
3. 修改学生考勤信息
4. 查询学生信息
可以根据需要进行扩展和改进。
阅读全文