2.06 作业

 一、

1.

Test::Test(){}

show();

2.

int x;

Test::x=33;

3.

"结 果:

姓名 成绩 等级

张三  78    中

李四  92    优

王五  63    及格

孙六  88    良

二、

1.

(1)

#include 

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 

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 
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 
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;
}

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