c++创建动态数组,怎么在主函数里用键盘输入数组元素个数?
利用下面已定义的Employee类,在主程序中声明包含若干个元素的对象数组,每个元素都是Employee类型的对象。要求从键盘输入数组大小,建立动态数组。classEmp...
利用下面已定义的Employee类,在主程序中声明包含若干个元素的对象数组,每个元素都是Employee类型的对象。要求从键盘输入数组大小,建立动态数组。
class Employee{
private:
string name;
string address;
string city;
string postcode;
public:
Employee():name("a"),address("b"),city("c"),postcode("d"){}
Employee(string n,string a,string c,string p):name(n),address(a),city(c),postcode(p){
cout<<"End Entering"<<endl;}
~Employee(){cout<<"End"<<endl;}
void setName(){
string n;
cout<<"Enter Nmae:";
cin>>n;
name=n;}
void display(){
cout<<"Name:"<<name<<endl;
cout<<"Address:"<<address<<endl;
cout<<"City:"<<city<<endl;
cout<<"Postcode:"<<postcode<<endl;
cout<<"Displaying all"<<endl;}
}; 展开
class Employee{
private:
string name;
string address;
string city;
string postcode;
public:
Employee():name("a"),address("b"),city("c"),postcode("d"){}
Employee(string n,string a,string c,string p):name(n),address(a),city(c),postcode(p){
cout<<"End Entering"<<endl;}
~Employee(){cout<<"End"<<endl;}
void setName(){
string n;
cout<<"Enter Nmae:";
cin>>n;
name=n;}
void display(){
cout<<"Name:"<<name<<endl;
cout<<"Address:"<<address<<endl;
cout<<"City:"<<city<<endl;
cout<<"Postcode:"<<postcode<<endl;
cout<<"Displaying all"<<endl;}
}; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询