版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上IJudgment. (The right answer is “T”, the wrong one is “F” .Each judgment is 2 points, total 20 points.)Number12345678910T/F1. 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 ca
2、n 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 c
3、an 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.IIFill in the blank . (Each blank is 1 poi
4、nt, total:10 points)1. The default access label for class is _.2. The constructor and the destructor must have the same as 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+
5、, a class with a pure virtual function is called an _.5. Suppose we have a class named as Dc, when such code like “Dc a5, 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 “.”, “*”,
6、“sizeof”, the operator _ and _ are also cant be overload.8. Class istream is used to support input operation, and class _ is used to support output operation. IIISingle Choice (Each choice is 2 point, total:10 points)1. ( )Usually copy constructors parameter isA) the name of some object B) the refer
7、ence of some objectC) member name of some object D) the pointer of some object2. ( )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 va
8、lue.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 point
9、er. 4. ( )The purpose of virtual base class is. A) to eliminate(消除)ambiguity B) to make a program simpleC) to increase the run efficiency D) to reduce the object codes5. ( )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 m
10、ember 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.4. int x=9 , *x_ptr=&x; /L16 int y=78; /L17*x_ptr = &y ; /L18.Point out the error the following programming and explain the reason(wri
11、te out error line number, total:10points)1. const size=10; /L1int asize; /L22. class Point public: Point() c=0; x=-1; /L3 Point(Point pobj); /L4 Point(Point& p); /L5private: 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;
12、/L9 void show()coutm; /L10 private: int m; /L11; int main( ) Example ex1; /L12Example ex2(5); /L13 ex2.m+=10; /L14 Example.show(); /L15 return 0; 4. int x=9 , *x_ptr=&x; /L16 int y=78; /L17*x_ptr = &y ; /L185. #includeusing namespace std;class BC public: void set_x(int a) x=a; /L19 protected: int ge
13、t_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 coutd.get_x( )endl; /L25 d.x=77; /L26 d.add2(); /L27 return 0; Number/ LineReasonNumber / LineReason1/6/2/7/3/8/4/9/5/1
14、0/Write out the results of the following programs. (Each subject is 5 points; total:30 points)1. #include using namespace std;char str20=Hello C+ world.;char &rep(int k)return strk; int main( )rep(15)=!;coutThe string is:strendl;return 0;2. #include #include using namespace std;int main() double val
15、ues=1.23,35.36,657.6,778.2; char* names=Zoot,Jimmy,A1,Stan; for(int i=0;i4;i+) coutleftsetw(6)namesi rightsetw(6) fixedsetprecision(1) valuesiendl; 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 : publi
16、c 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 &p) coutp.area()endl;int main() Figure fig; coutAr
17、ea of Figure is ; func(fig);Circle c(3.0); cout“Area of circle is ”; func(c); Rectangle rec(4.0,5.0); coutArea 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.
18、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 wil
19、l exist in the data.txt? 5. #include using namespace std;class Base1 public: Base1(int i) a=i; coutconstructing Base1 a= aendl; private:int a; ;class Base2 public: Base2(int i)b=i; coutconstructing Base2 b= bendl;private: int b;class Base3 public: Base3(int i)c=i;coutconstructing Base3 c= cendl; pri
20、vate: int c;class Derivedclass:public Base1public: 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;coutconstructing Derivedclass d=dendl; int main() Derivedclass x(5,7,6,8);return 0;6. #includeusing na
21、mespace std;templateclass A T m; static T n; public: A(T a): m(a) n+=m; void disp( ) coutm=m,n=nendl; ;templateT A: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
22、 given test function main: int main()Point p1(1,2), p2;cout請輸入點p2的坐標:endl; p2.input( );p1.show( ) ; /輸出(1,2)p2.show( ) ; coutThe 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() RMB m1(100,2,8), m2
23、(200,9), m; if( m1=m2) cout”兩者的錢數(shù)相等!”endl; else cout”兩者的錢數(shù)不相等!”endl; m=m1+m2; m=m+50;m.show( ); /按元角分輸出 return 0;2011 2012學(xué)年第 一 學(xué)期 C+面向?qū)ο蟪绦蛟O(shè)計 課程試卷標準答案及評分標準 A()/B( ) 卷 _專業(yè) 軟件103-5 IJudgment. (The right answer is “T”, the wrong one is “F” .Each judgment is 2 points, total 20 points.)題號12345678910選項FTF
24、TTTTFTFIIFill in the blank . (Each blank is 1 point, total:20 points)題 號1234填空privatenamepublic and protected abstract class題 號5678填空6catch ()?:, :ostreamIIISingle Choice (Each choice is 1 point, total:10 points)1B 2.B 3.D 4.A 5.CIV Point out the error the following programming and explain the reaso
25、nNumber/ LineReasonLine NumberReason1/L1沒有數(shù)據(jù)類型int6/L15不能使用類名訪問成員函數(shù)2/L3c是常數(shù)據(jù)成員,不能這樣初始化7/L18左值不是一個指針變量3/L4pobj不能是Point類型8/L23不能直接使用x4/L9構(gòu)造函數(shù)不能有返回類型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 st
26、ring is Hello C+ world!3. Area of Figure is 0Area of circle is 28.26Area of rectangle is 202. Zoot 1.2 Jimmy 35.4 A1 657.6 Stan 778.26. m=2,n=5m=3,n=5m=1.6,n=7m=5.4,n=74. This is a test program!Hello C+ world!This is an appending program. 5.constructing Base1 a=5constructing Base2 b=6constructing Ba
27、se3 c=7constructing Derivedclass d=8. Programming Design. (total 20 points)1.#include #include /1 pointusing namespace std;class Pointpublic:Point(int xx,int yy) x=xx; y=yy; / 2 pointsPoint()x=y=0; /2 pointsvoid input() /2 points cinxy; void show() cout(x,y)endl; / 1 pointdouble dist(Point p); /2 po
28、intsprivate: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()Point p1(1,2), p2;cout請輸入點p2的坐標:endl; p2.input( );p1.show( ) ; /輸出(1,2)p2.show( ) ; coutThe distance of point p1 and point p2 is p1.dist(p2)endl;return 0; 2. #includeusing namespace std;class R
29、MBpublic:RMB (int y,int j,int f)yuan=y;jiao=j;fen=f; /1 pointRMB (int y,int j) yuan=y; jiao=j; fen=0; /1 pointRMB (int y) yuan=y; jiao=0; fen=0; /2 pointsRMB ()yuan=0;jiao=0;fen=0; /1 pointvoid show()coutyuan元jiao角fen分=10) mon.fen -=10;mon.jiao +;if(mon.jiao =10) mon.jiao -=10;mon.yuan +;return mon;
30、int main() RMB m1(100,2,8), m2(200,9), m; if( m1=m2) cout”兩者的錢數(shù)相等!”endl; else cout”兩者的錢數(shù)不相等!”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 ele
31、ments of a vector may be accessed the same way as values stored in the elements array.()A class 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.
32、(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 class A can 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 abst
33、ract base classes.(F)In dynamic binding an objects 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 err
34、or 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 “A a3,b(6),*p;”was executed.Assume that the name of type parameter is defined as T,when de
35、fining the function template,you should add prefix statement_template_.If the 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 th
36、e C+,in addition to “,”,” * ”,”sizeof ”,the operator_and_are also cant be overload. 選擇1、( )Which are isnt the member funcition of a class?A)Constructor B)Destructor C)Friend Function D)Copy Constructor2、( )Opening the file”d:file.dat”and write data to it,which statement should we use?A)ifstream infi
37、le(“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 o
38、nly belong to a class. D)There are only one object in a class.4、( )Usually the parameter of a copy constructor is_. A) a object B)the member of a object C)the reference of a object D)the pointer of a object5、( ) If there are a pure virtual function in a class,then we call this class as_ A)abstract c
39、lass B)virtual basic class C)derived class D)none of abovePoint 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 cha
40、rstrlen(p_val);strcopy(p_book,p_val);num=num+1;void getNum()constreturn num;void setNum(int number)constnum=number;void print() const;CBook()deletep_book;Void print()constcoutp_bookendl;Void main()char book_title60;CBook *p_book_obj;coutbook_title;Cbook abook;coutabook.num;p_book_obj=abook;p_book_ob
41、j.print();錯誤行號 改錯錯誤行號 改錯1_1改成,#include1_23改成“void CBook:printf”1_29引號,應(yīng)該是英文的1_3改成 CBook1_22之后加“;” 編程1、class Moveprivate:double x;double y;public:Move(double a = 0, double b=0); /set x,y to a,bshowmove()const; /shows current x,y values;Move add(const Move & m)const; /this function adds x of m to x of
42、 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 itreset(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();Poi
43、nt2.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 p
44、arameters,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
45、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.
46、 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.3A 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. 5Just like the structure members, the default access specifier for class members is private. ()6If we defined a constructor in a class, we must
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中職(市場營銷)市場實訓(xùn)綜合測試題及答案
- 2025年大學(xué)一年級(食品科學(xué)與工程)食品微生物學(xué)試題及答案
- 2026年機械原理(機械運動優(yōu)化)試題及答案
- 2025年中職大數(shù)據(jù)技術(shù)與應(yīng)用(大數(shù)據(jù)處理基礎(chǔ))試題及答案
- 2025年中職(旅游服務(wù)與管理)旅游管理綜合階段測試試題及答案
- 2026年客服管理(投訴處理)試題及答案
- 2025年高職衛(wèi)生檢驗與檢疫技術(shù)(檢驗檢疫應(yīng)用)試題及答案
- 2025年高職汽車電子技術(shù)(電子控制系統(tǒng))試題及答案
- 2025年高職物流統(tǒng)計(物流統(tǒng)計)試題及答案
- 2025年大學(xué)大四(輕化工程)造紙廢水處理技術(shù)綜合測試試題及答案
- 2024-2025學(xué)年廣西柳州市九年級(上)期末數(shù)學(xué)試卷(含答案)
- 寧德時代心理測試題及答案
- 耳部刮痧課件
- 師范類學(xué)生教學(xué)能力提升計劃
- (2025)鐵路局招聘筆試真題及答案
- 騎車誤傷協(xié)議書
- 孔源性視網(wǎng)膜脫離護理查房
- 《中級財務(wù)會計》課件-11收入、費用和利潤
- 新生兒肺炎的治療與護理
- 電纜局部放電試驗報告模板
- 東莞初三上冊期末數(shù)學(xué)試卷
評論
0/150
提交評論