计算机二级大题.

1题
#include 
using namespace std;
class MyClass {
public:
    MyClass(int len)
    {
       array = new int[len];
        arraySize = len;
        for(int i = 0; i < arraySize; i++)
            array[i] = i+1;
    }

    ~MyClass()
    {
// ERROR   **********found**********
        delete []array;
    }

    void Print() const
    {
        for(int i = 0; i < arraySize; i++)
// ERROR   **********found**********
            cout<< array[i] << ' ';

        cout << endl;
    }
private:
    int *array;
    int arraySize;
};

int main()
{
// ERROR   **********found**********
    MyClass obj(10);

    obj.Print();
    return 0;
}

D:\untitled2\cmake-build-debug\untitled2.exe
1 2 3 4 5 6 7 8 9 10
2
#include 
using namespace std;
class vehicle
{
private:
    int MaxSpeed;
    int Weight;
public:
    //**********found**********
    vehicle(int maxspeed, int weight):MaxSpeed(maxspeed),Weight(weight)
    {
    };
    ~vehicle(){};
    int getMaxSpeed() { return MaxSpeed; }
    int getWeight() { return  Weight; }
};

//**********found**********
class bicycle : virtual public vehicle
{
private:
int Height;
public:
bicycle(int maxspeed, int weight, int height):vehicle(maxspeed, weight),Height(height){}
int getHeight(){ return Height; };
};

//**********found**********
class motorcar : virtual public vehicle
{
private:
int SeatNum;
public:
motorcar(int maxspeed, int weight, int seatnum):vehicle(maxspeed, weight),SeatNum(seatnum){}
int getSeatNum(){ return SeatNum; };
};

//**********found**********
class motorcycle : public motorcar,public bicycle
{
public:
    motorcycle(int maxspeed, int weight, int height):
            vehicle(maxspeed, weight),bicycle(maxspeed, weight,height),motorcar(maxspeed, weight, 1){}
};

int main()
{
    motorcycle a(80,150,100);
    cout<
80
150
100
1
3
#include
using namespace std;
class Xabc {
    int *a; int n;
public:
    Xabc(int aa[], int nn) {  //构造函数
        // ERROR **********found**********
        n=nn;
        // ERROR **********found**********
        a=new int[n];
        for(int i=0; i 
  
4
#include
#include
using namespace std;

class Date {            // 日期类
    int year, month, day;  // 年、月、日
public:
    Date(int year, int month, int day) :year(year), month(month), day(day) {}
    int getYear()const { return year; }
    int getMonth()const { return month; }
    int getDay()const { return day; }
};

class Person {       // 人员类
    char name[14];    // 姓名
    bool is_male;     // 性别,为 true 时表示男性
    Date birth_date;  // 出生日期
public:
    Person(char *name, bool is_male, Date birth_date)
        //**********found**********
        :is_male(is_male), birth_date(birth_date)
    {
        strcpy_s(this->name, name);
    }
    const char *getName()const { return name; }

    bool isMale()const { return is_male; }

    Date getBirthdate()const { return birth_date; }

    //利用strcmp()函数比较姓名,返回一个正数、0 或负数,分别表示大于、等于、小于
    int compareName(const Person &p)const {
        //**********found**********
        return strcmp(name, p.name);
    }

    void show() {
        cout << endl;
        cout << name << ' ' << (is_male ? "男" : "女") << ' ' << "出生日期:"
            << birth_date.getYear() << "年"       //显示出生年
                                                 //**********found**********
            << birth_date.getMonth() //显示出生月
            << birth_date.getDay() << "日";       //显示出生日
    }
};

void sortByName(Person ps[], int size) {  //将人员数组按姓名排列为升序
    for (int i = 0; ii) {
            Person p = ps[m];
            ps[m] = ps[i];
            ps[i] = p;
        }
    }
}

int main() {
    Person staff[] = {
        Person("张三", true, Date(1978, 4, 20)),
        Person("王五", false, Date(1965,8,3)),
        Person("杨六", false, Date(1965,9,5)),
        Person("李四", true, Date(1973,5,30))
    };

    const int size = sizeof(staff) / sizeof(staff[0]);
    int i;
    cout << endl << "按姓名排序";
    cout << endl << "排序前:";
    for (i = 0; i
结果

你可能感兴趣的:(计算机二级大题.)