2009年C++(II)双语_试卷B (1).doc_第1页
2009年C++(II)双语_试卷B (1).doc_第2页
2009年C++(II)双语_试卷B (1).doc_第3页
2009年C++(II)双语_试卷B (1).doc_第4页
2009年C++(II)双语_试卷B (1).doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

姓名 学号 学院 专业 座位号 ( 密 封 线 内 不 答 题 )密封线线_ _ 诚信应考,考试作弊将带来严重后果! 华南理工大学期末考试 C+程序设计(II) 试卷 B注意事项:1. 考前请将密封线内各项信息填写清楚; 2. 所有答案请直接答在试卷上; 3考试形式:闭卷; 4. 本试卷共 四 大题,满分100分,考试时间120分钟。题 号 一 二 三四总分得 分评卷人1. Sate whether each of the following is true or false. (20 scores, each 2 scores) 1) Treating a derived-class object as a bass-class object can be cause errors. ( f )2) Operator static-cast can be used to downcast base-class pointers safely. ( f )3) Operator typeid returns a reference to a type_info object. ( t )4) Key words class and typename as used with a template type parameter specifically mean “any user-defined class type”. ( t )5) When using parameterized manipulators, the header file must be included. ( t )6) Member function read can be used to read data from the input object cin. ( t )7) The programmer must create the cin and cout objects explicitly. ( f )8) operator : would be the name of a function that would provide an overloaded version of the operator : for a specific class. ( f )9) C+ provides for multiple inheritance, which allows a derived class to inherit from many based classes, even if these base classes are unrelated. ( t )10) A constant object must be initialized, it cannot be modified after it is created. ( t )11) If a member initializer is not provided for a member object of a class, the objects default copy constructor is called. ( t )12) The precedence, associativity and “arity” of an operator can not be changed by overloading the operator. ( t )13) In an “is-a” or inheritance relationship, an object of a derived class can not be treated as an object of its base class ( f )14) Base-class constructors are not inherited by derived classes. ( t )15) A “has -a” relationship is implemented via inheritance. ( f )16) All virtual functions in an abstract base class must be declared as pure virtual function. ( f )17) A friend function of a function template must be a function-template specialization. ( f )18) As with static data members of non-template class, static data member of class-template specialization must also be initialized at file scope. ( t )19) An exception thrown outside a try block causes a call to terminate. ( t )20) Data in sequential-access files always is updated without overwriting nearby data. ( (不确定请自行查书)f )2. For each of the following, show the output(25 scores, each 5 scores)C+程序设计(II) 试卷A 第1页 (共10页)1) #include class BASE public: void get( int i,int j,int k,int l ) a = i; b = j; x = k; y = l; void print() cout a = a t b = b t x = x t y = y endl; int a,b;protected:int x, y;class A: public BASE public:void get( int i, int j, int k, int l ) BASE obj3; obj3.get( 50, 60, 70, 80 ); obj3.print(); a = i; b = j; x = k; y = l; u = a + b + obj3.a ; v = y - x + obj3.b; void print() cout a = a t b = b t x = x t y = y endl; cout u = u t v = v endl;private: int u, v ;void main() BASE obj1; A obj2;obj1.get( 6, 9, 8, 7 ); obj2.get( 8, 3, 5, 6 ); obj1.print(); obj2.print();2) #includestruct list int data ;list * next ; ; list * head ; list * insert ( int num ) list * s, *p, *q ; s = new list ; s-data = num ; s-next = NULL ; if ( head = NULL ) head = s ; return( head ) ; if ( head-data s-data ) s-next = head ; head = s ; return ( head ) ; for ( q = head, p = head-next ; p ; q = p, p = p-next ) if ( p-data s-data ) s-next = p ; q-next = s ; return ( head ) ; q-next = s ; return ( head ) ;void showlist( const list * head ) cout now the items of list are: n ; while( head ) cout data next ; cout k ; for (int i=0;i5;i+0 ) head = insert(ki) ; showlist( head ) ; 3) # include template class FF TT a1,a2,a3;public :FF(TT b1,TT b2,TT b3) a1=b1; a2=b2; a3=b3;TT Sum() return a1+a2+a3; ;void main()FF x(2,3,4),y(5,7,9);cout x.Sum() y.Sum()endl;4) # include # include class A int a,b; char op;public:A(int aa,int bb,char ch) a=aa; b=bb; op=ch; int Comp( ) switch (op) case + : return a+b;case - : return a-b;case * : return a*b;case / : if (b!=0) return a/b; else exit(1);case % : if (b!=0) return a%b; else exit(1);default : exit(1); void SetA(int aa,int bb,char ch) a=aa; b=bb; op=ch; ;void main( void ) A x(3,5,*);int a=x.Comp( );x.SetA(4,9,+);a += x.Comp( );x.SetA(8,5,%);a += x.Comp( );cout a=aendl;5) #include using std:cout;using std:cin;using std:endl;int main() int widthValue = 4; char sentence 10 ; cout Enter a sentence: sentence ) cout.width( widthValue+ ); cout sentence endl; cin.width( 5 ); return 0; INPUT: This is a test of the width member functionOUTPUT:3. Answer the following questions.(35 scores)1) Find the errors in the following program correct them, after correcting, show the output.(6 scores)# include # include class Student public: Student(int num) +x; Sno=num;static int get_x() retrun x;int get_Sno() retrun Sno;private:static int x;int Sno;int Student:x=0;void main () coutStudent:get_x()”Student existn”; Student stu1(101); coutStudent:get_x()”Student exist, No.=”get_Sno()”n”; Student *pstu=new Student(102); coutStudent:get_x()”Student exist, No.=”get_Sno()”n”; 2) Fill in the blanks in each of the following program. The program should read the record from the file “C:client.dat”, and display it on screen. (8 scores) #include using std:cout;using std:cin;using std:ios;using std:cerr;using std:endl; using std:ifstream;#include int main() ; if ( ) cerr File could not be opened endl; exit( 1 ); int account; char name 30 ; double balance; while ( ) cout account”t ” name”t ” balance endl;inClientFile.close( ); return 0; 3) Fill in the blanks in each of the following program. The program checks for divide-by-zero exceptions. (4 scores)#include using std:cout;using std:cin;using std:endl;#include using std:exception;class DivideByZeroException : public exception public: DivideByZeroException:DivideByZeroException(): exception( attempted to divide by zero ) ; double quotient( int numerator, int denominator ) if ( denominator = 0 ) ; return static_cast( numerator ) / denominator; int main() int number1; / user-specified numerator int number2; / user-specified denominator double result; / result of division cout number1 number2 ) try result = quotient( number1, number2 ); cout The quotient is: result endl; cout Exception occurred: divideByZeroException.what() endl; cout nEnter two integers (end-of-file to end): ; return 0; 4). According main function, write out function template min. (5 scores)void main() coutmin(10,5,3)endl; coutmin(10.0,5.0,.03)endl; coutmin(a,b,c) and operators.(12 scores)#include #include class Stock public: ; ;private: char Stockcode7;char Stockname7;float p

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论