#include<iostream>
#include<string>
using namespace std;
class student{
public:
student(char *name1,char *num1,char *tel1);
void show();
private:
char *name;
char *num;
char *tel;
};
student::student(char *name1,char *num1,char *tel1)
{
name=new char[strlen(name1)+1];
strcpy(name,name1);
num=new char[strlen(num1)+1];
strcpy(num,num1);
tel=new char[strlen(tel1)+1];
strcpy(tel,tel1);
}
void student::show()
{
cout<<"name:"<<name<<endl
<<"num:"<<num<<endl
<<"tel:"<<tel<<endl;
}
int main()
{
student stu1("yangzhitao","11671132","15766249***");
stu1.show();
return 0;
}
学生类定义
最新推荐文章于 2023-03-20 21:47:53 发布