


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、重點大學(xué)考試試卷A卷2014 2015學(xué)年2學(xué)期面向?qū)ο蟪绦蛟O(shè)計課程閉卷時間120分鐘,學(xué)時,學(xué)分,總分100分,占總評成績100% 年 月曰-試卷裝訂線題號-一-二二三四五六七八九十合計總分為20182438100得分-得分項rL 題 擇 先一、得分項選擇題每一小題2分,共20分,此題答案填入下表中裝訂線內(nèi)不要答題,不要填寫考生信息小題號12345678910答案1.在C+中,如下語句,錯誤的答案是 ()A. i nt a(3);B. i nt a3;C. i nt &a;D. i nt *a;2.派生類中的成員函數(shù)可以直接訪問基類的()A.公有成員B.私有成員C.公有和保護(hù)成員D.
2、保護(hù)成員3.在C+沖,關(guān)于類的析構(gòu)函數(shù),正確的說法是。試卷裝訂線A.能帶形式參數(shù)B .函數(shù)體中必須有 delete 語句C.可以被重載D.無形參,也不可重載4. 一個類擁有多個構(gòu)造函數(shù),如此這些構(gòu)造函數(shù)之間為。A.重復(fù)關(guān)系B.拷貝關(guān)系C.重載關(guān)系D.繼承關(guān)系5. C+中聲明常量的關(guān)鍵字是。A. extern B . const Cpublic Dvolatile6. 一個函數(shù)功能不太復(fù)雜,但要求被頻繁調(diào)用,該函數(shù)應(yīng)該設(shè)計成()7.以下基類中的成員函數(shù)表示純虛函數(shù)的是。A. virtual void tt()=0; B. void tt(i nt)=0;C. virtual void tt(in
3、t); D. virtual void tt(int)p的基類成員a,其中a是 。公有繼承的私有成員;私有繼承的公有成員。8. 可以在類外用p.a的形式訪問派生類對象A. 公有繼承的公有成員;BC.公有繼承的保護(hù)成員;D9. 對于任意一個類,析構(gòu)函數(shù)的個數(shù)最多為10. 對于在類中定義的靜態(tài)數(shù)據(jù)成員count,下面正確的說法是A. count在類外進(jìn)展初始化B. 該類的每個對象中都有一個獨立的靜態(tài)數(shù)據(jù)成員cou ntC. 對象創(chuàng)建時產(chǎn)生 countD. count既可以在類外初始化,也可以在類內(nèi)初始化得分B)10、改錯題(共3小題,每一小題6分,共18分)1. error C2440: '
4、;type cast' : cannot convert from 'class plex' to 'float',No user-defined-conversion operator available that can perform this conversion,請指出錯誤原因并改正。#in clude <iostream>using n amespace std;class plexpublic:plex(float r=0,float i=0)real=r; imag=i; void prin t()cout<<
5、39;('<<real<<','<<imag<<')'<<e ndl; private:float real,imag;int mai n() plex a(2.2f,4.4f);a.pri nt();cout<<float (a) *0.5<<e ndl;return 0;2. 下面的程序在 VC6.0 上編譯提示 error C2662:'getX' : cannot convert 'this' pointer from 'c
6、onst class CTest' to 'class CTest &,請指出錯誤原因并改正。#in clude<iostream>using n amespace std;class CTestprivate:int x;public:CTest(i nt x) this->x = x; in t getX() return x; ;int mai n() const CTest obj(5);cout<<obj.getX()<<e ndl;return 0;3. 下面的程序在 VC6.0上編譯無錯,運行結(jié)果出錯:“ p1:葺
7、葺葺葺葺葺葺葺,請指出錯誤原 因并改正。#in clude <iostream>#in clude<cstri ng>using n amespace std;class STRING public:STRING(char *s)ptr= new charstrle n( s)+1;strcpy(ptr,s);STRING()delete ptr; void prin t()cout<<ptr<<e ndl; private:char *ptr;int mai n() STRING p1("book");STRING p2(&
8、quot;pe n");p1=p2;cout<<"p1:"p1.pri nt();return 0;-試卷裝訂線得分讀程序,給出程序的輸出結(jié)果每一小題6分,共24分裝訂線內(nèi)不要答題,不要填寫考生信息試卷裝訂線【1】#include <iostream>using n amespace std;class Pers on public:Pers on() cout<<"C on structor of Pers on"<<en dl; Pers on() cout<<"Dest
9、ructor of Pers on"<<en dl; ;class Stude nt: public Personpublic:Student() cout<<"Constructor of Student"<<endl; Student() cout<<"Destructor of Student"<<endl; ;class Teacher: public Personpublic:Teacher() cout<<"C on structor of Teach
10、er"<<e ndl; Teacher() cout<<"Destructor of Teacher"<<e ndl; ;int mai n()Stude nt s;Teacher t;return 0;-試卷裝訂線裝訂線內(nèi)不要答題,不要填寫考生信息試卷裝訂線2 #i nclude <iostream>using n amespace std;class A public:A (int i) x = i; void dispa () cout << x << "," pri
11、vate :int x ;class B : public A public:B(i nt i) : A(i+10) x = i; void dispb() dispa(); cout << x << en dl; private :int x ;int mai n()B b(2);b.dispb();return 0;【3】 #in clude<iostream.h>class Count static int count ;public:Count( ) cout<<co un t+ ;static int Getc( ) retur n c
12、ount ; Count( ) count- ;int Coun t:co unt = 5;int mai n() Cou nt c1,c2,c3,c4 ;cout<<Co un t:Getc( )<<e ndl; return 0;【4】#include<iostream>using n amespace std;class MyClasspublic:MyClass(int i=0)cout<<1;MyClass(co nst MyClass &x)cout<<2;MyClass & operator=(co ns
13、t MyClass &x)cout<<3; return *this;MyClass()cout<<4;int mai n()MyClass obj1(1),obj2(2),obj3(obj1);obj1=obj2;return 0;得分四、編程題共38分(12 分)1 下面是一個類的測試程序,請設(shè)計出能使用如下測試程序的類。int mai n() Test a;a.i ni t(68,55);a.pri nt();return 0;其執(zhí)行結(jié)果為:測試結(jié)果:68-55=132 請為fraction 類分?jǐn)?shù)類定義如下重載運算符函數(shù)注意函數(shù)原型(12分)加法運算+。
14、賦值運算=提取運算。-試卷裝訂線class fraction private:int fz; /分子int fm; /分母public:;裝訂線內(nèi)不要答題,不要填寫考生信息試卷裝訂線3創(chuàng)建一個表示雇員信息的employee類,其中包含數(shù)據(jù)成員 name empNo和salary ,分別表示雇員的某某、編號和月薪。再從employee類派生出3個類worker、technician和salesman,分別代表普通工人、科研人員、銷售人員。三個類中分別包含數(shù)據(jù)成員 productNum、workHours和monthlysales ,分別代表工人每月生產(chǎn)產(chǎn)品的數(shù)量、科研人 員每月工作的時數(shù)和銷售人
15、員每月的銷售額。要求各類中都包含成員函數(shù)pay,用來計算雇員的月薪,并假定:普通工人的月薪=每月生產(chǎn)的產(chǎn)品數(shù)x每件產(chǎn)品的贏利x20%科研人員的月薪=每月的工作時數(shù)x每小時工作的酬金銷售人員的月薪=月銷售額X銷售額提成。(14分)重點大學(xué)考試試題答案A卷20142015學(xué)年2學(xué)期面向?qū)ο蟪绦蛟O(shè)計課程一、 單項選擇題每一小題2分,共20分CCDCB AAABA二、改錯題洪3小題,每一小題6分,共18分)1. main()函數(shù)第3句出錯,因為類 plex無類類型轉(zhuǎn)換函數(shù),將plex對象轉(zhuǎn)換成float。改正:在plex中類增加:operator float() retur n real; 2. ma
16、in()函數(shù)第2句出錯,因為常對象 obj不能調(diào)用非常成員函數(shù),改正:在 CTest 類中:將 CTest(i nt x)換成 fCTest(i nt x) con st?;蛘邔?mai n()中 con st CTest obj(5);換成 CTest obj(5);3. 當(dāng)程序執(zhí)行對象p2的析構(gòu)函數(shù)時,對象 p1的數(shù)據(jù)成員ptr出現(xiàn)了所謂的“指針懸掛問題,這說明C+中提供應(yīng)對象的默認(rèn)的賦值運算符并不是萬能的,解決的方法就是重載賦值運算符“=,使對象不但能淺拷貝,還能實現(xiàn)深層拷貝。STRING & STRING:operator=(co nst STRING &s)if(th
17、is=&;s)return *this;delete ptr;ptr=new charstrle n( s.ptr)+1;strcpy(ptr,s.ptr);return *this;三、讀程序,給出程序的輸出結(jié)果。每一小題6分,共24分【1 】 Co nstructor of PersonCon structor of Stude ntCon structor of Pers onCon structor of TeacherDestructor of TeacherDestructor of Pers onDestructor of Stude ntDestructor of Pe
18、rs on【2】12,2【3】56789【4】1123444四、編程題共38分=12分+ 12分+14分1. 解答:#include<iostream.h>class Test 4 分 int x,y;public:void in it(i nt,i nt);void prin t();void Test:init(int i,int j) 4 分 x=i;y=j;void Test:print() 4分 cout<<"測試結(jié)果:"<<x<<"-"<<y<<"="
19、<<x-y<<e ndl;2. 解答: fraction operator +(fraction & f1,fraction & f2) 4分int nfz = f1.fz*f2.fm+f1.fm*f2.fz;int nfm = f1.fm*f2.fm;return fractio n(nfz,n fm); fracti on & fraction :operator =(fract ion & f) 4分fz=f.fz;fm=f.fm;return *this; istream & operator >>(istre
20、am & is,fracti on & f) 4分is>>f.fz>>f.fm;return is;3. 解答:#include<iostream>using n amespace std;class employee 4分protected:char n ame20;int empNo;float salary;public:employee(char *cp="李強",int no=1001); employee(employee&);void set name(char *cp);void setempNo(
21、i nt no);void setsalary(float sa);char*get name();int getempNo();float getsalary();void display();employee psalary(employee *emp);employee:employee(char *cp,i nt no) int i=0;while(*cp)n amei=*cp;i+;cp+;namei='0'empN o=no;employee:employee(employee & em) int i=0;while(em. namei)n amei=em
22、.n amei;i+;namei='0:empNo=em.empNo;salary=em.salary;void employee:set name(char *cp) int i=0;while(*cp) n amei=*cp;i+;cp+;namei='0'void employee:setempNo(i nt no)empN o=no;void employee:setsalary(float sa) salary=sa;char*employee:get name() return n ame;int employee:getempNo() return emp
23、No;float employee:getsalary() retur n salary;void employee:display() cout<<"工號為"<<empNo<<"的雇員"<<name<<"的月薪為"<<salary<<endl;employee employee:psalary(employee *emp)if(this->salary>=emp->salary)return *this;elsereturn *em
24、p;class worker : public employeepublic:worker(char*,i nt,i nt);void setproductNum(i nt n) productN um=n;int getproductNum() retur n productNum;void pay();private:int productNum;static float proper;每件產(chǎn)品的利潤;float worker:proper=20;/假設(shè)每件產(chǎn)品的利潤為20元worker:worker(char *n ame,i nt n o,i nt pronum):employee(
25、name ,no)productNum=pr onum;void worker:pay()salary=productNum*proper*0.2;class tech nicia n : public employeepublic:tech nician( char*,i nt,float);void sethours(float h) workHours=h;float gethours() return workHours;void pay();private:float workHours;static float payperhour;科研人員每小時工作的酬金40元;float tech ni cia n:payperhour=40;/假設(shè)科研人員每小時工作的酬金為tech ni cia n:tech nici
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 化工產(chǎn)品批發(fā)商業(yè)務(wù)持續(xù)改進(jìn)考核試卷
- 木竹漿生產(chǎn)過程中的自動化物流系統(tǒng)考核試卷
- 阿里巴巴全球數(shù)學(xué)競賽2024年決賽題目集錦
- 固體飲料的食品安全風(fēng)險評估考核試卷
- 水產(chǎn)品加工過程中的食品安全管理考核試卷
- 毛發(fā)染整行業(yè)職業(yè)技能培訓(xùn)與教育考核試卷
- 冷凍飲品行業(yè)消費群體研究考核試卷
- 毛皮動物養(yǎng)殖技術(shù)與疾病預(yù)防考核試卷
- 木樓梯安全評估與風(fēng)險管理考核試卷
- 衛(wèi)星傳輸技術(shù)在寬帶衛(wèi)星互聯(lián)網(wǎng)的部署考核試卷
- 中國腫瘤藥物治療相關(guān)惡心嘔吐防治專家共識(2022年版)解讀
- 現(xiàn)代家政導(dǎo)論-課件 5.1.1認(rèn)識家政服務(wù)業(yè)
- 2024綠色建筑評價標(biāo)準(zhǔn)
- 商法學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- 幼兒園中班社會活動《警察叔叔你真棒》課件
- 床旁血液凈化治療的原理及應(yīng)用
- 酒店標(biāo)準(zhǔn)間設(shè)計規(guī)范
- 醫(yī)療護(hù)理查對制度課件
- 環(huán)衛(wèi)車輛投標(biāo)方案(技術(shù)方案)
- 高速公路建設(shè)承攬合同
- 20以內(nèi)破十法練習(xí)題-A4打印版
評論
0/150
提交評論