教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 专业资料 >

高级语言程序设计(C++II)练习题(2)

来源:网络收集 时间:2026-09-15
导读: (每小题3分,共9分) #includeiostream.h void main() { int j=1,k=3; coutint 数据类型:\nj,k=; swap(j,k); coutj,kendl; double x=1.23,y=9.87; coutdouble数据类型: \nx,y=; swap(x,y); coutx,yendl; 第 5 页

(每小题3分,共9分)

#include<iostream.h>

void main()

{ int j=1,k=3;

cout<<"int 数据类型:\n"<<j<<","<<k<<"=>"; swap(j,k); cout<<j<<","<<k<<endl; double x=1.23,y=9.87;

cout<<"double数据类型: \n"<<x<<","<<y<<"=>"; swap(x,y); cout<<x<<","<<y<<endl;

第 5 页 共 6 页

C++辅导资料

《C++Ⅱ》试卷 (№ A03Ⅱa)

char p='A',q='B';

cout<<"char 数据类型:\n"<<p<<","<<q<<"=>"; swap(p,q); cout<<p<<","<<q<<endl ; }

2.下列程序使用了向量vector和算法sort实现数组的排序,请把有关的语句填充完整。 (每小题3分,共9分)

#include<iostream>

#include<vector>

#include<algorithm>

const int size=10;

void display(vector<int>V,int n)

bool down(int x,int y)

void main( )

{ int a[size]={10,3,17,6,15,8,13,34,25,2};

vector<int>V(a,a+size); // 用数组对模板向量赋初值

cout<<"输出原始数组: \n";

display(V,size);

sort(V.begin( ),V.end( )); // 对向量按升序排序

cout<<"输出升序排列后的数组: \n" ;

display(V,size);

sort(V.begin( ),V.end( ),down); // 对向量按降序排序

cout<<"输出降序排列后的数组: \n" ;

display(V,size);

}

四、给出一个输入输出流操作的程序段,请把有关的语句填充完整。 (每小题3分,共6分)

#include <iostream.h>

#include <fstream.h>

#include <stdlib.h>

void main( )

{ ofstream outstuf ; // 建立输出文件流对象

if(!outstuf){cerr<<"error!"<<endl;abort( );} // 调用重载算符函数测试流

outstuf<<"This is a file of example.\n"; // 写入一行内容

;

}

第 6 页 共 6 页

高级语言程序设计(C++II)练习题(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/265233.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)