用c++生产一段代码,定义一个Employee类,其中包括表示姓名、街道地址、城市和邮编等属性,包括ChangeName()和display()等函数。Display()使用cout语句显示姓名、地址、城市和邮编等属性,函数setName()改变对象的姓名属性,实现并测试这个类。
时间: 2023-03-14 21:10:36 浏览: 97
#include<iostream>
using namespace std;
class Employee{
private:
string name;
string streetAddress;
string city;
int postalCode;
public:
Employee(string name, string streetAddress, string city, int postalCode) {
this->name = name;
this->streetAddress = streetAddress;
this->city = city;
this->postalCode = postalCode;
}
void setName(string name) {
this->name = name;
}
void display() {
cout << "姓名:" << this->name << endl;
cout << "街道地址:" << this->streetAddress << endl;
cout << "城市:" << this->city << endl;
cout << "邮编:" << this->postalCode << endl;
}
};
int main() {
Employee emp("张三", "北京市中关村大街1号", "北京", 100000);
emp.display();
emp.setName("李四");
emp.display();
return 0;
}
阅读全文