单选题 C++ 题号 #2607968 下列语句都是程序运行时的第1条输出语句,其中一条语句的输出效果与其他三条语句不同,该语句是( )。 A.cout<<internal<<12345; B.eout<<left<<12345; C.cout<<right<<12345; D.cout<<setw(6)<<12345; 收起答案及解析 进入在线模考 参考答案 D 答案解析 本题考查控制输出格式,A、B、c选项都会输出“12345”,只有D选项输出“12345”,所以本题答案为D。 你可能感兴趣的试题 1 请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl。程序中位于每个“//ERROR****found料****之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: Name:Smith Age:21 ID:99999 CourseNum:12 Record:970 注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。 #include<iostream> using namespace std; class Studentlnfo { protected: //ERROR********************found**************** char Name; int Age; int ID: int CourseNum; float Record; public: Studentlnfo(char*name,int Age,int ID,int coumeNum,float record); //ERROR ********************found******************** void~Studentlnfo(){} float AverageRecord(){ return Record/CourseNum; } void show()const{ cout<<”Name:”<<Name<<”Age:”<<Age<<”ID:”<<ID <<”CourseNum:”<<CourseNum<<”Record:”<<Record<<endl; } }; //ERROR ******************found************** StudentInfo StudentInfo(char*Name,int Age,int ID,int CourseNum,float Record) { Name=name; Age=age; this一>ID=ID: CourseNum=courseNum: Record=record; } int main() { Studentlnfo st(’’Smith”,21,99999,12,970); st.show(); return 0; } 查看解析 → 2 请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 80 150 100 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 #include<iostream.h> class vehicle { private: int MaxSpeed; int Weight; public: //*************found************ vehicle(int maxspeed,int weight):—— ~vehicle(){}; int getMaxSpeed(){return MaxSpeed;} int getWeight(){retum Weight;} }; //****************found************ class bicycle:——public vehicle { private: int Height; public: bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){} int getHeight(){retum Height;}; }; //*******************found************** class motorcar:——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: motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight, height),motorcar(maxspeed,weight,1){} }; void main() { motorcycle a(80,150,100); cout<<a.getMaxSpeed()<<endl; cout<<a.getWeight()<<endl; cout<<a.getHeight()<<endl; cout<<a.getSeatNum()<<endl; } 查看解析 → 3 请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的CDeepCopy是一个用于表示矩阵的类。请编写这个类的赋值运算符成员函数0perator=,以实现深层复制。 要求: 补充编制的内容写在“//************333************”与“//****************666*************”之间。不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。 //CDeepCopy.h #include <iostream> #include<string> using namespace std; class CDeepCopy { public: int n;//动态数组的元素个数 int *p;//动态数组首地址 CDeepCopy(int); ~CDeepCopy(); CDeepCopy&operator=(const CDeepCopy&r);//赋值运算符函数 }; void writeToFile(char}); //main.cpp #include”CDeepCopy.h” CDeepCopy::一CDeepCopy(){delete[]P;} CDeepCopy::CDeepCopy(int k){n=k;p=new int[n];}//构造函数实现 CDeepCopy&CDeepCopy::0perator=(const CDeepCopy&r)//赋值运算符函数实现 { //***********333********* //***********666*********** } int main() { CDeepCopy a(2),d(3); a.p[O]=1;d.p[O]=666;//对象a,d数组元素的赋值 { CDeepCopy b(3);//调用赋值运算符函数 a.p[O]=88;b=a; cout<<b.p[O];//显示内层局部对象的数组元素 } cout<<d.p[O];//显示d数组元素a.p[O]的值 cout<<”d fade away;\n”; cout<<a.p[O];//显示a数组元素a.p[O]的值 writeToFile(””); return 0; } 查看解析 →