模拟毕业生选择指导老师提供的毕业课题老师可增加,删除,修改课题,学生可选择课题,老师和学生都可以查看当前已经选择的结果 以#include<iostream> #include<string>为头文件
时间: 2024-03-29 12:41:10 浏览: 82
#include <iostream>
好的,这是一个比较复杂的问题,需要设计一些类与函数来实现。以下是一个简单的实现示例:
```c++
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
class Teacher {
private:
string name;
vector<string> topics; // 老师开设的课题列表
public:
Teacher(string name) {
this->name = name;
}
void addTopic(string topic) {
topics.push_back(topic);
}
void removeTopic(string topic) {
for (auto it = topics.begin(); it != topics.end(); ++it) {
if (*it == topic) {
topics.erase(it);
break;
}
}
}
void modifyTopic(string oldTopic, string newTopic) {
for (auto it = topics.begin(); it != topics.end(); ++it) {
if (*it == oldTopic) {
*it = newTopic;
break;
}
}
}
string getName() {
return name;
}
vector<string> getTopics() {
return topics;
}
};
class Student {
private:
string name;
string selectedTopic;
public:
Student(string name) {
this->name = name;
}
void selectTopic(string topic) {
selectedTopic = topic;
}
string getSelectedTopic() {
return selectedTopic;
}
};
class GraduationProject {
private:
vector<Teacher*> teachers;
map<string, Student*> students;
public:
void addTeacher(Teacher* teacher) {
teachers.push_back(teacher);
}
void removeTeacher(Teacher* teacher) {
for (auto it = teachers.begin(); it != teachers.end(); ++it) {
if (*it == teacher) {
teachers.erase(it);
break;
}
}
}
void modifyTopic(Teacher* teacher, string oldTopic, string newTopic) {
teacher->modifyTopic(oldTopic, newTopic);
}
void displayAllTopics() {
for (auto teacher : teachers) {
cout << "Teacher " << teacher->getName() << " topics:" << endl;
for (auto topic : teacher->getTopics()) {
cout << " " << topic << endl;
}
}
}
void selectTopic(Student* student, string topic) {
if (students.find(student->getName()) == students.end()) {
students[student->getName()] = student;
}
students[student->getName()]->selectTopic(topic);
}
void displayAllSelections() {
cout << "Student selections:" << endl;
for (auto it = students.begin(); it != students.end(); ++it) {
cout << " " << it->first << ": " << it->second->getSelectedTopic() << endl;
}
}
};
int main() {
GraduationProject project;
Teacher *t1 = new Teacher("Tom");
t1->addTopic("Topic 1");
t1->addTopic("Topic 2");
Teacher *t2 = new Teacher("Jerry");
t2->addTopic("Topic 3");
t2->addTopic("Topic 4");
project.addTeacher(t1);
project.addTeacher(t2);
Student *s1 = new Student("Alice");
project.selectTopic(s1, "Topic 2");
Student *s2 = new Student("Bob");
project.selectTopic(s2, "Topic 3");
project.displayAllTopics();
project.displayAllSelections();
return 0;
}
```
这个程序实现了老师添加、删除、修改课题,学生选择课题,以及展示所有老师的课题和所有学生的选择。你可以根据需要进行修改和扩展。
阅读全文