1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| #include<iostream> #include<string> class Date { private: int year; int month; int day; public: Date() {} Date(int year,int month,int day); ~Date(){} std::string showd()const; };
Date::Date(int year,int month,int day):year(year),month(month),day(day){} std::string Date::showd()const{ return std::to_string(year) + "-" + std::to_string(month) + "-" + std::to_string(day); } class People { private: int number; Date d; int id; public: enum sex { 男, 女 }s; People(){} People(int number, sex s, Date d, int id) :number(number), s(s), d(d), id(id) {} ~People(); People(const People& p); void record(); void show(); }; People::People(const People& p) { this->number = p.number; this->s = p.s; this->d = p.d; this->id = p.id; } People::~People() { std::cout << number << "已经录入" << std::endl; } void People::record() { int y, m, day; int sexInput; std::cout << "输入编号:"; std::cin >> number; std::cout << std::endl;
std::cout << "输入性别:"; std::cin >> sexInput; s = (sexInput == 0) ? 女 : 男; std::cout << std::endl;
std::cout << "输入出生日期:"; std::cin >> y >> m >> day; d = Date(y, m, day); std::cout << std::endl;
std::cout << "输入id:"; std::cin >> id; std::cout << std::endl; } void People::show() { std::cout << "编号:" << number <<std::endl<< "性别:" <<(s == 男 ? "男" : "女") <<std::endl<< "出生日期:"<< d.showd() <<std::endl<< "id:" << id << std::endl; } int main() { People p; p.record(); p.show(); return 0; }
|