class stu { public: int id, profess, academy, grade, kaoyan; string name, gender; int getscore(stu s) { if(gender != s.gender) return 0; int score = 1; if(kaoyan == s.kaoyan) score += 10; if(grade == s.grade) score += 20; if(academy == s.academy) score += 25; if(profess == s.profess) score += 45; return score; } void show() { cout << id << " " << name << " " << gender << " " << profess << " " << academy << " " << grade << " " <<kaoyan << endl; } };
时间: 2024-04-08 18:32:10 浏览: 18
这是一个名为`stu`的类,它有以下成员变量和成员函数:
成员变量:
- `id`:学生的ID
- `profess`:学生的专业
- `academy`:学生所属的学院
- `grade`:学生的年级
- `kaoyan`:是否考研,整数类型(0表示未考研,1表示考研)
- `name`:学生的姓名,字符串类型
- `gender`:学生的性别,字符串类型
成员函数:
- `getscore(stu s)`:计算当前学生与给定学生`s`之间的匹配度分数。如果两个学生的性别不同,返回0;否则根据两个学生的考研情况、年级、学院和专业进行加权计算,返回最终得分。
- `show()`:将学生的信息以一行输出。
请注意,以上代码只是类的定义,没有包含类的实现部分。
相关问题
给出下面的人员基类框架: class Person { protected: string name; int age; public: Person(); Person (string p_name, int p_age); void display () {cout<<name<<“:”<<age<<endl;} }; 建立一个派生类student,增加以下成员数据: int ID;//学号 float cpp_score;//
下面是实现了上述要求的 `Student` 类的代码:
```cpp
#include <iostream>
using namespace std;
class Person {
protected:
string name;
int age;
public:
Person();
Person(string p_name, int p_age);
void display() {
cout << name << ":" << age << endl;
}
};
class Student : public Person {
protected:
int ID; // 学号
float cpp_score; // C++ 成绩
public:
Student(string p_name, int p_age, int p_id, float p_cpp_score);
void display() {
cout << name << ":" << age << ":" << ID << ":" << cpp_score << endl;
}
};
Person::Person() {
name = "";
age = 0;
}
Person::Person(string p_name, int p_age) {
name = p_name;
age = p_age;
}
Student::Student(string p_name, int p_age, int p_id, float p_cpp_score) : Person(p_name, p_age) {
ID = p_id;
cpp_score = p_cpp_score;
}
int main() {
Student stu("张三", 20, 1001, 90.5);
stu.display();
return 0;
}
```
需要注意的是,派生类 `Student` 中的 `display` 函数覆盖了基类 `Person` 中的 `display` 函数,因为它们的函数名和参数列表都相同。在 `Student` 类的 `display` 函数中,我们不仅输出了基类中的 `name` 和 `age`,还输出了派生类中的 `ID` 和 `cpp_score`。
REATE TABLE IF NOT EXISTS stu(id INT PRIMARY KEY, key又什么用
在创建表的语句中,`key`关键字用于定义表中的索引。索引是一种特殊的数据结构,它可以帮助我们快速地查询和定位表中的数据。使用`key`关键字定义索引后,我们可以在查询语句中使用`where`子句来加快查询速度。在实际应用中,我们通常会在表中添加一个主键(如这里的`id`字段),并使用`key`关键字为主键创建索引,以确保表中的数据能够快速地被查询和管理。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)