- 1
- 0
- 约1.45万字
- 约 8页
- 2017-01-07 发布于辽宁
- 举报
电大(精新编版)c语言程序设计期末考试试题及答案小抄参考__2017年度
电大C++语言程序设计
期末考试试题及答案
姓名 ____________ 学号 ____________ 班号 ___________
题 号 一 二(1) 二(2) 三 总 分 成 绩
一、填空
1.在类中必须声明成员函数的 原型 ,成员函数的 实现 部分可以写在类外。
2.如果需要在被调函数运行期间,改变主调函数中实参变量的值,则函数的形参应该是 引用 类型或 指针 类型。
3. 抽象 类只能作为基类使用,而不能声明它的对象。
4.进行函数重载时,被重载的同名函数如果都没有用const修饰,则它们的形参 个数 或 类型 必须不同。
5.通过一个 常 对象只能调用它的常成员函数,不能调用其他成员函数。
6.函数的递归调用是指函数直接或间接地调用 自身 。
7.拷贝构造函数的形参必须是 本类对象的引用 。
二、阅读下列程序,写出其运行时的输出结果 如果程序运行时会出现错误,请简要描述错误原因。
1.请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。
(1)程序:
#include iostream.h
#include string.h
class Base
{ private:
char msg[30];
protected:
int n;
public:
Base(char s[],int m=0):n(m)
{ strcpy(msg,s);
}
void output(void)
{ coutnendlmsgendl;
}
};
class Derived1:public Base
{
private:
int n;
public:
Derived1(int m=1):
Base(Base,m-1)
{ n=m; }
void output(void)
{ coutnendl;
Base::output();
}
};
class Derived2:public Derived1
{
private:
int n;
public:
Derived2(int m=2):
Derived1(m-1)
{ n=m; }
void output(void)
{ coutnendl;
Derived1::output();
}
};
int main()
{
Base B(Base Class,1);
Derived2 D;
B.output();
D.output();
}
运行结果:
1
Base Class
2
1
0
Base
(2)程序:
#include iostream.h
class Samp
{public:
void Setij(int a,int b){i=a,j=b;}
~Samp()
{ coutDestroying..iendl;
}
int GetMuti(){return i*j;}
protected:
int i;
int j;
};
int main()
{
Samp *p;
p=new Samp[5];
if(!p)
{ coutAllocation error\n;
return 1;
}
for(int j=0;j5;j++)
p[j].Setij(j,j);
for(int k=0;k5;k++)
coutMuti[k] is:
p[k].GetMuti()endl;
delete[]p;
return 0;
}
运行结果:
Muti[0] is:0
Muti[1] is:1
Muti[2] is:4
Muti[3] is:9
Muti[4] is:16
Destroying..4
Destroying..3
Destroying..2
Destroying..1
Destroying..0
2.请在以下两题中任选一题,该题得分即为本小题得分。如两题都答,则取两题得分之平均值为本小题得分。
(1)程序:
#include iostream.h
#include stdlib.h
class Vector
{
public:
Vector(int s=100);
int Elem(int ndx);
void Display(void);
void Set(void);
~Vector(void);
protected:
您可能关注的文档
- 电大(精新编版)《市场营销学》专科期末重点复习考试资料小抄【微缩打印版,电大考试必备】__2017年度.doc
- 电大(精新编版)《试验设计与生物统计》作业二及参考答案小抄__2017年度.doc
- 电大(精新编版)《税收理论与实务》期末复习题及参考答案资料小抄__2017年度.doc
- 电大(精新编版)《饲料与饲养》期末复习考试精华版资料小抄__2017年度.doc
- 电大(精新编版)《统计基础知识与统计实务》期末复习题及参考答案小抄__2017年度.doc
- 电大(精新编版)《市场营销学》专科期末复习资料考试小抄__2017年度.doc
- 电大(精新编版)《市场营销原理与实务》专科期末复习考试重点参考资料小抄【精编完整版】__2017年度.doc
- 电大(精新编版)《土壤与肥料》期末复习重点知识归纳考试小抄【精编版电大小抄】__2017年度.doc
- 电大(精新编版)《土木工程cad》期末考试复习试题资料参考小抄【精华版】__2017年度.doc
- 电大(精新编版)《推销策略与艺术》形成性考核册作业答案(附题)__2017年度.doc
原创力文档

文档评论(0)