南开大学复习资料-面向对象程序设计10001.docx

上传人:M****1 文档编号:564516757 上传时间:2022-11-23 格式:DOCX 页数:26 大小:60.85KB
返回 下载 相关 举报
南开大学复习资料-面向对象程序设计10001.docx_第1页
第1页 / 共26页
南开大学复习资料-面向对象程序设计10001.docx_第2页
第2页 / 共26页
南开大学复习资料-面向对象程序设计10001.docx_第3页
第3页 / 共26页
南开大学复习资料-面向对象程序设计10001.docx_第4页
第4页 / 共26页
南开大学复习资料-面向对象程序设计10001.docx_第5页
第5页 / 共26页
点击查看更多>>
资源描述

《南开大学复习资料-面向对象程序设计10001.docx》由会员分享,可在线阅读,更多相关《南开大学复习资料-面向对象程序设计10001.docx(26页珍藏版)》请在金锄头文库上搜索。

1、面向对象程序设计课程期末复习资料一、客观部分:(单项选择、多项选择、不定项选择、判断)(一)、选择部分1、面向对象方法的基本观点是一切系统都是由(C )构成的。A、结构B、模块C、对象D、类2、下列关于主函数的叙述中正确的是(B )。A、一个程序可以有多个主函数B、程序从主函数开始执行C、一个程序可以没有主函数D、主函数是一个特殊的函数,因此其结构与其他函数不同3、有关带默认参数的函数的描述正确的是(D )。A、只能在函数定义时设置默认参数值B、只能在函数声明时设置默认参数值C、函数调用时,必须使用默认的参数值,不能给出新的实参值D、设置默认参数时,应该设置最右边的若干个参数的默认值4、有关重

2、载函数的描述正确的是(C )。A、函数名相同的函数就是重裁函数B、函数名相同但返回值类型不同的函数就是重载函数C、函数名相同但参数个数或类型不同的函数就是重载函数D、函数功能相同的函数就是重载函数5、假设堆内存分配均成功,则下面程序段完全正确的是(A )oA、int *p=new int(3) ;cout*p;delete p;B、int *p=new int5 = (l, 2, 3, 4, 5 ;for(int i=0; i5; i+)coutpi jdelcte p;C、int *p=new int 5 ;for(int i=0; iWho();p=&obj2;p-Who();p=&obj

3、3;p-Who();obj2.Who();obj3.Who(); return 0;参考答案:class Baseclass Baseclass Baseclass Derivedlclass Derived26、写出下面程序的运行结果。 #inckide using namespace std;class Shape(public:void Draw()coutShapeendl;Ivirtual void Prinl()=0;;class Circle:public Shapeprivate:double r;public:void Draw()coutCircleendl;void Se

4、tData(double radius)r=radius;void Print()cou(area:3.14*r*rendl;;class Rectangle:public Shapeprivate:double a,b;public:void Draw()coutRectangleendl;1void SetData(doublc x,double y)a=x,b=y;void Print()(cout,area:a*bendl;1;int main()Circle c;Rectangle r;Shape *spl=&c;Shape &sp2=r;c.SetData(IO);r.SetDat

5、a(3,5);spl-Draw();c.Piint();sp2.Draw();r.Print();return 0;参考答案:Shapearea:314Shapearea:157、写出下面程序的运行结果。#include using namespace std;class Sample;Sample opcrator-(Samplc &,Samplc &);Sample operator+(Sample &,Sample &); class Sample(public:Samplc()Sample(int i)n=i;friend Sample operator-(Sample &,Sampl

6、e &); friend Sample opcrator+(Sample &,Sample &); void disp()coutn=nendl; private:int n;;Sample opcrator-(Saniple &sl,Sample &s2)(int m=sl .n-s2.n;return Sample(iTi);Sample operator+(Sample &sl,Sample &s2)(int m=sl .n+s2.n;return Sample(m);)int main()Sample s 1 (10),s2(20),s3;s3=s2-sl;s3.disp();s3=s

7、2+sl;s3.disp();return 0;参考答案:n=10n=308、写出下面程序的运行结果。#include using namespace std;class Sample public:Sample(int i)n=i;void opcrator+=(int i)(n+=i; void operator-=(int i)(n-=i;void disp() coutn=ncndl:private:int n;;int inain()(Sample A(2),B(2);A+=l;B-=l;A. dispO;B. dispO;return 0;参考答案:n=3n=l9、写出下面程序的运

8、行结果。#include #includc using namespace std;int main。(ofstream fllel; filcl.opcn(fl.datu); filell23endl; filel63.78;filel.close();ifstream file2(f 1 .dat);int i, j;file2ij;cout,i+j=i+jendl; file2.close();return 0;参考答案:i+j=18610、写出下面程序的运行结果。#include using namespace std;template class addTx, y;public:ad

9、d(T a, T b)x=a;y=b;IT add 1() return x+y; ;int main()(add A(65, 120);add B(13.6, 22.9);coutsl =A.addl ()endl;cout,s2=,B .add 1 ()endl;return 0;参考答案:sl=185s2=36. 511、swap(涵数利用引用作为参数实现两个变量的交换,将程序填写完整。#includc using namespace std;void swaD(int &x, int &、)(int temp;temp=x;y=temp;int main()(int a,b;cinab

10、;swaD(a, b):couta, bendl; return 0;考核知识点:C+与C的主要差异-函数的引用调用参见讲稿章节:1-1612、下面的程序定义了两个类,一个是TennisClub,其成员数据有俱乐部和会员 名,另一个是Person,其成员数据有姓名和年龄,类TennisClub的成员函数visit 可以显示姓名、年龄、俱乐部名、会员名。将程序填写完整。#include #include using namespace std;class Person;class TennisClub(public:TennisClub(char 华char *q)strcpy(club,p);

11、strcpy(name,q);void visit(Person);private:char club24;char name24;;class Person(public:Person(char *p.int y)strcpy(namc,p);age=y;friend void TennisClub:visit(Person x);private:char namc24;ini age;;void TennisClub:visit(Person x)(cout姓名:x.nameendl;cout,r 年龄:x.ageendl;coutH可以使用的俱乐部:clubendl;cout介绍人:na

12、meendl;int main()(TennisClub a(”明星俱乐部”,”李晓明,Person b(”张静”,28);a.visit(b);return 0;考核知识点:类的定义、类的友元参见讲稿章节:2-03. 2-1613、请将下面程序补充完整。#include using namespace std;class Student;class Teacher(public:void setScore(Student& s,double sc);void setHour(Studcnt& s,int h);private:long number;charname 101; ;class

13、Studentpublic:friend class Teacher;double getScorc() return score; int getHour() ( return semeHour; private:long number;char name I0J;double score;int semeHour;;void Teacher:setScore(Student& s,double sc) s.score=sc; 可以直接访问Student的私有数据成员void Teacher:se(Hour(Student& s,int h) s.semeHour=h; /可以直接访问Stu

14、dent的私有数据成员int niain() Teacher I;Student s;t.setScore(s,98.5);t.selHour(s,5);couts.gctScorc() s.gctHour()cndl;return 0;考核知识点:类的友元参见讲稿章节:2-1614、请补充完整下面类说明中的拷贝构造函数。class MyClass(public:int *p;int size;MyClass(int n):size(n),p(new intn)MyClass() delete p;MyClass(MyClass& me): sizc(mc.size)D = new intlsize;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号