用c++设计一个学生student类,包括学生姓名,学号,住址,成员函数包括constructor,setName,setID,setAddress,getName,getID,getAddress和print
时间: 2024-06-13 11:08:36 浏览: 159
以下是用C++设计的学生类,包括学生姓名,学号,住址,以及成员函数包括constructor,setName,setID,setAddress,getName,getID,getAddress和print:
```cpp
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string name;
string id;
string address;
public:
Student(string name, string id, string address) {
this->name = name;
this->id = id;
this->address = address;
}
void setName(string name) {
this->name = name;
}
void setID(string id) {
this->id = id;
}
void setAddress(string address) {
this->address = address;
}
string getName() {
return name;
}
string getID() {
return id;
}
string getAddress() {
return address;
}
void print() {
cout << "Name: " << name << endl;
cout << "ID: " << id << endl;
cout << "Address: " << address << endl;
}
};
int main() {
Student s("Tom", "001", "Beijing");
s.print();
s.setName("Jerry");
s.setID("002");
s.setAddress("Shanghai");
s.print();
return 0;
}
```
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![chm](https://img-home.csdnimg.cn/images/20250102104920.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.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)