更多“使用标准命名空间的语句是()A、using namespace std;B、using namespace iostream;C、include std;D、include iostream;”相关问题
  • 第1题:

    以下程序的执行结果为______。include using namespace std; class base { public: vir

    以下程序的执行结果为______。

    include<iostream>

    using namespace std;

    class base

    public:

    virtual void who()

    cout<<"base class"<<endl;

    };

    class derivel:public base

    public:

    void who()

    cout<<"d


    正确答案:base class derivel class derive2 class
    base class derivel class derive2 class

  • 第2题:

    下列程序的输出结果是______。 include using namespace std; void fun(int &rf) {

    下列程序的输出结果是______。

    include<iostream>

    using namespace std;

    void fun(int &rf)

    {

    rf*=2;

    }

    int main()

    {

    int num=500;

    fun(num);

    cout<<num<<endl;

    return 0;

    }


    正确答案:1000
    1000 解析:本题考核引用作为函数参数的使用。引用作为形参时,它实际上就是实参,函数对形参的访问和修改就是对实参的访问和修改,题中函数fun对形参的操作是自增2倍,所以经过函数调用后,实参的值自增2倍,即输出1000。

  • 第3题:

    下列程序的输出结果是______。 include using namespace std; int main() {int data=l;

    下列程序的输出结果是______。

    include<iostream>

    using namespace std;

    int main()

    {

    int data=l;

    int &r = data;

    data+=5;

    r+=5;

    cout<<data<<endl;

    return 0;

    }


    正确答案:11
    11 解析:本题考核引用的概念和使用。C++的引用是一种赋值、发送和返回复杂数据结构的方法,应用这种方法,系统不需要负担额外的开销,节省内存空间。在程序中对引用的存取都是对它所引用的变量的存取。题中r为data的引用,所以对r的操作等于对data的操作,所以最后 data的值为11。

  • 第4题:

    关于语句 include using namespace std; void main( ) { cout < < 100.8989663 <

    关于语句 #include<iostream> using namespace std; void main( ) { cout < < 100.8989663 < < '; cout < < fixed < < 100.8989663 < <'; cout < < scientific < < 100.8989663 < <';} 的输出结果为

    A.100.899 100.898966 1.008990e+002

    B.100.8989663 100.898966 1.008990e+002

    C.100.899 100.898966 1.008989e+002

    D.100.899 100.8989663 1.008989e+002


    正确答案:A
    解析:C++语言中默认小数的输出位一共是六位,fixed的意义是在小数点后保留六位,scientific的意义是以科学计数法输出小数,本题中,100.8989663的默认输出就是100.899,fixed输出是100,898966,scienlific输出是1.008990e+002。注意:C++语言中的小数输出及各种控制方法。

  • 第5题:

    下列程序的输出结果是【】。 include include using namespace std; void fun(c

    下列程序的输出结果是【 】。

    include<iostream>

    include<cstring>

    using namespace std;

    void fun(const char *s,char &c){c=s[strlen(s)/2];}

    int main()

    {

    char str[]="ABCDE";

    char ch=str[1];

    fun(str,ch);

    cout<<ch;

    return 0;

    }


    正确答案:C
    C

  • 第6题:

    有如下程序:include using namespace std;class AA{public: virtual void f() {cout<

    有如下程序: #include <iostream> using namespace std; class AA { public: virtual void f() { cout<< "AA"; } }; class BB : public AA { public: BB() { cout << "BB"; } }; cla

    A.AA

    B.AABBCC

    C.BBAABBCC

    D.BBBBAACC


    正确答案:D
    解析:本题中,函数f()在基类AA中派生类CC中都声明为虚函数,所以采用动态联编。主函数首先定义类AA的对象aa和指针对象p,然后定义了类BB的对象bb,此时调用了类BB的构造函数输出BB。再定义类CC的对象cc,由于类CC是类BB的派生类,所以此时又调用类BB的构造函数输出BB。最后执行语句“p=&cc; p->f();”,输出AA和CC。

  • 第7题:

    有以下程序:include include using namespace std;int main ( ){ ofstream

    有以下程序: #include <iostream> #include <fstream> using namespace std; int main ( ) { ofstream ofile; char ch; ofile.open ("abc.txt"); cin>>ch; while (ch!='#' ) { cin>>ch; ofile.put(ch);

    A.程序编译时出错

    B.abc#

    C.abc

    D.#


    正确答案:C
    解析:本题程序的功能是将从键盘终端输入的内容存储到指定的文件中。

  • 第8题:

    以下程序的运行结果是【】。 include include using namespace std; void main()

    以下程序的运行结果是【 】。

    include<iostream>

    include<string>

    using namespace std;

    void main(){

    chara[10]="China",b[]="Chin",c[]="ese";

    cout<<strlen(strcat(strcpy(a,b),c))<<endl;

    }


    正确答案:7
    7 解析:本题主要考查C++中字符串函数的使用。strcpy(s1,s2)将s2的内容赋值到s1中; strcat(s1,s2)连接s1和s2两个字符串;strlen(s)返回字符数组s的长度。因此最后输出的结果是b和c进行连接后的字符串长度,即7。

  • 第9题:

    有如下程序: include include using namespace std; int main() {cout.f

    有如下程序: #include <iostream> #include <iomanip> using namespace std; int main() { cout.fill('*'); cout.width(6); cout.fill('#'); cout<<123<<end1; return 0; } 执行生的输出结果是( )。

    A. ###123

    B.123###

    C. ***123

    D.123***


    正确答案:A

  • 第10题:

    下列程序的运行结果为()。include using namespace std;namespace m {int flag = 10;}

    下列程序的运行结果为( )。 #include <iostream> using namespace std; namespace m { int flag = 10; } namespace n { flag = 100; } void mian( ) { int flag = 0; using namespace n; cout<<flag<<","<<m:: flag; }

    A.100,10

    B.100,0

    C.0,100

    D.0,10


    正确答案:D
    解析:contflag;输出的是main()中的flag值0,而m::flag=10。

  • 第11题:

    请在下列程序的横线处填写正确的语句。include using namespace std; class Base{ publ

    请在下列程序的横线处填写正确的语句。

    include<iostream>

    using namespace std;

    class Base{

    public:

    void fun(){cout<<"Base fun"<<endl;}

    };

    class Derivde:public Base{

    public:

    void fun(){

    ______∥ 调用基类的函数


    正确答案:Base∷fun()
    Base∷fun() 解析: 此题考查的是派生类对基类成员的访问。本题中派生类Derived覆盖了基类Base中的fun(),如果需要调用基类中的fun(),则需要使用域运算符“∷”。故应填写Base∷fun()。

  • 第12题:

    单选题
    使用标准命名空间的语句是()
    A

    using namespace std;

    B

    using namespace iostream;

    C

    include std;

    D

    include iostream;


    正确答案: C
    解析: 暂无解析

  • 第13题:

    下列程序的执行结果是______。 include include using namespace std; vo

    下列程序的执行结果是______。

    include<iostream.h>

    include<iomanip.h>

    using namespace std;

    voidmain()

    {

    cout<<setfill('x')<<setw(10);

    cout<<"Hello"<<end1;

    }


    正确答案:xxxxxHello
    xxxxxHello 解析:此题考查的是I/O的格式化输出。Setfill('x')表示填充字符为V,并且一直有效;setw(10)表示将输入输出的宽度设置为10,宽度设置的效果只对以此次输入或输出有效,在完成一个数据的输入或输出后,宽度自动恢复为0;题目中字符串“Hello”的宽度不够10,所以其前面将有5个填充符V。

  • 第14题:

    下面程序运行输出的结果是【】。 include using namespace std; int main(){char a[]="C

    下面程序运行输出的结果是【 】。

    include <iostream>

    using namespace std;

    int main(){

    char a[]="Chinese";

    a[3]='\0';

    cout<<a<<endl;

    return 0;

    }


    正确答案:Chi
    Chi 解析:字符串的结束标识是'\0',输出字符串时,到第一个'\0'输出结束,而不管其后是否还有数据,因此本题输出为字符中的前3个字符。

  • 第15题:

    下面程序的执行结果是【】。 include include using namespace std; void main(

    下面程序的执行结果是【 】。

    include<iostream>

    include<iomanip>

    using namespace std;

    void main()

    {

    cout<<setfill('x')<<setw(10);

    cout<<"Hello"<<endl;

    }


    正确答案:xxxxxHello
    xxxxxHello

  • 第16题:

    下面程序的运行结果为( )。include using namespace std;void main( ) { for(int a =0

    下面程序的运行结果为( )。 #include <iostream> using namespace std; void main( ) { for(int a =0,x =0; !x&&a < =10; a ++ ); cout << a << endl;

    A.0

    B.1

    C.10

    D.11


    正确答案:D
    解析:当i=11时,循环结束。

  • 第17题:

    有如下的程序: include using namespace std; class AT{friend ostream & operato

    有如下的程序:

    include<iostream>

    using namespace std;

    class AT{

    friend ostream & operator<<(ostream&,AT);

    }at;

    ostream& operator<<(ostream& os,AT){return os<<'@';}

    int main(){

    cout<<"MyHome"<<at<<"isHere.com";

    }

    执行上面的程序将输出


    正确答案:Myhome@is Here.com
    Myhome@is Here.com

  • 第18题:

    有以下程序:include include using namespace std;class base{private: cha

    有以下程序: #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base ( ) { strcpy (baseName, "Base"); } virtual char *myName() {

    A.DerivedBase

    B.BaseBase

    C.DerivedDerived

    D.BaseDerived


    正确答案:A
    解析:本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此,Derived是基类Base的子类型。主函数中定义了一个基类对象bb和一个派生类对象dd。从程序中可看出,派生类Derived的对象dd交给了处理基类Base的对象的函数showPtr进行处理。由于在基类中函数myName被定义成虚函数,所以在函数showPtr中调用的myName函数为派生类的成员函数mySame,从而输出Derived。然后输出className,即基类名称Base。

  • 第19题:

    下面程序的运行结果为( )。 include using namespace std; class A{ pu

    下面程序的运行结果为( )。 #include <iostream> using namespace std; class A{ public: A(){cout<<" ";} ~A(){cout<<" ";} } class B:public A{ public: B(){cout<<" ";} ~B(){cout<<" ";} } void main(){ B b; }

    A.1234

    B.1324

    C.1342

    D.3142


    正确答案:C
    解析:构造函数和析构函数系统可以自动调用。先执行其基类构造函数,输出1;执行派生类的构造函数,输出3;执行派生类析构函数,输出4;执行基类析构函数,输出2。

  • 第20题:

    有如下程序: include include using namespace std; int ma

    有如下程序: #include <iostream> #include <iomanip> using namespace std; int main() { cout.fill('*'); cout << left << setw(4) << 123 << "OK" << endl; return 0; }

    A.123*OK

    B.123*OK**

    C.*123OK

    D.*123**OK


    正确答案:A
    解析:本题考查了输出流的格式控制。cout的fill()方法的作用是设置填充字符,若输出数据宽度小于设置宽度,则空闲位置用填充字符填满。left和endl是C++预定义的用于格式控制的符号常量,前者使输出数据在指定宽度内左对齐,后者使输出换行。setw()函数的作用是设置输入输出宽度,不过宽度设置的效果只对一次输入或输出有效,在完成了一个数据的输入或输出后,宽度设置自动恢复为0(表示按数据实际宽度输入输出)。所以在本题中,输出整数123时宽度为4且左对齐,空出最后一位填入填充字符'*',结果是123*:输出字符串"OK"时宽度自动恢复为0,结果是OK。故程序的输出结果是123*OK,应该选择A。

  • 第21题:

    下面的程序输出的结果是( )。 include using namespace std; void main(){

    下面的程序输出的结果是( )。 #include <iostream> using namespace std; void main(){ int a=2; int &c=a; a++; cout<<c; }

    A.2

    B.3

    C.4

    D.*a


    正确答案:B
    解析:c是a的引用,故a++相当于c++。

  • 第22题:

    请在如下程序中的空格处填写正确的语句: include using namespace std; class Base {

    请在如下程序中的空格处填写正确的语句:

    include <iostream>

    using namespace std;

    class Base {

    public:

    void fun() {cout<<"Base fun"<<endl; }

    };

    class Derived: public Base {

    public:

    void fun() {

    【 】; //调用基类的函数fun()

    cout<<"Derived fun "<<endl;

    }

    };


    正确答案:Base::fun()
    Base::fun() 解析:本题考查的知识点是:派生类对基类成员的访问。本题的派生类Derived覆盖了基类Base中的fun(),如需调用基类版本的fun(),则需要使用域运算符“::”。故应该填写Base::fun()。

  • 第23题:

    在下面横线上填上适当的语句,完成程序。include using namespace std; class Base { in

    在下面横线上填上适当的语句,完成程序。

    include<iostream>

    using namespace std;

    class Base

    {

    int x;

    public:

    Base(int i){x=i;}

    ~Base(){}

    );

    class Derived:public Base

    {

    public:

    ______//完成类Derive构造函数的定义

    };

    iht main()

    {

    Derived obj


    正确答案:Derived(int i;Base(i){}。
    Derived(int i;Base(i){}。 解析: 程序中,类Derived是基类Base的公有派生。在类Derived的构造函数应该包括调用基类构造函数使基类的数据成员得以初始化,