When I first learned the code in the C ++ practice class, it was easy to understand the class. The interface is also unfriendly (it is estimated that no one except me can understand what it is ).
/* Design a people class for personnel management. Considering universality, only attributes of all types of personnel are abstracted: Number, sex, birthday, ID, and so on. The "birthdate" is defined as an embedded sub-object of the "date" class. Use member functions to record and display personnel information. Requirements include constructor and destructor, copy constructor, inline member function, and aggregation. Defines a date class, including year, month, and day. In the defined people class, including number, sex, birthday, and ID ). The main () function constructs several people class objects and provides several member functions to input and display personnel information. In addition, each class requires constructors and destructor. Program name: lab2_3.cpp. */# Include <iostream> using namespace STD; Class Date {PRIVATE: int year; int month; int day; public: Date () {cout <"date is created" <Endl;} void input () {CIN> year> month> day;} void print () {cout <year <". "<month <". "<day <". "<Endl ;}~ Date () {cout <"date is ruined" <Endl ;}}; class people {PRIVATE: int number; int sex; Date birthday; int ID; public: people () {cout <"Create a people" <Endl <"Please input his number, sex (0 is man.1 is woman ), ID and birthday "<Endl;} People (People & A) {cout <" copy a people "<" \ n "; number =. number; Sex =. sex; Birthday =. birthday; id =. ID;} void input () {CIN> number> sex> ID; birthday. input ();} void print () {cout <numb Er <Endl <sex <Endl <id <Endl; birthday. Print ();}~ People () {cout <"people is Delete" <Endl ;}; void main () {People people1; people1.input (); people1.print (); people people2 (people1); people2.print ();}
The program runs as follows. It is estimated that the program looks at the Pan-pilot. Fortunately, the code is simple.