第一范文网 - 专业文章范例文档资料分享平台

自考c++程序设计 参考

来源:用户分享 时间:2025/7/23 7:49:32 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

T sum (T a[], int n) { int i; T s=0;

for(i=0;i< n;i++) s = s + a[i]; return s; }

template //重载上面的模板

T sum (T a[], int n, T b[], int m) {

return sum(a,n)+sum(b,m); } void main () {

int a[5]={1,2,3,4,5};

int b[10]={1,2,3,4,5,6,7,8,9,10}; int s1 = sum(a, 5); int s2 = sum(b, 10); int s3= sum(a, 5, b, 10); cout<< s1<< endl; cout<< s2<< endl; cout<< s3<< endl; }

[color=#EE1111]第四章[/color] 一、填空题

1.数据成员、成员函数; 2.类、重载、1;

3.fun:fun(fun &)、fun:fun(const fun &); 二、单项选择题

1.C。2.C。3.没又答案,应该是A::~A(void)、或A::~A()。4.B。 5.C。 6.C。 7.D

三、改错题

1.return m;---错误,没又定义变量m;

2.A.init(24,56);---错误,应该先定义A对象:Point A; 四、完成程序题 1.

#include < iostream > using namespace std; class base {

private : //私有数据成员 int a, b; public :

void init(int x, int y)//公有函数 { a = x; b = y; }

void print() {

cout<<\

} };

void main() { base a; a.init(68,55); a.print(); } 2. #include

using namespace std; class Point { private : int m, n; public :

Point(int, int);//整型变量,为参数的构造函数 Point(Point&);//复制构造函数的原型 print() {

cout<<\} };

Point::Point(int a, int b) {

m = a; n = b; }

Point::Point(Point & t)//复制构造函数的定义 { m = t.m; n = t.n; }

void main() {

Point a(10,89); Point b(a); a.print(); b.print(); }

五、程序分析题

1.没有结果,因为没有main函数 如果加main函数 void main() {

base b(10, 20); } 输出:

初始化...10,20 Destory...10,20 2.

输出: 55 六、编程题

1.设计一个点类Point,再设计一个矩形类,矩形类使用Point类的两个坐标点作为矩形的对

角顶点。并可以输出4个坐标值和面积。使用测试程序验证程序。 #include

using namespace std; class Point //点类 { private:

int x, y;//私有成员变量,坐标 public :

Point()//无参数的构造方法,对xy初始化 { x = 0; y = 0; }

Point(int a, int b)//又参数的构造方法,对xy赋值 { x = a; y = b; }

void setXY(int a, int b)//设置坐标的函数 {

搜索更多关于: 自考c++程序设计 参考 的文档
自考c++程序设计 参考.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4vv0r7730q7b8vd538ce5nrap1rg1l00xes_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top