#include<iostream>
#include<cstring>
using namespace std;
class student
{
public:
student(char*name1, char*num1, int score1);
~student();
void show();
private:
char*name;
char*num;
int score;
};
student::student(char*name1, char*num1, int score1)
{
name = new char[strlen(name1) + 1];
strcpy(name, name1);
num = new char[strlen(num1) + 1];
strcpy(num, num1);
score = score1;
}
student::~student()
{
delete[]name;
delete[]num;
}
void student::show()
{
cout << "name:" << name << endl;
cout << "num:" << num << endl;
cout << "score:" << score << endl;
}
int main()
{
student student1("zhaoyujie","U201713644",99);
student1.show();
system("pause");
return 0;
#include<cstring>
using namespace std;
class student
{
public:
student(char*name1, char*num1, int score1);
~student();
void show();
private:
char*name;
char*num;
int score;
};
student::student(char*name1, char*num1, int score1)
{
name = new char[strlen(name1) + 1];
strcpy(name, name1);
num = new char[strlen(num1) + 1];
strcpy(num, num1);
score = score1;
}
student::~student()
{
delete[]name;
delete[]num;
}
void student::show()
{
cout << "name:" << name << endl;
cout << "num:" << num << endl;
cout << "score:" << score << endl;
}
int main()
{
student student1("zhaoyujie","U201713644",99);
student1.show();
system("pause");
return 0;
}