一起答
主观

#include ﹤iostream.h﹥

main( ) {

int x=5, y=6;

const int *p=&x;

*p=y;

cout﹤﹤*p﹤﹤endl;

}

试题出自试卷《自考C++程序设计2014年10月试题及答案解析》
参考答案
查看试卷详情
相关试题
  1. 定义堆栈类模板Stack(先进后出),栈的大小由使用者确定。要求该类模板对外提供如下二种基本操作:

    (1)push入找

    (2)pop出栈,用数组来实现

    #include ﹤iostream﹥

    using namespace std;

    template﹤class T, int size﹥

    class Stack {

    T x[size];

    int current;

    public:

    Stack( ) { current =0; }

    ....push(....);

    ....pop(....);

    }

    请写出两个函数的过程(如果需要形式参数,请给出形参类型和数量,以及返回值类型)

  2. 给出下面程序的输出结果

    #include ﹤iostream﹥

    using namespace std;

    class Simple

    {

    int x, y;

    public:

    Simple( ) { x=y=0; }

    Simple( int i, int j) { x=i; y =j; }

    void copy( Simple &s);

    void setxy { int i, int j) { x=i; y=j; }

    void print( ) { cout ﹤﹤"x="﹤﹤x﹤﹤",y="﹤﹤y ﹤﹤ endl; }

    };

    void Simple:: copy( Simple &s)

    {

    x=s.x; y=s.y;

    }

    void func ( Simple s1, Simple &s2)

    {

    s1. setxy(30, 40);

    s2. setxy(70, 80);

    }

    vpid main( )

    {

    Simple obj1(1, 2), obj2;

    obj2. copy(obj1);

    func(obj1, obj2);

    obj1. print( );

    obj2. print( );

    }

  3. 请写出myText1. txt文本文件中的内容

    #include ﹤iostream﹥

    #include ﹤string﹥

    using namespace std;

    #include ﹤fstream﹥

    void main( )

    {

    ofstream myFile1;

    myFile1. open("myText1. txt");

    cout﹤﹤"Enter the data in Chinese format(e. g. , 2008, May 25): "﹤ endl;  string Date("2008, January 1");

    string Year=Date. substr(0,4);

    int k=Date. find( ",");

    int i= Date. find(" ");

    string Month= Date. substr(k+1, i-k-1);

    tring Day = Date. substr(i+1, 2);

    string NewDate=Day +" "+Month+" "+Year;

    myFile1﹤﹤"original date: "﹤﹤ Date ﹤﹤ endl;

    myFile1﹤﹤"Converted date: "﹤﹤NewDate ﹤﹤ endl;

    myFile1. close( );

    }

  4. 在下面下划线处填上正确的语句使序输出结果为  201  402  3  4  5

    #include ﹤iostream﹥

    using namespace std;

    template ﹤class T﹥

    T f(T &a, T &b, int n) {

    for(int i=0; i﹤n; i++) {

    a[i]=a[i]+b[i];

    }

    return a;

    }

    void main( ) {

    int a[5]={1,2,3,4,5};

    int b[5]={100,200,300,400,500}, *p;

    for(int i=0; i﹤2; i++) {

    p=_________;

    }

    for( ; p﹤a+5; p++){

    cout ﹤﹤_________﹤﹤endl;

    }

    }

  5. 完成下面类的定义,使其可以正确的初始化成员变量m和n:

    class point {

    private: int m, n;

    public:

    point( int, int);

    point(point &t);

    };

    point:: point(int a, int b) {

    m=a;  _________=b;

    }

    point:: point( _________ ) {

    m=t. m;

    n=t. n;

    }

  6. 在下面横线处填上适当的语句完成类的定义。

    #include ﹤iostream﹥

    using namespace std;

    class Base {

    int x;

    static const int b;

    public:

    Base (int, int);

    const int *a;

    };

    _________ b=15;

    Base:: Base( int i, int j): _________ { }

  7. 输入一个字符串,将其逆序输出:

    #include ﹤iostream﹥

    using namespace std;

    void main( ) {

    char a[50];

    memset(a, 0, sizeof(a));

    int i=0, j;

    char t;

    cin. getline( a, 50, '\n');

    for(i=0, j=_________; i﹤_________; i++, j--) {

    t=a[i];

    a[i]=a[j];

    a[j]=t;

    }

    cout ﹤﹤a﹤﹤ endl;

    }

  8. 程序的输出结果如下:

    Parent:: Parent( ) called.

    Child:: Child( ) called.

    Child:: ~Called( ) called.

    Parent:: ~Parent( ) called.

    根据输出结果在下面程序中的下划线出填写正确的语句

    include ﹤iostream﹥

    using namespace std;

    class Parent

    {

    public:

    Parent( ) { cout ﹤﹤"Parent:: Parent( ) called. \n"; }

    vintual ~Parent( ) { cout ﹤﹤"Parent:: ~Parent( ) called. \n"; }

    }:

    class Child: public Parent

    {

    public:

    Child(int i) {

    cout﹤﹤"Child:: Child( ) called. \n";

    buf=new char[i];

    }

    virtual ~Child( ) {

    delete [ ]buf;

    cout﹤﹤"Child:: ~Child( ) called. \n";

    }

    private:

    char * buf;

    };

    void disp( _________ *a)

    {

    _________;

    }

    woid main( )

    {

    Parent *a=new Child(20);

    disp(a);

    int d;

    cin ﹥﹥d;

    }

  9. #include ﹤iostream.h﹥

    main( ) {

    int x=5, y=6;

    const int *p=&x;

    *p=y;

    cout﹤﹤*p﹤﹤endl;

    }

  10. #include ﹤iostream﹥

    using namespace std;

    main( ) {

    int num;

    max=10;

    num=1;

    while( num﹤max) num++;

    cout ﹤﹤"num="﹤﹤num;

    }