全部知识点

第7721题

若变量a的定义为“int a=8;”,则下列逻辑表达式中其值为false的 是( )。

第7722题

下列不属于C++关键字的是( )。

第7723题

下列不属于C++预定义的流对象的是( )。

第7724题

下列关于函数模板的说法,正确的是( )。

第7725题

下列关于构造函数的说法中,正确的是( )。

第7726题

下列关于函数的说法中,正确的是( )。

第7727题

请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程文件 proj1。此工程包含程序文件 main.cpp,其中有类Door和主函数main的 定义。程序中位于每个“//ERROR*********found*********”下的语句行 有错误,请加以更正。更正后程序的输出应该是:

 打开503号门...门是锁着的,打不开。打开503号门的 锁...锁开了。 

 打开503号门...门打开了。 

 打开503号门...门是开着的,无须再开门。 锁上503号门...先关门...门锁上了。

 注意:只能修改每个“//ERROR********found*********”下的那一 行,不要改动程序中的其他内容。

# include<iostream>
using namespace std ;
class Door{
    int num;        // 门号
    bool closed;    // true 表示门关着
    bool locked;    // true 表示门锁着
public:
    // ERROR ********* found *********
    Door(int n) : num(n), closed(true), lock(true) { }
    bool isClosed( ) const { return closed; }       // 门关着时返回 true,否则返回 false
    bool isOpened( ) const { return ! closed; }     // 门开着时返回 true,否则返回 false
    bool isLocked( ) const{ return locked; }        // 门锁着时返回 true,否则返回 false
    bool isUnlocked( ) const { return ! locked; }   // 门未锁时返回 true,否则返回 false
    // ERROR ********* found *********
    void open( ) const {        // 开门
        cout << endl << "打开" << num << "号门...";
        if ( ! closed )
            cout << "门是开着的,无须再开门。";
        else if (locked)
            cout << "门是锁着的,打不开。";
        else {
            closed = false;
            cout << "门打开了。";
        }
    }
    void close ( ) {        // 关门
        cout << endl << "关上" << num << "号门...";
        if(closed)
            cout << "门是关着的,无须再关门。";
        else{
            closed = true;
            cout << "门关上了。";
        }
    }
    void lock( ) const {    // 锁门
        cout << endl << "锁上" << num << "号门...";
        if(locked)
            cout << "门是锁着的,无须再锁门。";
        else{
            // ERROR ********* found *********
            if(closed){
                cout<<"先关门...";
            closed = true;
            }
            locked = true;
            cout << "门锁上了。";
        }
    }
    void unlock( ) {    // 开锁
        cout<< endl << "打开" << num << "号门的锁...";
        if ( ! locked )
            cout << "门没有上锁,无须再开锁。";
        else{
            locked = false;
            cout << "锁开了。";
        }
    }
};
int main( ) {
    Door door(503);
    door.open( );
    door.unlock( );
    door.open( );
    door.open( );
    door.lock( );
    return 0;
}
第7728题

请使用“答题”菜单或使用VC6打开考生文件夹proj1下的工程文件 proj1,程序中位于每个“//ERROR*********found*********”下的语句行 有错误,请加以更正。更正后程序的输出应该是:

 Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 

注意:只能修改每个“//ERROR*********found*********”下的那一 行,不要改动程序中的其他内容。

源程序如下:

# include <iostream>
using namespace std;
class StudentInfo
{
protected:
    // ERROR ********* found *********
    char Name[30] ;
    int Age;
    int ID;
    int CourseNum;
    float Record;
public:
    // ERROR ********* found *********
    void StudentInfo (char * name , int age, int ID , int courseNum , float record );
    ~StudentInfo( ) { delete [ ] Name ; }
    float AverageRecord( ) {
        return Record/CourseNum;
    }
    void show( ) const;
};
StudentInfo :: StudentInfo ( char * name, int age, int ID, int courseNum, float record)
{
    Name = strdup(name);
    Age = age;
    this -> ID = ID;
    CourseNum = courseNum;
    Record = record;
}
// ERROR ********* found *********
void StudentInfo::show( )
{
    cout << "Name: " << Name << " " << "Age: " << Age << " " << " ID: " << ID
         << "    CourseNum: " <<CourseNum<< "    Record: " <<Record<< endl;
}
int main()
{
    StudentInfo st("Smith",21,99999,12,970);
    st.show();
    return 0;
}
第7729题

