大學(xué)C++期末考試試卷(含答案)_第1頁
大學(xué)C++期末考試試卷(含答案)_第2頁
大學(xué)C++期末考試試卷(含答案)_第3頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、C+突擊題C+突擊題2012-06-08- CBook(分)include #include math.h #inlcude stringclass CBookprivate:char *p_book; public:p_book=new charstrlen(p_val)+1 CBook(const char p_book = new strcpy(p_book, p_val);void print() const cout p_book p;CBook abook(; p_book_obj = 10)include iostream.hclass CJournal public:CJour

2、nal() cout“Journal default constructor”endl; virtual void subscribe() = 0;void read() cout “Read paper” endl; CJournal() coutJournal default destructor” endl;class CComputerDesign : public CJournal public:CComputerDesign) coutComputerDesigndefaultconstructor”endl; virtual void subscribe() cout“Subsc

3、ribing Computer endl; void read() cout “ReadingComputer endl; CComputerDesign() cout “Computer Designdefault destructor” rea(;1。當(dāng)程序運(yùn)行到處時(shí),寫出程序運(yùn)行的輸出結(jié)果 (3 分)2。 當(dāng)程序結(jié)束時(shí),程序會(huì)在第 1 問的基礎(chǔ)上增加哪些輸出. (4 分)3。 若在主函數(shù)中定義一個(gè)對(duì)象 CJournal journal;程序編譯時(shí)會(huì)否出錯(cuò)?為什么?(3 分)四、編程題(40)定義一個(gè)商品類 CGoods,其中包含商品號(hào)(long no)、商品名(char p_name、商

4、品價(jià)格(doubleprice)(10include iostream#include string.husing namespace std; class CCourse private:long no;char float credit; public:CCourse(long no_val,char p_val,float CCourse(const CCourse &r_course;CCourse()delete p_name; void print() const;;CCourse:CCourse(long no_val,char p_val,float no=no_val;p_n

5、ame=new charstrlen(p_val)+1; strcpy(p_name,p_val); credit=credit_val;CCourse:CCourse(const CCourse no=r_course。no;p_name=new charstrlen(r_course.p_name)+1; strcpy(p_name,r_course 。 p_name); credit=r_course.credit;void CCourse:print() constcout”Course number”noendl; cout”Course name”p_nameendl; cout”

6、Course credit”credit2。 為 CGoods 類增加一個(gè)商品總數(shù)( int count)獲取count獲取商品名稱p_name.CGoods1(103。 為 CGoods 類定義小于運(yùn)算符()和不小于運(yùn)算符(=)兩個(gè)運(yùn)算符重載函數(shù).CGoods的值的大小來實(shí)現(xiàn)的(2)(10)4CGoodsCClothesCFood(char 數(shù)(void usedFor()可分別輸出一條表示服裝和食品用途的信息).寫出 CFoodusedFor()成員函數(shù)的實(shí)現(xiàn)).(10)3075)1CGoods(long total_goods)和商品總價(jià)格total_price)getTotalGood

7、s()getTotalPrice(。(注意說明數(shù)據(jù)成員和成員函數(shù)的存儲(chǔ)類型,getTotalGoods()getTotalPrice()這兩個(gè)函數(shù)).為了能夠采用動(dòng)態(tài)聯(lián)編的方式調(diào)用派生類的 usedFor()成員函數(shù),應(yīng)該在 CGoods 類及其派生類CClothesCFood(15)swap,個(gè)數(shù)組元素(通用類型)的數(shù)組采用冒泡排序算法進(jìn)行排序的函數(shù)模板.(15)答案二、include math。h 改為#include ReadingComputer (312。 SubscribingComputer Reading paperComputer default destructor Jou

8、rnal default destructor(全部答對(duì)得 4 分,答錯(cuò)或漏答一條輸出扣 1 分)會(huì)出錯(cuò),因?yàn)镃JournalCJournal(12四、1。 include iostreaminclude string。husing namespace std; class CCourse private:long char float credit;public:C+突擊題C+突擊題2012-06-08- CCourse(long no_val, char *p_val, float CCourse(const CCourse r_cours;CCourse() delete p_name;

9、 void print() const;CCourse::CCourse(long no_val, char *p_val, float credit_val) no = no_val;p_name = new strcpy(p_name, p_val);credit = credit_val;CCoursCCoursconst CCourse no = r_course.no;p_name = new chastrle(r_cours strcpy(p_name, r_course。p_name);credit = r_course.credit;void CCourse::print()

10、constcoutCourse numbernoendl; cout”Course p_nameendl; cout”Course credit = r_course。credit)return true;elsereturn false;(答對(duì)得 3 分)4。class CHLP : public CCourse private:char *p_openby; public:CHLP(longno_val,char p_va,floatcredit_va,char*p_ope):CCours(no_val,p_val, credit_val)p_openby = new charstrlen

11、(p_open)+1; strcpy(p_openby, p_open);CHLP() delete p_openby; void studyFor() cout ”Study for structured programming” endl; ;(531,studyFor(1class COOP : public private:char p_openby; public:COOP(longno_val,charp_va,floatcredit_val,char p_ope): p_val, credit_vap_openby = new strcpy(p_openby, p_open);C

12、OOP() delete p_openby; void studyFor() cout ”Study for object orientedprogramming” endl; ;(答對(duì)得 5 分,其中構(gòu)造函數(shù) 3 分,析構(gòu)函數(shù) 1 分,studyFor()函數(shù) 1 分)五、1。 在 class CCourse 定義中增加一條: public:virtual void cout choice;cout studyFor(); delete p_course;(答對(duì)得 13 分)2.#include iostream using namespace std; template class Tvoid swap(T a, T &b)T temp; temp = a; a = b;b = temp;template class Tvoid bubbleSort(T a, int int i, j;for (i=1; i n; i+) for (j=0; j ni; if ( aj+1) swaa, aj+1;template class T1vo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論