- 1、本文档共15页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
课后习题
认识C++的对象
单项选择题
下列选项中不是C++语言关键字的是(B) A、typedef B、mycase C、typeid D、typename
下列选项中不是C++语言合法标识符的是(C) A、area B、_age C、-xy D、w123
下列选项中正确的标识符是(C) A、case B、de。fault C、c_ase D、a. b
填空题
来处理标准输入的是 cin ,用来处理屏幕输出的是 cout 。
动态分配内存使用关键字 new ,释放内存使用关键字 delete 。
为整数55分配一块内存的语句为 int a = 55; 。
改错题
分析如下主程序中的错误。
void main( ){
int ref=num;
ref=ref+100;
num=num+50;
}
分析如下主程序中的错误。
void main( ){
int x=58,y=98;
int* const p=x;
*p=65;
p=y;
}
分析如下主程序中的错误。
void main( ){
int x=58,y=98,z=55;
int* const p=x;
*p=65;
p=y;
z=*p;
}
编程题
分别用字符和ACSII码形式输出整数值65和66。
编写一个为int型变量分配100个整形量空间的程序。
编写完整的程序,它读入15个float值,用指针把它们存在一个存储块里,然后输出这些值的和以及最小值。
声明如下数组: int a[ ]={1,2,3,4,5,6,7,8};
先查找4的位置,将数组a复制给数组b,然后将数组a的内容反转,再查找4的位置,最后分别输出数组a和b的内容。
答案:
#include iostream
#include iomanip
#include algorithm
#include ctype.h
using namespace std ;
typedef int array[100];
float max(float,float);
void main(){
//改错一
int num=0;
int ref=num;
ref=ref+100;
num=num+50;
//改错二
int abc=58,abd=98;
int* const p3=abc;
*p3=65;
//p3=abd;
//编程一
char x = 65;
char y = 66;
cout character 65= x character 66= y endl ;
cout Ascii 65= \65 Ascii 66= \66 endl ;
//二
int *p1 = new int[100];
//三
//float three[15]={0};
float *p ;
p = new float[15];
float sum_value = 0.0f;
float max_value = 0.02f;
for (int i=0;i15;i++){
cout please type the i+1 st Number: ;
cin *(p+i);
sum_value = sum_value + *(p+i);
max_value = max(max_value,*(p+i));
}
cout The Sum value = sum_value endl;
cout The Max value = max_value endl;
//编程四
int a[]={1,2,3,4,5,6,7,8},b[8];
int *z = find(a,a+8,4);
cout the 4 memory address of array a is : z , its position is : a[*z] endl;
copy(a,a+8,b);
reverse(a,a+8);
z = find(a,a+8,4);
cout the 4 memory address of reverse array a is : z , its position is : a[*z] endl;
cout the array a is :;
copy(a,a+8,ostream_iteratorint(cout, ));
cout endl;
cout the array b is :;
copy(b,b+8,ostream_iteratorint(cout, ));
文档评论(0)