请使用“答题”菜单或使用VC6菜单打开考生文件夹proj2下的工程 proj2,其中包含抽象类Shape的声明,以及在此基础上派生出的类 Rectangle和Circle的声明,两者都有计算对象面积的函数GetArea()和 计算对象周长的函数GetPerim()。

The area of the Circle is 78.5

The perimeter of the Circle is 31.4

The area of the Rectangle is 24

The perimeter of the Rectangle is 20

注意:只能在横线处填写适当的代码,不要改动程序中的其他内 容,也不能删除或移动“//**********found**********”。 

源程序如下:

# include <iostream>
using namespace std;
class Shape
{
public:
    Shape(){}
    ~Shape(){}
    //**********found**********
    __________ float GetArea() = 0
    //**********found**********
    __________ float GetPerim () = 0
};
class Circle : public Shape
{
public:
    Circle(float radius) : itsRadius(radius){ }
    ~Circle(){ }
    float GetArea() { return 3.14 * itsRadius * itsRadius; }
    float GetPerim () { return 6.28 * itsRadius; }
private:
    float itsRadius;
};
class Rectangle : public Shape
{
public:
    //**********found**********
    Rectangle(float len, float width): __________ {};
    ~Rectangle(){};
    virtual float GetArea() { return itsLength * itsWidth; }
    float GetPerim () { return 2 * itsLength + 2 * itsWidth; }
    virtual float GetLength() { return itsLength; }
    virtual float GetWidth() { return itsWidth; }
private:
    float itsWidth;
    float itsLength;
};
int main() {
    //**********found**********
    __________
    sp = new Circle(5);
    cout << "The area of the Circle is " << sp -> GetArea () << endl;
    cout << "The perimeter of the Circle is " << sp -> GetPerim () << endl;
    delete sp;
    sp = new Rectangle(4, 6);
    cout << "The area of the Rectangle is " << sp -> GetArea() << endl;
    cout << "The perimeter of the Rectangle is " << sp -> GetPerim () << endl;
    delete sp;
    return 0;
}
第7730题

请使用“答题”菜单或使用VC6菜单打开考生文件夹proj2下的工程 proj2。此工程包含一个程序文件 main.cpp,其中有日期类Date、人员 类Person以及排序函数sortByAge和主函数main的定义。请在程序中的横 线处填写适当的代码,然后删除横线,以实现该程序。此程序的正确 输出结果应为:

排序前:

张三 男 出生日期:1978年4月20日

王五 女 出生日期:1965年8月3日

杨六 女 出生日期:1965年9月5日

李四 男 出生日期:1973年5月30日

排序后:

张三 男 出生日期:1978年4月20日

李四 男 出生日期:1973年5月30日

杨六 女 出生日期:1965年9月5日

王五 女 出生日期:1965年8月3日

注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动“//**********found**********”。

源程序如下:

