#include <iostream>
#include<string>
using namespace std;
//Emp.h
using namespace std;
class CEmp
{
public:
CEmp();
virtual~CEmp(){delete[] name;}
void set_name(char *);
void set_age(short a){age=a;};
void set_salary(float s){salary=s;};
void print();
private: char *name;
short age;
float salary;
};
//Emp.cpp
CEmp::CEmp()
{
name=0;
age=0;
salary=0;
}
void CEmp::set_name(char *n)
{
name=new char(strlen(n)+1);
strcpy(name,n);
}
void CEmp::print()
{
cout<<"Name:"<<name;
cout<<"Age:"<<age;
cout<<"Salary:"<<salary<<endl;
}
//text.cpp
int main(int argc,char* argv[])
{
char *name=NULL;
short age=0;
float salary=0;
name=new char[30];
CEmp emp[3];
for(int i=0;i<3;i++)
{
cout<<"输入第"<<i+1<<"员工的信息"<<endl;
cout<<"姓名:";
cin>>name;
cout<<"年龄:";
cin>>age;
cout<<"工资:";
cin>>salary;
emp[i].set_name(name);
emp[i].set_age(age);
emp[i].set_salary(salary);
emp[i].print();
}
system("Pause");
return 0;
}
#include<string>
using namespace std;
//Emp.h
using namespace std;
class CEmp
{
public:
CEmp();
virtual~CEmp(){delete[] name;}
void set_name(char *);
void set_age(short a){age=a;};
void set_salary(float s){salary=s;};
void print();
private: char *name;
short age;
float salary;
};
//Emp.cpp
CEmp::CEmp()
{
name=0;
age=0;
salary=0;
}
void CEmp::set_name(char *n)
{
name=new char(strlen(n)+1);
strcpy(name,n);
}
void CEmp::print()
{
cout<<"Name:"<<name;
cout<<"Age:"<<age;
cout<<"Salary:"<<salary<<endl;
}
//text.cpp
int main(int argc,char* argv[])
{
char *name=NULL;
short age=0;
float salary=0;
name=new char[30];
CEmp emp[3];
for(int i=0;i<3;i++)
{
cout<<"输入第"<<i+1<<"员工的信息"<<endl;
cout<<"姓名:";
cin>>name;
cout<<"年龄:";
cin>>age;
cout<<"工资:";
cin>>salary;
emp[i].set_name(name);
emp[i].set_age(age);
emp[i].set_salary(salary);
emp[i].print();
}
system("Pause");
return 0;
}