C++课后习题(黄荷修改).docVIP

  • 140
  • 0
  • 约1.59万字
  • 约 15页
  • 2017-08-03 发布于河南
  • 举报
课后习题 认识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)

1亿VIP精品文档

相关文档