# include <iostream>
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**********
        strcpy(this -> name, _________);
    }
    const char * getName()const{ return name; }
    bool isMale()const{ return is_male; }
    Date getBirthdate()const{ return birth_date; }
    int compareAge(const Person &p)const{
        //比较两个人的年龄,返回正数、0或负数,分别表示大于、等于和小于
        int n;
        n = p.birth_data.getYear() - birth_data.getYear();
        if( n != 0 ) return n ;
        //**********found**********
        ___________________________
        if( n != 0 ) return n ;
        return p.birth_data.getDay() - birth_data.getDay();
    }
    void show(){
        cout<<endl;
        cout<<name<<' ';        //显示姓名
        //**********found**********
        << ___________________  //显示性别(“男”或“女”,双引号内不含空格)
        <<"出生日期"            //显示出生日期
        <<birth_date.getYear()<<"年"
        <<birth_date.getMonth() << "月"
        <<birth_date.getDay()<<"日";
    }
};
void sortByAge(Person ps[], int size){  //将人员数组按年龄由小到大顺序排序
                                        //采用挑选排序算法
    for(int i=0; i<size-1; i++ ){
        int m = i;
        for(int j = i+1; j<size; j ++ )
            if(ps[j].compareAge(ps[m])<0) m = j;
        if(m>i){
            //**********found**********
            Person p = ______________________;
            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<<"排序前:";
    for(i=0; i<size; i++) staff[i].show();
    sortByAge(staff,size);
    cout<<endl<<endl<<"排序后:";
    for(i=0; i<size; i++) staff[i].show();
    cout<<endl;
    return 0;
}
第7731题

请使用“答题”菜单或使用VC6打开考生文件夹proj3下的工程文件proj3,其中声明了CDeepCopy类,它是一个用于表示动态数组的类。请编写其中的复制构造函数。

要求:

补充编制的内容写在//********333********与//********666********两行之间。不得修改程序的其他部分。

注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。

部分源程序如下:

/**********code.c**********/
# include "CDeepCopy.h"
CDeepCopy :: ~CDeepCopy() { delete[] p ;}
CDeepCopy:: CDeepCopy(int k) { n = k; p = new int[n]; } //构造函数实现
CDeepCopy:: CDeepCopy(const CDeepCopy& r) //复制构造函数
{
    /*******333*******/
    /*******666*******/
}
int main()
{
    CDeepCopy a(2),d(3);
    a.p[0] = 1; d.p[0] = 666   //对象 a,d 数组元素的赋值
    {
        CDeepCopy b(a);
        a.p[0] = 88 ;
        cout<<b.p[0]         //显示内层局部对象的数组元素
    }
    cout<<d.p[0];        //显示 d 数组元素 a.p[0] 的值
    cout<<"d fade away:\n"; cout<<a.p[0]   //显示 a 数组元素 a.p[0] 的值
    writeToFile("k:\k01\61010001\");
    return 0
}
结果文件 out.dat 内容如下:
5222 d fade away:
66
/**********code.c**********/
第7732题

请使用“答题”菜单或使用VC6打开考生文件夹proj3下的工程文件proj3,其中包含了类Integers和主函数main的定义。一个Integers对象就是一个整数的集合,其中包含0个或多个可重复的整数。成员函数 add将一个元素添加到集合中,成员函数remove从集合中删除指定的元素(如果集合中存在该元素),成员函数 filter去除集合中的所有负整数。请编写这个filter函数。此程序的正确输出结果应为:

5 28 2 -4 5 3 2 -75 27 66 31

5 28 2 -4 5 3 2 -75 27 66 31 6

5 28 2 -4 5 3 2 -75 27 66 31 6 -19

5 28 2 -4 5 3 -75 27 66 31 6 -19 4

5 28 2 -4 5 3 -75 27 66 31 6 -19 4

5 28 2 5 3 27 66 31 6 4

要求: 

补充编制的内容写在//********333********与//********666******** 两行之间。不得修改程序的其他部分。 

注意:相关文件包括:main.cpp、Integers.h。 

程序最后已经调用WriteToFile函数,使用另一组不同的测试数据, 将不同的运行结果输出到文件out.dat中。输出函数writeToFile已经编译 为obj文件。 

部分源程序如下:

/**********code.c**********/
# include "Integers.h"
# include <iomanip>
Integers::Integers(int data[], int size): counter(0){
    for(int i=0; i<size; i++) add(data[i]);
}
void Integers::add(int element){
    if(counter<MAXELEMENTS) elemK[counter++] = element;
}
void Integers::remove(int element){
    int j;
    for(j = counter - 1; j >= 0; j --)
        if(elem[j] == element) break;
    for(int i = j; i<counter - 1; i++) elem[i] = elem[i+1];
    counter -- ;
}
void Integers::filter(){
    //**********333**********
    //**********666**********
}
void Integers::show() const{
    for(int i = 0; i<getCount(); i++)
        cout<<setw(4)<<getElement(i);
    cout<<endl;
}
int main(){
    int d[] = {5,28,2,-4,5,3,2,-75,27,66,31};
    Integers s(d,11); s.show();
    s.add(6);
    s.show();
    s.add(-19);
    s.show();
    s.remove(2);
    s.show();
    s.add(4);
    s.show();
    s.filter();
    s.show();
    writeToFile("k:\k01\61010001\");
    return 0;
}
/**********code.c**********/

结果文件out.dat内容如下:

0,27,-2,9,67,62 ,

第7733题

若变量a的定义为“int a=8;”,则下列逻辑表达式中其值为false的 是( )。