c++ day 3

c++ day 3_第1张图片

 

  1. 设计一个Per类,类中包含私有成员:姓名、年龄、指针成员身高、体重,再设计一个Stu类,类中包含私有成员:成绩、Per类对象 p1,设计这两个类的构造函数、析构函数和拷贝构造函数。
#include 
using namespace std;
class per
{
    string name;
    int age;
    int * high;
    int *weight;
public:
    per(string name,int age,int *high,int* weight):name(name),age(age)
    {
        this->high=high;
        this->weight=weight;
    }
    per(per &other):name(other.name),age(other.age)
    {
        high=other.high;
        weight=other.weight;
    }
    ~per(){
        delete high;
        delete weight;
    }
    string name1(){
        return name;
    }
    int age1(){
        return age;
    }
    int *high1(){
        return high;
    }
    int *weight1(){
        return weight;
    }
};
class stu
{
    int soc;
    per p1;
public:
    stu(int soc,string name,int age,int *high,int *wight):soc(soc),p1(name,age,high,wight)
    {
    }
    ~stu(){}
    stu(stu &other):soc(other.soc),p1(other.p1)
    {
    }

    void soc1()
    {
        cout<<"soc "<

你可能感兴趣的:(c++,开发语言)