具体就不说啦,应该能看懂的
#include<iostream.h>
#include<string.h>
class Student {
public:
Student(char *name1, char *insterest1, int hight1);
~Student();
void show();
private:
char *name;
// Student's name
char *interest;
// Student's interest
int hight;
// Student's hight
};
Student::Student(char *name1, char *insterest1, int hight1)
{
name = new char[strlen(name1)+1];
strcpy(name, name1);
interest = new char[strlen(insterest1)+1];
strcpy(interest, insterest1);
hight = hight1;
}
Student::~Student()
{
delete []name;
delete []interest;
}
void Student::show()
{
cout << "name:" << name <<endl;
cout << "interest:" << interest << endl;
cout << "hight:" << hight << "CM" <<endl;
cout << endl;
}
void main()
{
Student ob1("2B", "play basketball", 150);
ob1.show();
Student ob2("3B", "play football", 175);
ob2.show();
}