编写职工信息类,包含数据成员工号、姓名、性别、出生年份,包含成员函数完成输入职工所有信息、修改职工出生年份、修改职工姓名、修改职工性别、修改职工工号、输出职工的所有信息的功能,实现并测试这个类
这个就是基本的类的操作,网上例子很多,可以先自己写一下。
代码:
#include <iostream>
#include <string>
using namespace std;
typedef struct
{
int year, month, day;
}Date;
class Employee
{
private:
int mId; //工号
string mName; //姓名
string mSex; //性别
int mBirthYear; //出生年份
public:
Employee() {}
Employee(int id, string name, string sex, int y)
{
mId = id;
mName = name;
mSex = sex;
mBirthYear = y;
}
//setter
void setId(int id) { mId = id; }
void setName(string name) { mName = name; }
void setSex(string sex) { mSex = sex; }
void setBirthYear(int y) { mBirthYear = y; }
//getter
int getId() { return mId; }
string getName() { return mName; }
string getSex() { return mSex; }
int getBirthYear() { return mBirthYear; }
//show
void show()
{
cout << "工号:" << mId << ",姓名:" << mName << ",性别:" << mSex << ",出生年份:" << mBirthYear << endl;
}
};
int main()
{
Employee e(10000, "张三", "男", 1990);
e.show();
e.setId(102);
e.setName("李丽");
e.setSex("女");
e.setBirthYear(1999);
e.show();
return 0;
}