注释下列每行代码#include<string> #include<iostream> #include<vector> using namespace std; class Student { public: string sno; string name; string major; int grade; Student(string _sno, string _name, string _major, int _grade) { sno = _sno; name = _name; major = _major; grade = _grade; } }; class Course { public: string cid; string name; int credit; int capacity; string teacher; int start_grade; string location; Course(string _cid, string _name, int _credit, int _capacity, string _teacher, int _start_grade, string _location) { cid = _cid; name = _name; credit = _credit; capacity = _capacity; teacher = _teacher; start_grade = _start_grade; location = _location; } }; class Selection { public: Student student; Course course; Selection(Student _student, Course _course) : student(_student), course(_course) { } };
时间: 2024-02-14 12:35:38 浏览: 31
// 引入头文件
#include<string>
#include<iostream>
#include<vector>
// 使用 std 命名空间
using namespace std;
// 学生类
class Student {
public:
string sno; // 学号
string name; // 姓名
string major; // 专业
int grade; // 年级
Student(string _sno, string _name, string _major, int _grade) {
sno = _sno;
name = _name;
major = _major;
grade = _grade;
}
};
// 课程类
class Course {
public:
string cid; // 课程 ID
string name; // 课程名称
int credit; // 学分
int capacity; // 容量
string teacher; // 授课教师
int start_grade; // 开课年级
string location; // 授课地点
Course(string _cid, string _name, int _credit, int _capacity, string _teacher, int _start_grade, string _location) {
cid = _cid;
name = _name;
credit = _credit;
capacity = _capacity;
teacher = _teacher;
start_grade = _start_grade;
location = _location;
}
};
// 选课类
class Selection {
public:
Student student; // 学生
Course course; // 课程
Selection(Student _student, Course _course)
: student(_student), course(_course) // 构造函数,初始化学生和课程信息
{
}
};
以上代码定义了三个类:Student、Course 和 Selection。其中,Student 类表示学生,包含学号、姓名、专业和年级等信息;Course 类表示课程,包含课程 ID、名称、学分、容量、授课教师、开课年级和授课地点等信息;Selection 类表示选课信息,包含学生和课程信息。这些类都有构造函数,用于初始化类的属性。同时,代码还引入了三个头文件:string、iostream 和 vector,用于支持字符串类型、输入输出和向量容器等功能。
相关推荐
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)