用c++语言设计一个基于面向对象程序设计的学生管理信息系统要求学生成绩管理系统有若干学生成绩记录组成,每个记录由学号、姓名、性别和成绩四部分组成,学号不超过11个字符,姓名不超过20个字符,性别为’m’(male)或’f’(female),成绩为double型数据。该系统具有以下功能: ⑴程序开始执行时显示系统首界面及版权信息后,显示以下主菜单:1.添加学生成绩记录2.显示学生成绩记录 3.查找学生成绩记录 4.删除学生成绩记录 5.保存学生成绩记录6.导出学生成绩记录 0.退出学生成绩管理系统
时间: 2024-03-06 15:47:52 浏览: 58
好的,这是一个比较复杂的程序,需要进行面向对象的设计。我可以给你提供一个基本的框架,你可以根据需要进行修改和完善。
首先,我们需要设计一个学生成绩记录类,包括学号、姓名、性别和成绩四个属性,以及相应的get和set方法。
```c++
class StudentRecord {
public:
StudentRecord(string id, string name, char gender, double score);
string getId();
string getName();
char getGender();
double getScore();
void setId(string id);
void setName(string name);
void setGender(char gender);
void setScore(double score);
private:
string id;
string name;
char gender;
double score;
};
```
然后,我们需要设计一个学生管理信息系统类,包括添加学生记录、显示学生记录、查找学生记录、删除学生记录、保存学生记录和导出学生记录等功能,以及相应的菜单和界面。
```c++
class StudentManagementSystem {
public:
void start();
private:
vector<StudentRecord> records;
void showMenu();
void addRecord();
void showRecords();
void searchRecord();
void deleteRecord();
void saveRecords();
void exportRecords();
};
```
在学生管理信息系统类中,我们需要使用一个vector来存储所有的学生记录,然后实现相应的功能。下面是相应的实现代码。
```c++
StudentRecord::StudentRecord(string id, string name, char gender, double score) {
this->id = id;
this->name = name;
this->gender = gender;
this->score = score;
}
string StudentRecord::getId() {
return id;
}
string StudentRecord::getName() {
return name;
}
char StudentRecord::getGender() {
return gender;
}
double StudentRecord::getScore() {
return score;
}
void StudentRecord::setId(string id) {
this->id = id;
}
void StudentRecord::setName(string name) {
this->name = name;
}
void StudentRecord::setGender(char gender) {
this->gender = gender;
}
void StudentRecord::setScore(double score) {
this->score = score;
}
void StudentManagementSystem::start() {
cout << "欢迎使用学生成绩管理系统!" << endl;
cout << "版权所有(C) 2021,xxx公司。" << endl;
while (true) {
showMenu();
int choice;
cin >> choice;
switch (choice) {
case 1:
addRecord();
break;
case 2:
showRecords();
break;
case 3:
searchRecord();
break;
case 4:
deleteRecord();
break;
case 5:
saveRecords();
break;
case 6:
exportRecords();
break;
case 0:
cout << "谢谢使用学生成绩管理系统!" << endl;
return;
default:
cout << "请输入正确的选项!" << endl;
break;
}
}
}
void StudentManagementSystem::showMenu() {
cout << "学生成绩管理系统菜单" << endl;
cout << "1.添加学生成绩记录" << endl;
cout << "2.显示学生成绩记录" << endl;
cout << "3.查找学生成绩记录" << endl;
cout << "4.删除学生成绩记录" << endl;
cout << "5.保存学生成绩记录" << endl;
cout << "6.导出学生成绩记录" << endl;
cout << "0.退出学生成绩管理系统" << endl;
cout << "请选择(0-6):" << endl;
}
void StudentManagementSystem::addRecord() {
string id, name;
char gender;
double score;
cout << "请输入学号:" << endl;
cin >> id;
cout << "请输入姓名:" << endl;
cin >> name;
cout << "请输入性别(m/f):" << endl;
cin >> gender;
cout << "请输入成绩:" << endl;
cin >> score;
StudentRecord record(id, name, gender, score);
records.push_back(record);
cout << "添加成功!" << endl;
}
void StudentManagementSystem::showRecords() {
if (records.size() == 0) {
cout << "没有学生记录!" << endl;
return;
}
cout << "学号\t姓名\t性别\t成绩" << endl;
for (int i = 0; i < records.size(); i++) {
cout << records[i].getId() << "\t" << records[i].getName() << "\t" << records[i].getGender() << "\t" << records[i].getScore() << endl;
}
}
void StudentManagementSystem::searchRecord() {
string id;
cout << "请输入要查找的学号:" << endl;
cin >> id;
for (int i = 0; i < records.size(); i++) {
if (records[i].getId() == id) {
cout << "学号\t姓名\t性别\t成绩" << endl;
cout << records[i].getId() << "\t" << records[i].getName() << "\t" << records[i].getGender() << "\t" << records[i].getScore() << endl;
return;
}
}
cout << "没有找到该学生记录!" << endl;
}
void StudentManagementSystem::deleteRecord() {
string id;
cout << "请输入要删除的学号:" << endl;
cin >> id;
for (int i = 0; i < records.size(); i++) {
if (records[i].getId() == id) {
records.erase(records.begin() + i);
cout << "删除成功!" << endl;
return;
}
}
cout << "没有找到该学生记录!" << endl;
}
void StudentManagementSystem::saveRecords() {
ofstream fout("records.txt");
if (!fout) {
cout << "文件打开失败!" << endl;
return;
}
for (int i = 0; i < records.size(); i++) {
fout << records[i].getId() << " " << records[i].getName() << " " << records[i].getGender() << " " << records[i].getScore() << endl;
}
fout.close();
cout << "保存成功!" << endl;
}
void StudentManagementSystem::exportRecords() {
ofstream fout("records.csv");
if (!fout) {
cout << "文件打开失败!" << endl;
return;
}
fout << "学号,姓名,性别,成绩" << endl;
for (int i = 0; i < records.size(); i++) {
fout << records[i].getId() << "," << records[i].getName() << "," << records[i].getGender() << "," << records[i].getScore() << endl;
}
fout.close();
cout << "导出成功!" << endl;
}
```
在主函数中,我们只需要创建一个学生管理信息系统对象,并调用其start方法即可。
```c++
int main() {
StudentManagementSystem sms;
sms.start();
return 0;
}
```
这样,一个基于面向对象的学生管理信息系统就完成了。你可以根据需要进行修改和完善。
阅读全文