下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、 裝 訂 線 西安工業(yè)大學(xué)試題紙學(xué)年學(xué)期20092010學(xué)年第一學(xué)期課程名稱 面向?qū)ο蠹夹g(shù)與C+ A卷/B卷命題教師審 批考試形式開卷/閉卷考試類型考試/考查使用班級070601、02、03、09、10考試時間2009.12.22 1:303:30考試地點C101、C102學(xué)生班級姓 名學(xué) 號備 注一、程序填空題(共5題,每空2分,共30分)2、#include class p_class int num ; public : void set_num ( int val ) num = val ; void show_num ( ) ; ; void p_class : show_num (
2、 ) cout num t ; void main ( ) p_class ob3 , * p ; for(int i = 0; i show_num ( ) ; _(4)_; p - show_num ( ) ; _(5)_; p - show_num ( ) ; 輸出: 20 30 101、#include class A _(1)_ void f(int i)coutit; void g()coutgn; ; class B:private A public: void h()couthn; _(2)_ ; void main() B d; d.f(6); d.h(); 輸出: 6 h3
3、、#include class Tdate int month ; int day ; int year ; int IsLeapYear() return(year%4=0&year%100!=0)|(year%400=0); _(6)_ void Set (int m, int d, int y) month=m; day=d; year=y; _(7)_; ; _(8)_Print() cout month / day / yearendl ; if(IsLeapYear()coutThis year Is leapyear.n ; else coutThis year Is not l
4、eapyear.n; void main() Tdate a ; a.Set ( 2, 4, 2000 ) ; a.Print() ; 3、#include class Base1 public: Base1( int i ) cout Base1 construct i endl ; ; class Base2 public: Base2( int j ) cout Base2 construct j endl ; ; class A: public Base1, public Base2 public: A( int a, int b, int c, int d ) : Base2(b),
5、 Base1(c), b2(a), b1(d) coutA construct: a+b+c+d endl; private: Base1 b1; Base2 b2; ; void main() A obj( 1, 2, 3, 4 ); 2、#include class test private: int num; public: test( ); int geint( )return num; test( ); ; test : test( ) cout constructor is active! endl; num=0; test: test( ) cout Destructor is
6、active! endl; void main( ) test x2; cout Exiting main endl; 4、#include class Location public: Location( int xx = 0 , int yy = 0 ) X = xx ; Y = yy ; cout Constructor Object.n ; Location( Location & p ) /復(fù)制構(gòu)造函數(shù) X = p.X ; Y = p.Y ; cout Copy_constructor called. endl ; Location() cout X , Y Object destr
7、oyed. endl ; int GetX () return X ; int GetY () return Y ; private : int X , Y ; ;void f ( Location p ) cout Funtion: p.GetX() , p.GetY() endl ; void main() Location A ( 1, 2 ) ; f ( A ) ;5、#include iostream.h#includestdlib.hclass ARRAY int *v; /指向存放數(shù)組數(shù)據(jù)的空間 int s; /數(shù)組大小 public: ARRAY(int a, int n);
8、ARRAY()delete v; int size() return s; int& operator(int n); ;ARRAY: ARRAY(int a, int n) if(n=0) v=NULL;s=0;return; s=n; v=_(12)_; for(int i=0; in; i+) _(13)_;_(14)_ operator(int n) / 的運算符成員函數(shù)定義if(n=s) cerr下標(biāo)越界!; exit(1); return _(15)_;4、#include class Time public: Time(int h, int m) hours=h; minutes
9、=m; void Time12(); _(9)_ Time24(Time time); private: int hours, minutes; ; _(10)_ Time12() if(hours12) couthours-12:minutesPMn ; else couthours:minutesAMn ; void Time24(Time time) cout_(11)_ void main() Time T1(20,30), T2(10,45); T1.Time12(); Time24(T1); T2.Time12(); Time24(T2); 輸出: 8:30PM 20:30 10:
10、45AM 10:45二、寫出程序的運行結(jié)果(共7題,每題5分,共35分)1、#include int f (int a 3 ,int row,int col) int i,j,t= 1;for(i=0;irow;i+) for(j=0;jcol;j+) aij+; if (i=j) t*=aij; return t; void main() int a 3=0,1,2,3,4,5,6,7,8;coutf(a,3,3)endl; 7、#include class Bclass public: Bclass( int i, int j ) x = i; y = j; virtual int fun
11、() return 0 ; int getx()return x; int gety()return y; protected: int x, y ; ; class Iclass:public Bclass public : Iclass(int i, int j, int k):Bclass(i, j) z = k; int fun() return ( x + y + z ) / 3; int getz()return z; private : int z ; ;void main() Iclass obj( 2, 4, 10 ); Bclass p1 = obj; cout p1.fu
12、n() endl; Bclass & p2 = obj ; cout p2.fun() endl; cout p2.Bclass : fun() endl; Bclass *p3 = &obj; cout fun() endl; coutgetz()endl; 5、#includeclass A public:A( ) coutcall A( )n; virtual A( ) coutcall A( )n; ;class B:public A char* buf;public:B( ) buf=new char100; coutcall B( )n; B( ) delete buf; coutcall B( )n; ;void main( ) A *p=new B; delete p; 6、#include iostream.hvoid main() int a33=1,2,3,4,5,6,7,8,9; cout*(a1+2);三 編程題(1、2每小題10分,第3題15分,共35分):1、 用面向?qū)ο蟮姆椒ǎ幊虒崿F(xiàn)求100300以內(nèi)的所有素數(shù)。2、利用靜態(tài)數(shù)據(jù)成員的概念,編寫一個類,可以統(tǒng)計目前存在多少個該類的對象,并在主程序中使用這個類。3、 定義一個字符
溫馨提示
- 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)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 安全、環(huán)境事故報告制度
- 廠房除塵清掃制度
- 華為的項目經(jīng)理制度
- 礦山地質(zhì)環(huán)境監(jiān)測系統(tǒng)方案
- 礦山地下水保護與管理方案
- 中醫(yī)院職工培訓(xùn)體系建設(shè)方案
- 小學(xué)水電系統(tǒng)改造方案
- 2025-2030中國男士襯衫行業(yè)前景預(yù)測與投資戰(zhàn)略規(guī)劃研究研究報告
- 儲備糧倉庫運行管理優(yōu)化方案
- 標(biāo)準(zhǔn)化廠房項目管理軟件應(yīng)用方案
- 北京市順義區(qū)2025-2026學(xué)年八年級上學(xué)期期末考試英語試題(原卷版+解析版)
- 中學(xué)生冬季防溺水主題安全教育宣傳活動
- 2026年藥廠安全生產(chǎn)知識培訓(xùn)試題(達標(biāo)題)
- 初中九年級上一元二次方程計算練習(xí)題及答案詳解B2
- 冷庫防護制度規(guī)范
- 2026年生產(chǎn)管理崗入職性格測試題及答案
- 廣東省廣州市番禺區(qū)2026屆高一數(shù)學(xué)第一學(xué)期期末聯(lián)考試題含解析
- 2026年廣東省佛山市高三語文聯(lián)合診斷性考試作文題及3篇范文:可以“重讀”甚至“重構(gòu)”這些過往
- 2025年汽車駕駛員技師考試試題及答案含答案
- 觀看煤礦警示教育片寫心得體會
- 2025年國際中文教師證書考試真題附答案
評論
0/150
提交評論