#include<iostream>
#include<string>
using namespace std;
class student{
public:
student(char *name1,char *place1,float score1);
void disp();
private:
char *name;
char *place;
float score;};
student::student(char *name1,char *place1,float score1)
{name=new char[strlen(name1)+1];
strcpy(name,name1);
place=new char[strlen(place1)+1];
strcpy(place,place1);
score=score1;}
void student::disp()
{cout<<"name:"<<name<<endl;
cout<<"place:"<<place<<endl;
cout<<"score:"<<score<<endl;
}
int main()
{student stu1("dlh","广东省广州市",100);
stu1.disp();
student stu2("wy","广东省潮州市",10);
stu1.disp();
return 0;
}
定义学生类
最新推荐文章于 2023-11-25 13:37:29 发布