c/c++课的作业合集,都是很简单的文件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cpp-work/test1/20220317-5.cpp

116 lines
2.1 KiB

3 years ago
#include <iostream>
#include <cstring>
class Date {
int year;
int month;
int day;
public:
Date(int year, int month, int day) : year(year), month(month), day(day) {}
Date() : year(1970), month(1), day(1) {}
Date(const Date &date) {
Date::year = date.year;
Date::month = date.month;
Date::day = date.day;
}
int getYear() const {
return year;
}
void setYear(int year) {
Date::year = year;
}
int getMonth() const {
return month;
}
void setMonth(int month) {
Date::month = month;
}
int getDay() const {
return day;
}
void setDay(int day) {
Date::day = day;
}
void setDate(int year, int month, int day) {
Date::year = year;
Date::month = month;
Date::day = day;
}
};
class Staff {
private:
char *name;
int id;
char sex;
Date birthday;
public:
Staff(char *name, int id, char sex, const Date &birthday) : name(name), id(id), sex(sex), birthday(birthday) {}
Staff() : name("name"), id(0), sex('M') {
}
Staff(const Staff &staff) {
strcpy(name, staff.name);
id = staff.id;
sex = staff.sex;
birthday = staff.birthday;
}
char *getName() const {
return name;
}
void setName(char *name) {
strcpy(Staff::name, name);
}
int getId() const {
return id;
}
void setId(int id) {
Staff::id = id;
}
char getSex() const {
return sex;
}
void setSex(char sex) {
Staff::sex = sex;
}
const Date &getBirthday() const {
return birthday;
}
void setBirthday(const Date &birthday) {
Staff::birthday = birthday;
}
void setStaff(char *name, int id, char sex, const Date &birthday) {
strcpy(Staff::name, name);
Staff::id = id;
Staff::sex = sex;
Staff::birthday = birthday;
}
};
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}