2016年計(jì)算機(jī)二級(jí)《C++》考前模擬試題:基本操作

字號(hào):

二、基本操作題
    41請(qǐng)使用VC6或使用【答題】菜單打開(kāi)考生文件夾projl下的工程projl,其中有枚舉DOGCOLOR、狗類(lèi)Dog和主函數(shù)main的定義。程序中位于每個(gè)“//ERROR ****found****”下的語(yǔ)句行有錯(cuò)誤,請(qǐng)加以改正。改正后程序的輸出結(jié)果應(yīng)該是:
    There is a white dog named Hoh0. There is a blaCk dog named Haha. There is a motley dog named Hihi. 注意:只修改每個(gè)//ERROR****found****女料下的那一行,不要改動(dòng)程序中的其他內(nèi)容。
    #inClude using namespaCe std; //狗的顏色:黑、白、黃、褐、花、其他
    enum DOGCOLOR{BLACK,WHITE,YELLOW,BROWN,PIEBALD,OTHER}; Class Dog{//狗類(lèi)
    DOGCOLOR Color; Char name[20]; statiC int Count; publiC:
    Dog(Char nalTle[],DOGCOLOR Color){ strCpy(this一>name,name);
    //ERROR**********found**********、
    strCpy(this一>Color,Color);
    } 1 DOGCOLOR getColor()Const{retum Color;}
    //ERROR**********found**********
    Const Char * 9etName()Const{return*finin9;} Const Char * 9etColorString()Const{
    switCh(Color){
    Case BLACK:return”blaCk“; Case WHITE:return”white”:
    Case YELLOW:return’"yellow”: Case BROWN:return”brown”; ease PIEBALD:return”piebald”:
    }
    return”motley”;
    }
    void show()Const{ . Cout<<”There is a”<
    } }; int main(){
    //ERROR**********found**********
    Dog dogl(”Hoh0”,WHITE),dog2(”Haha”,BLACK);d0g3(”Hihi”,0THER); d091.show();
    dos2.show(); dos3.show(); return 0;
    }
    參考解析:
    (1)this->color=color:
    (2)consL char getName()eonst{return*name;}
    (3)Dog dogl(”Hoho”,WHITE)。dog2(”Haha”,
    BLACK),dog3(”Hihi”,OTHER);