第十章单元测试
  1. C++语言中模板分为函数模板和类模板两种。 ( )

  2. A:错 B:对
    答案:对
  3. template <typename T>则T在函数模板中 ( )

  4. A:可以作为返回类型、参数类型或函数中的变量类型 B:只能作为函数参数类型 C:只能作为函数返回类型 D:只能用于函数中的变量类型
  5. 关于类模板描述不正确的是( )

  6. A:它可以使类中的某些数据取任意类型 B:根据它可以定义多个对象 C:根据它可以产生一系列类 D:它的存在不代表一个具体的、实际的类,而是代表一类的类
  7. vector 容器的成员函数empty()表示移出所有的元素。( )

  8. A:错 B:对
  9. 利用vector<int> vec;创建vector对象后,调用语句vec.erase(vec.begin()+2) ; 则删除vec的第3个元素。( )

  10. A:对 B:错
  11. #include <stdio.h>
    template <typename T>
    T add(T a, T b) {
    return a+b;
    }
    void main(){
    printf("%d", add<int>(1, 3));
    }
    Output? ( )

  12. A:4 B:Error C:0
  13. A generic function that can be used for different data type is a ( )

  14. A:None of the above B:Object template C:Class template D:Function template
  15. What are Iterators? ( )

  16. A:STL component used to call functions efficiently B:STL component used to point a memory address of a container C:STL component used for vectors D:STL component used to define template classes
  17. Which of the following C++ statements adds a new element to the end of the vector Scores? ( )

  18. A:Scores.push_back(score); B:Scores.push(score); C:Scores.begin(score); D:Scores.at(score);
  19. #include <stdio.h>
    #include <vector>
    using namespace std;
    void main()
    {
    vector<char>value;
    value.push_back('S');
    value.push_back('T');
    value.push_back('L');
    printf("%d ", value.size());
    }
    Output? ( )

  20. A:0 B:1 C:STL D:3

温馨提示支付 ¥3.00 元后可查看付费内容,请先翻页预览!
点赞(2) dxwkbang
返回
顶部