2.06 作业

 一、

1.

Test::Test(){}

show();

2.

int x;

Test::x=33;

3.

"结 果:

姓名 成绩 等级

张三  78    中

李四  92    优

王五  63    及格

孙六  88    良

二、

1.

(1)

#include <iostream>

using namespace std;
class Stu
{
    int x;
    static int y;
public:
    Stu()
    {
        x=0;
        y=1;
    }
    ~Stu()
    {
        y=y-1;
    }

};

int main()
{
    return 0;
}

(2)

#include <iostream>

using namespace std;
class Stu1
{
    int x;
    static int y;
public:
    Stu1()
    {
        x=0;
        y=1;
        cout<< x << y << endl;
    }
    ~Stu1()
    {
        y=y-1;
        cout<< x << y << endl;
    }
};

class Stu2
{
    int x;
    static int y;
public:
    Stu2()
    {
        x=0;
        y=1;
        cout<< x << y << endl;
    }
    ~Stu2()
    {
        y=y-1;
        cout<< x << y << endl;
    }
};

class Stu3
{
    int x;
    static int y;
public:
    Stu3()
    {
        x=0;
        y=1;
        cout<< x << y << endl;
    }
    ~Stu3()
    {
        y=y-1;
        cout<< x << y << endl;
    }
};
int main()
{
    return 0;
}

(3)

没看懂题目

2.

(1)

void SetValue(Animal& ta, int tw, int tn),void SetValue(Animal& ta, int tw, int tn)没加friend

(2)

#include <iostream>
using namespace std;
class Animal;
void SetValue(Animal&, int);
void SetValue(Animal&, int, int);
class Animal
{
public:
 
protected:
    int itsWeight;
    int itsAge;

void SetValue(Animal& ta, int tw)
{
    ta.itsWeight = tw;
}

void SetValue(Animal& ta, int tw, int tn)
{
    ta.itsWeight = tw;
    ta.itsAge = tn;
}
};
int main()
{
    Animal peppy;
    SetValue(peppy, 5);
    SetValue(peppy, 7,9);
    
    return 0;
}

3.

#include <iostream>
using namespace std;

class Boat;

class Car {
public:
    Car(int j) { size = j; }
    int Leisure(int time, Boat& bobj);
    
    void set(int j) { size = j; }
    
private:
    int size;
};

class Boat {
public:
    Boat(int j) { size = j; }
    int Leisure(int time, Car& aobj);
    
    void set(int j) { size = j; }
    
private:
    int size;
};

int Car::Leisure(int time, Boat& bobj) {
    return time * size * bobj.size;
}

int Boat::Leisure(int time, Car& aobj) {
    return time * size * aobj.size;
}

int main() {
    Car c1(2);
    Boat bl(3);
    int time = 4;
    
    cout << c1.Leisure(time, bl) << endl;
    
    return 0;
}

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值