已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
I Judgment The right answer is T the wrong one is F Each judgment is 2 points total 20 points Number12345678910 T F 1 Both constructor and destructor of base class can be inherited by derived class 2 Static data member is shared by all objects of this class 3 Constructors can be declared as virtual function 4 When overloading an operator at least one argument of the resulting overloaded operator must be of a class type 5 Constructors have no return type 6 A friend function is not a member of the class but it can access the private members of that class 7 We can only list types of formal parameters in function declarations 8 There are loop statements can be wrote in the inline function 9 The assignment operator can only be overloaded into a member function 10 In C STL is a standard function template library II Fill in the blank Each blank is 1 point total 10 points 1 The default access label for class is 2 The constructor and the destructor must have the sameas the class 3 The member functions of derived classes can get access to members and members of a base class do not get access to private members of a base class 4 In C a class with a pure virtual function is called an 5 Suppose we have a class named as Dc when such code like Dc a 5 b 2 p is implemented the system will auto call the constructor of class Dc for times 6 Statement can catch all kinds of exceptions 7 In C in addition to sizeof the operator and are also can t be overload 8 Class istream is used to support input operation and class is used to support output operation III Single Choice Each choice is 2 point total 10 points 1 Usually copy constructor s parameter is A the name of some objectB the reference of some object C member name of some objectD the pointer of some object 2 Which is wrong about constructor A The compiler may supply default constructor B Constructors can have parameters and returned value C Constructors can be overloaded D Constructors can have default parameter value 3 Which is wrong about friend A The keyword friend is used to declare the friend B The member function of one class can be the friend of another class C The friend functions can access any specified access label member D The friend functions access the member of some object by this pointer 4 The purpose of virtual base class is A to eliminate 消除 ambiguityB to make a program simple C to increase the run efficiencyD to reduce the object codes 5 Which is right about the static data member A The static data member can not be called by the object name B The static data member can be initialized in the constructors C The static data member belongs to a certain class D The static data member must not be initialized in the file scope Point out the error the following programming and explain the reason write out error line number total 10points 1 constsize 10 L1 int a size L2 2 class Point public Point c 0 x 1 L3 Point Point pobj L4 Point Point L5 private int x L6 const int c L7 3 include using namespace std class Example public Example int i m i L8 void Example m 0 L9 void show cout m L10 private int m L11 int main Example ex1 L12 Example ex2 5 L13 ex2 m 10 L14 Example show L15 return 0 4 int x 9 x ptr L16 int y 78 L17 4 int x 9 x ptr L16 int y 78 L17 x ptr L18 x ptr L18 5 include using namespace std class BC public void set x int a x a L19 protected int get x const return x L20 private int x class DC public BC public void add2 L21 int c get x set x c 2 L22 void add3 x 3 L23 int main DC d d set x 3 L24 cout d get x endl L25 d x 77 L26 d add2 L27 return 0 Number LineReasonNumber LineReason 1 6 2 7 3 8 4 9 5 10 Write out the results of the following programs Each subject is 5 points total 30 points 1 include using namespace std char str 20 Hello C world char int main rep 15 cout The string is str endl return 0 2 include include using namespace std int main double values 1 23 35 36 657 6 778 2 char names Zoot Jimmy A1 Stan for int i 0 i 4 i cout left setw 6 names i right setw 6 fixed setprecision 1 values i endl return 0 3 include const double PI 3 14 using namespace std class Figure public Figure virtual double area const return 0 0 class Circle public Figure public Circle double myr R myr double area const return PI R R protected double R class Rectangle public Figure public Rectangle double myl double myw L myl W myw double area const return L W private double L W void func Figure int main Figure fig cout Area ofFigure is func fig Circlec 3 0 cout Area of circle is func c Rectangle rec 4 0 5 0 cout Area of rectangle is func rec return 0 4 include include using namespace std int main cout Opening data txt for appending endl ofstream fout fout open data txt ios app if fout fail cout Input file opening failed endl exit 1 fout Hello C world endl This is an appending program endl fout close cout End of appending to file endl return 0 Suppose that there is the content This is a test program in the data txt when the program executes what content will exist in the data txt 5 include using namespace std class Base1 public Base1 int i a i cout constructing Base1 a a endl private int a class Base2 public Base2 int i b i cout constructing Base2 b b endl private int b class Base3 public Base3 int i c i cout constructing Base3 c c endl private int c class Derivedclass public Base1 public Derivedclass int i int j int k int m private int d Base2 f Base3 g Derivedclass Derivedclass int i int j int k int m Base1 i g j f k d m cout constructing Derivedclass d d endl int main Derivedclass x 5 7 6 8 return 0 6 include using namespace std template class A Tm static T n public A T a m a n m void disp cout m m n n endl template TA n 0 int main A a 2 b 3 a disp b disp A c 1 6 d 5 4 c disp d disp return0 Programming Design total 20 points 1 10 points To define a Point class to satisfy the given test function main int main Pointp1 1 2 p2 cout 请输入点 p2 的坐标 endl p2 input p1 show 输出 1 2 p2 show cout The distance of point p1 and point p2 is p1 dist p2 endl return 0 2 10 points To design a RMB class to satisfy the given test function main int main RMBm1 100 2 8 m2 200 9 m if m1 m2 cout 两者的钱数相等 endl elsecout 两者的钱数不相等 endl m m1 m2 m m 50 m show 按元角分输出 return 0 2011 2012 学年第一学期C 面向对象程序设计课程试卷 标准答案及评分标准A B 卷 专业软件 103 5 I Judgment The right answer is T the wrong one is F Each judgment is 2 points total 20 points 题号12345678910 选项FTFTTTTFTF II Fill in the blank Each blank is 1 point total 20 points 题 号 1234 填 空 privatenamepublic and protectedabstract class 题 号 5678 填 空 6catch ostream III Single Choice Each choice is 1 point total 10 points 1 B2 B3 D4 A5 C IV Point out the error the following programming and explain the reason Number LineReasonLine NumberReason 1 L1没有数据类型 int6 L15不能使用类名访问成员函数 2 L3 c 是常数据成员 不能这样初 始化 7 L18 左值不是一个指针变量 3 L4pobj 不能是 Point 类型8 L23不能直接使用 x 4 L9构造函数不能有返回类型9 L25不能访问 protected 成员 5 L14不能直接用 来访问私有成员10 L26不能直接访问私有成员 Write out the results of the following programs Each subject is 5 points total 30 points 1 The string is Hello C world 2 Zoot1 2 Jimmy35 4 A1657 6 Stan778 2 4 This is a test program Hello C world This is an appending program 5 constructing Base1 a 5 constructing Base2 b 6 constructing Base3 c 7 constructing Derivedclass d 8 Programming Design total 20 points 1 include include 1 point using namespace std class Point public Point int xx int yy x xx y yy 2 points Point x y 0 2 points void input 2 points cin x y void show cout x y endl 1 point 3 Area ofFigure is 0 Area of circle is 28 26 Area of rectangle is 20 6 m 2 n 5 m 3 n 5 m 1 6 n 7 m 5 4 n 7 double dist Point p 2 points private int x int y double Point dist Point p return sqrt p x x p x x p y y p y y int main Pointp1 1 2 p2 cout 请输入点 p2 的坐标 endl p2 input p1 show 输出 1 2 p2 show cout The distance of point p1 and point p2 is p1 dist p2 endl return 0 2 include using namespace std class RMB public RMB int y int j int f yuan y jiao j fen f 1 point RMB int y int j yuan y jiao j fen 0 1 point RMB int y yuan y jiao 0 fen 0 2 points RMB yuan 0 jiao 0 fen 0 1 point void show cout yuan 元 jiao 角 fen 分 10 mon fen 10 mon jiao if mon jiao 10 mon jiao 10 mon yuan return mon int main RMBm1 100 2 8 m2 200 9 m if m1 m2 cout 两者的钱数相等 endl elsecout 两者的钱数不相等 endl m m 50 m show 按元角分输出 return 0 Judgment The right answer is T the wrong one is F The keyword friend is used in a function definition not in a function declaration F Values stored in the elements of a vector may be accessed the same way as values stored in the elements array Aclass can only have one subclass F It is not possible to access the attributes of a class with no member fuctions methods F The meaning of all the C operators such as etc is fixed and cannot be changed T If you do not declare a constructor in a class the compiler will furnish a default constructor for you automatically T An object of a classAcan be a private member of a class B T Because we cannot instantiate objects of abstract base classes we cannot declare pointers and references to abstract base classes F In dynamic binding an object s type must be known at compile time for a virtual function call to be compiled The assignment operator can only be overloaed into a nonmember function F Fill in the blank There are four stream object defined in the object cerr is the standard error output stream In C Encapsulation is achieved by making class 类 In a class maximum number of destructors are 1 Assume that A is a class the constructor of class A had be called 4 times when the statement Aa 3 b 6 p was executed Assume that the name of type parameter is defined as T when defining the function template you should add prefix statement template Ifthe name of a is Myclass then the name of its destructor is it has return values If class B is derived from class A class C is derived from class B an object of class C is created then the called order of constructor is In the C in addition to sizeof the operator and are also can t be overload 选择 1 Which are isn t the member funcition of a class A ConstructorB DestructorC Friend FunctionD Copy Constructor 2 Opening the file d file dat and write data to it which statement should we use A ifstream infile d file dat ios in B ifstream infile d file dat ios in C ofstream infile d file dat ios out D fstream infile d file dat ios in ios out 3 Which is wrong about class A Class is one kind of type it encapsulates data and operates B Object is a instance of a class C One object can only belong to a class D There are only one object in a class 4 Usually the parameter of a copy constructor is A a objectB the member of a object C the reference of a objectD the pointer of a object 5 If there are a pure virtual function in a class then we call this class as A abstract classB virtual basic classC derived classD none of above Point out the error the following programming and explain the reason write out the error line member total 15 points include using namespace std class Cbook private char p book int num public void CBook const char p val p book new char strlen p val strcopy p book p val num num 1 void getNum const return num void setNum int number const num number void print const CBook delete p book Void print const cout p book endl Void main char book title 60 CBook p book obj cout book title Cbook abook cout abook num p book obj abook p book obj print 错误行号改错错误行号改错 1 1改成 include1 23改成 void CBook printf 1 29引号 应该是英文的 1 3改成 CBook 1 22 之后加 编程 1 class Move private double x double y public Move double a 0 double b 0 set x y to a b showmove const shows current x y values Move add const Move this function adds x of m to x of invoking object to get new x adds y of m to y of invoking object to get new y create a new move object initialized to new x y values and returns it reset double a 0 double b 0 reset x y to a b Int main Move Point1 3 4 Point2 Point3 cout x and y values of Point1 are Point1 showmove Point2 reset 5 6 Point3 Point1 add Point2 cout x and y values of Point3 are Point3 showmove return 0 Create member function definitions to satisfy the test function main 2 9 points Deine a Complex class it has two private member real and image 1 Please write a constroctor which can accept 0 2 parameters a copy constructor a Print function which can display the value of data member 2 Write Set function setReal and setImage which can change the value of private data member 3 Overload operator and which can finish addition and subtraction of two complex The main function listed as following void main Complex c1 1 5 7 9 Complex c2 c1 c2 setReal 2 7 c2 setImage 0 c1 Print c2 Print c1 c2 Print c1 c2 Print 一 Judgement Please judge the following 10 sentence and full the blank of the list with your result The right answer is the wrong one is 20 point 1 We can assign a value to a constant when it is declared 2 int sort int arr and float sort float arr are overloaded functions 3 A function that the compiler generates using a function template is called an instance of the function template or a template function 4 A constant pointer to a constant cannot be changed to point to another constant of the same type 5 Just like the structure members the default access specifier for class members is private 6 If we defined a constructor in a class we must define a destructor to destroy it 7 When passing an object to a function its copy is created in memory But it does not invoke 调用 a class constructor 8 When instantiating an object of a derived class constructors of all of its parent class are executed prior to the derived class constructors Destructor functions are always executed in the same order 9 Virtual functions are used with inheritance to resolve conflicts when both base and derived class declare member functions with the same signature 10 The member defined in base class as protected or private can only be accessed by the member functions in derived class 二 Fill in the blank each blank has 1 point total 24 score 1 Apointer type specifies the type of object to which the pointer points 2 Passing a reference to a function is like passing the the address of the variable used as the argument in the function call 3 A program that uses dynamically allocates exactly the amount of memory needed during its execution 4 The default access specifier 指示符 区分符 说明符 for data members and member function are private 5 If member function of class don t proviet to initialize a class object default constructor is automatically called 6 When member function is called of the member function point function called 7 While the friend function is not a member of class it has access to the class allmenber 8 When declared static data member outside the class class name must precede the static data member name 9 Constant member functions must be used when working with constantdata member 10 A binary operator can be overloaded by using a friendfunction rather than a member function 11 control access specifier is used only when implementing inheritance 12 To pass arguments from a derived class to a base class a derived class constructor must be created NUM 1 2 3 4 5 6 7 8 9 10 RESULT 三 Write out result of the following programs each subject is 6 point total 36 point 1 include classA int a public A int aa 0 a aa A cout Destructor A a endl class B public A int b public B int aa 0 int bb 0 A aa b bb B cout Destructor B b endl void main B x 5 y 6 7 2 include class Counter public Counter val 0 cout Default Constructor of Counter endl Counter int x val x cout Coustructor of Counter val endl Counter cout Destructor of counter val endl private int val class Example public Example val 0 cout Default Constructor of Example endl Example int x c2 x val x cout Constructor of Example val endl Example cout Destructor of Example val endl void Print cout value val endl private Counter c1 c2 intval void main Example e1 e2 4 e2 Print 3 include class Test void fun1 Test t Test fun2 class Test public Test int n 1 val n cout Con endl Test const Testcout Copy con endl Test cout Assignment endl return this private int val void main Test t1 1 Test t2 t1 Test t3 t3 t1 fun1 t2 t3 fun2 void fun1 Test t Test fun2 Test t return t 4 include class Person public Person cout Constructor of Person endl Person cout Destructor of Per
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 广西名校联考2025-2026学年高三上学期11月考试生物试卷
- 2025年世博分校培训考试题及答案
- 电工安全技术试题及答案
- 重庆綦江地震应急预案(3篇)
- 庐江科四考试题目及答案
- 铁路局机务笔试题库及答案
- 空间音频音乐制作-洞察与解读
- 碳纤维复合应用-洞察与解读
- 2025年技术支持专家招聘面试题库及参考答案
- 2025年民宿运营经理岗位招聘面试参考试题及参考答案
- (标准)驿站转让合同协议书样本
- 2024版电网典型设计10kV配电站房分册
- 2025年工会基础知识考试题库及参考答案
- 企业团险培训课件
- 市政工程施工配套课件
- 国际贸易部管理制度
- 嗜酸细胞性食管炎的诊断与治疗
- 呼吸系统感染健康教育
- DB13 2122-2014 洁净颗粒型煤
- 白酒委托加工合同范本
- 消防供水协议书
评论
0/150
提交评论