云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 全国计算机技术与软件专业技术资格(初级程序员2008下半年下午试题)

全国计算机技术与软件专业技术资格(初级程序员2008下半年下午试题)

  • 62 次阅读
  • 3 次下载
  • 2025/5/6 19:20:09

【说明】

C++标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空间为std。vector模板类的部分方法说明如下表所示:

方 法 push_back(k) begin() end() empty() erase(ptr) 含 义 向vector对象的尾部添加一个元素k 返回一个迭代器对象,该对象指向vector中的第一个元素 返回一个迭代器对象,该对象指向vector中的最后一个元素 测试vector对象是否为空 删除vector中ptr指向的元素 【C++代码】

#include <iostream> #include <vector>

using namespace (1) ; typedef vector< (2) > INTVECTOR; const int ARRAY_SIZE = 6;

void ShowVector (INTVECTOR &theVector); int main() {

INTVECTOR theVector;

// 初始化 theVector, 将theVector的元素依次设置为0至5

for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++} theVector.push_back( (3) ); ShowVector(theVector); // 依次输出theVector中的元素 theVector.erase (theVector.begin () + 3}; ShowVector(theVector); }

void ShowVector (INTVECTOR &theVector) { if (theVector.empty ()) {

cout << \<< endl; return; }

INTVECTOR::iterator (4) ;

for (theIterator=theVector.begin(); theIterator !=theVector.end(); theIterator++) { cout << *theIterator;

if (theIterator != theVector.end()-1) cout << \ }

cout << end1; }

该程序运行后的输出结果为: 0,1,2,3,4,5 (5) 试题六

阅读以下说明和Java代码,将应填入 (n) 处的字句写在对应栏内。 【说明】

java.util库中提供了Vector模板类,可作为动态数组使用,并可容纳任意数据类型。该类的部分方法说明如下表所示:

方法名 5

含 义

add(k) removeElementAt(i) isEmpty() size() 向vector对象的尾部添加一个元素k 删除序号为i的元素(vector元素序号从0开始) 判断vector对象是否含有元素 返回vector对象中所包含的元素个数 【Java代码】

import (1) ;

public class JavaMain {

static private final int (2) = 6;

public static void main(String[] args){

Vector<Integer> theVector = new Vector< (3) >(); // 初始化 theVector, 将theVector的元素设置为0至5

for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++) theVector.add( (4) );

showVector(theVector); // 依次输出theVector中的元素 theVector.removeElementAt(3); showVector(theVector); }

public static void showVector(Vector<Integer> theVector if (theVector.isEmpty()) {

System.out.println(\ return; }

for (int loop = 0; loop < theVector.size(); loop++) System.out.print(theVector.get(loop)); System.out.print(\ }

System.out.println(); } }

该程序运行后的输出结果为: 0,1,2,3,4,5 (5)

6

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

【说明】 C++标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空间为std。vector模板类的部分方法说明如下表所示: 方 法 push_back(k) begin() end() empty() erase(ptr) 含 义 向vector对象的尾部添加一个元素k 返回一个迭代器对象,该对象指向vector中的第一个元素 返回一个迭代器对象,该对象指向vector中的最后一个元素 测试vector对象是否为空 删除vector中ptr指向的元素 【C++代码】 #include <iostream> #include <vector> using namespace (1) ; typedef vector< (2)

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com