期中考试编程题答案 (1).docx
第1题 矩形类及期成员函数的实现
#include
#include
using namespace std ;
class CPoint
{
int x;
int y;
public :
CPoint (int ptX =0, int ptY =0): x (ptX ), y(ptY )
{
}
friend class CRectangle;
};
2015-2016学年 第2学期《面向对象程序设计》课程期中考试编程题.docx
标题: 1.设计改进的数组Vector
描述: 设计一个改进的数组,即向量Vector类,使得它可以通过如下main函数中代码的测试.
int main()
{
int i;
int seed;//随机数种子
int len;//数组长度
cin>>seed;
srand(seed);
len=1+rand()P0;
Vector v1(len); //构造向量
for(i=0;i<v1.Length();i++)
{
v1[i]=10+rand()0;//给向量中的元素赋值
}
Vector v2(v1);//用向量v1初始化向量v2
len=1+rand()P0;
int ary[len];
for(i=0;i<len;i++)
{
ary[i]=10+rand()0;
}
Vector v3(ary,ary+len);//基于数组构造向量
cout<<v3<<endl;//输出流运算符重载
if(v1.Length()==v2.Length())
{
v3=v1+v2;//加法运算符重载
}
cout<<v3<<endl;
}
输入: 随机数种子
输出: 向量v3
输入样例: 2
输出样例: 69 48 108 94 87 50 96 79 28 17 69 69 27 12 62 91 102 50 22 106 73 34 37 39 107 33 23 68 75 68 26 70 95 105 91 14 14 104 39 94 48 23 64 27 75 81 69 25 23 78 98 62 77 36 107 23 99 11 64 67 66 107 41 69 25 62 31 89 13 37 39 66 58 12 85 50 62 72 91 93
52 216 210 188 120 200 82 30 52 134 198 124 32 126 78 46 154 136 142 98 190 54 154 210 100 144 68 42 44 116 210 24 198 218 196 66 44 48 62 168 172 128 44 118 44 162
c++面向对象程序设计第二版教材代码.rar
c++学好的关键在于勤练习,多看书,许多东西多源于课本,此次分享c++面向对象程序设计第二版教材答案供大家参考,希望大家都能学好c++这门语言。
c语言程序设计第十二章课后题答案.zip
c语言程序设计第十二章课后题答案,附加课后习题代码
Suppose that the following declarations are in effect:
int a[] = {5, 15, 34, 54, 14, 2, 52, 72};
int *p = &a[1], *q = &a[5];
(a) What is the value of *(p + 3)? 14
(b) What is the value of *(q - 3)? 34
(c) What is the value of q - p? 4
(d) Is the condition p < q true or false? true
(e) Is the condition *p < *q true or false? false