下载此文档

C++程序设计-参考答案刘振安.doc


文档分类:IT计算机 | 页数:约51页 举报非法文档有奖
1/51
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/51 下载此文档
文档列表 文档介绍
第一章
一、选择题
; (typedef ,typeid ,typename,都为保留字);
; (标识符,应该以字母或,下划线开头);
; (标识符中有的特殊符号,只能有下划线);
二、填空题
1. cin,cout
2. new,delete
3. new int (55);
三、改错题
;
,声明指向常量的指针const int *p=&x; 如果吧x定义为常量const,*p不能当作“左值”。
,不能吧p作为“左值”,p=&y,错误。
四、编程题
1. 分别用字符和ASCII码形式输出整数值65和66.
#include < iostream >
using namespace std;
void main()
{
int ascii_1=65,ascii_2=66;//ASCII码中的,65和66
cout<<"字符输出:"<<(char)ascii_1<<","<<(char)ascii_2<< endl;
cout<<"ASCII码输出:"<<ascii_1<<","<<ascii_2<< endl;
}

#include < iostream >
using namespace std;
void main()
{
int *p;
p = new int[100];

for(int i = 0;i < 100;i++)
{
*(p+i)=i;
}

for(i = 0;i < 100;i++)
{
cout<<*(p+i)<<" ";
}

delete []p;
}
,它读入15个float值,用指针把它们存放在一个存储快里,然后输出这些值和以及最小值。
#include < iostream >
#include < algorithm > //用于数组排列的头文件
using namespace std;
void main()
{
float *p;
p = new float[15];
cout<<"输入15个float类型的值:" << endl;
for(int i = 0;i < 15 ; i++)
{
// cin>>*(p+i);
*(p+i)=i;
}

sort(p,p+15);
int sum=0;
for(i = 0;i < 15;i++)
{
cout<<*(p+i)<<",";
sum += *(p+i);
}
cout<<endl;
cout<<"和是:"<<sum<< endl;
cout<<"最小的是:"<<*(p)<< endl;
delete []p;
}
:
int a[] = {1 ,2 ,3, 4, 5, 6, 7, 8};
先查找4的位置,讲数组a复制给数组b,然后将数组a的内容反转,再查找4的位置,最后分别输出数组a和b的内容。
#include < iostream>
#include < algorithm>
#include < functional>
using namespace std;
void main()
{
int a[]={1,2,3,4,5,6,7,8},b[8];
cout<<"数组a中'4'的位置是:"<< find(a,a+8,4)<< endl;//查找4的位置

copy(a,a+8,b);//将数组a复制给数组b

reverse_copy(b,b+8,a);//把数组b,逆向复制给a,完成a的逆转

cout<<"数组a反转后,'4'的位置是:"<< find(a,a+8,4)<< endl;//在查找4的位置


cout<<"数组a的内容:"<< endl;
copy(a,a+8,ostream_iterator<int>(cout," "));

cout<<"\n数组b中的内容:"<< endl;
copy(b,b+8,ostream_iterator<int>(cout," "));
}
第二章参考答案
一、选择题


二、作图题
1. 已知一个学生类具有性别和年龄两个属性,男学生张明的年龄为12岁,女学生李红的年龄为11岁。给出这个学生类的类图和它们的对象图。
类图
Student
string sex;
int a

C++程序设计-参考答案刘振安 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数51
  • 收藏数0 收藏
  • 顶次数0
  • 上传人zhongxinado
  • 文件大小157 KB
  • 时间2018-08-18