1. 设计一个学生类,其中包括姓名、年龄、学号和出生日期等属性,并提供构造方法和访问方法。
时间: 2023-05-27 22:03:06 浏览: 56
class Student:
def __init__(self, name, age, iden, birthdate):
self.name = name
self.age = age
self.iden = iden
self.birthdate = birthdate
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_iden(self):
return self.iden
def get_birthdate(self):
return self.birthdate
相关问题
使用Java语言 设计一个学生类,其中包括姓名、年龄、学号和出生日期等属性,并提供构造方法和访问方法。
public class Student {
private String name; // 姓名
private int age; // 年龄
private String studentId; // 学号
private String birthDate; // 出生日期
// 构造方法
public Student(String name, int age, String studentId, String birthDate) {
this.name = name;
this.age = age;
this.studentId = studentId;
this.birthDate = birthDate;
}
// 访问方法
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getStudentId() {
return studentId;
}
public String getBirthDate() {
return birthDate;
}
}
4.定义一个学生类,包括学号、姓名和出生日期三个属性(数据成员);包括一个
构造函数,用于初始化学生对象;包括一个成员函数,用于输出学生的信息。代码如下:
```cpp
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string id; // 学号
string name; // 姓名
string birthdate; // 出生日期
public:
Student(string i, string n, string b) { // 构造函数
id = i;
name = n;
birthdate = b;
}
void display() { // 成员函数
cout << "学号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "出生日期:" << birthdate << endl;
}
};
int main() {
Student stu("20210001", "张三", "2003.01.01");
stu.display();
return 0;
}
```
运行结果:
```
学号:20210001
姓名:张三
出生日期:2003.01.01
```