用c++写一个教务系统的专业学院的查询
时间: 2023-12-04 12:02:51 浏览: 44
好的,教务系统一般包括学生信息管理、教师信息管理、课程信息管理、成绩管理等模块。针对专业学院的查询,可以考虑以下几个方面:
1. 学生信息查询:可以根据学号、姓名等关键字进行查询,查询结果包括学生基本信息、选课情况、成绩等。
2. 教师信息查询:可以根据工号、姓名等关键字进行查询,查询结果包括教师基本信息、所授课程信息等。
3. 课程信息查询:可以根据课程编号、课程名称等关键字进行查询,查询结果包括课程基本信息、上课时间地点、授课教师信息等。
4. 成绩查询:可以根据学号、课程编号等关键字进行查询,查询结果包括学生姓名、课程名称、成绩等信息。
下面是一个简单的C++代码示例,实现了学生信息查询的功能:
```c++
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
// 定义学生结构体
struct Student {
string id; // 学号
string name; // 姓名
string major; // 专业
string course; // 课程
float score; // 成绩
};
// 读取学生信息文件
void readStudentFile(Student students[], int& count) {
ifstream infile("students.txt");
if (!infile) {
cout << "打开文件失败!" << endl;
return;
}
string line;
count = 0;
while (getline(infile, line)) {
if (line.empty()) {
continue;
}
int pos = line.find(",");
students[count].id = line.substr(0, pos);
line = line.substr(pos + 1);
pos = line.find(",");
students[count].name = line.substr(0, pos);
line = line.substr(pos + 1);
pos = line.find(",");
students[count].major = line.substr(0, pos);
line = line.substr(pos + 1);
pos = line.find(",");
students[count].course = line.substr(0, pos);
line = line.substr(pos + 1);
students[count].score = stof(line);
count++;
}
infile.close();
}
// 学生信息查询
void queryStudentInfo(Student students[], int count) {
string keyword;
cout << "请输入查询关键字:";
cin >> keyword;
cout << "查询结果如下:" << endl;
cout << "学号\t姓名\t专业\t课程\t成绩" << endl;
for (int i = 0; i < count; i++) {
if (students[i].id.find(keyword) != string::npos ||
students[i].name.find(keyword) != string::npos ||
students[i].major.find(keyword) != string::npos ||
students[i].course.find(keyword) != string::npos) {
cout << students[i].id << "\t" << students[i].name << "\t"
<< students[i].major << "\t" << students[i].course << "\t" << students[i].score << endl;
}
}
}
int main() {
Student students[100];
int count;
readStudentFile(students, count);
queryStudentInfo(students, count);
return 0;
}
```
在此示例中,我们定义了一个学生结构体,存储了学生的基本信息。readStudentFile函数用于读取存储学生信息的文件,queryStudentInfo函数用于根据关键字查询学生信息。这里我们只实现了学生信息查询的功能,其他功能可以仿照此代码进行实现。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)