09秋07級(jí)net程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)手冊(cè)_第1頁(yè)
09秋07級(jí)net程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)手冊(cè)_第2頁(yè)
09秋07級(jí)net程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)手冊(cè)_第3頁(yè)
09秋07級(jí)net程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)手冊(cè)_第4頁(yè)
09秋07級(jí)net程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)手冊(cè)_第5頁(yè)
已閱讀5頁(yè),還剩7頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、實(shí)驗(yàn)要求一、可讀性編程高手都知道:一個(gè)好的程序要具備可讀性,可方便自己也可方便別人。所以,要培 養(yǎng)一個(gè)良好的編程習(xí)慣,可注意以下幾方面:1.代碼的縮進(jìn);2.有效使用空格;3.簡(jiǎn)明的注釋;4.意義明確的命名;5.著重表示的常暈。%1. 親手編寫源程序在編寫c#程序過(guò)程中,還可以利用一些可視化的開(kāi)發(fā)工具,它們可以綜合使用c#的編 譯器和調(diào)試器等,例如symantec公司的visual cafes kawas sun公司的c# worshop和c# studio、inprise公司的jbuildcr.微軟的visual j+等,使用編程開(kāi)發(fā)工具可以加快編程 的速度。但在初始學(xué)習(xí)時(shí)還是最好親手編寫源程

2、序,以便理解類和編程思想。三、立即運(yùn)行程序編寫的源程序要立即上機(jī)編譯運(yùn)行來(lái)檢驗(yàn)程序中存衣的問(wèn)題。通過(guò)運(yùn)行的結(jié)杲驗(yàn)證程序 的功能是否實(shí)現(xiàn)。即時(shí)有一些系統(tǒng)類的方法、變量也需要上機(jī)實(shí)驗(yàn)去了解它們的含義。實(shí)驗(yàn)報(bào)告姓名: 學(xué)號(hào):日期:實(shí)驗(yàn)名稱: 成績(jī):一、實(shí)驗(yàn)?zāi)康募耙蠖?、?shí)驗(yàn)環(huán)境windows xp 操作系統(tǒng),visual 2005三、實(shí)驗(yàn)源程序及關(guān)鍵代碼解釋四、實(shí)驗(yàn)調(diào)試過(guò)程及運(yùn)行結(jié)果五、實(shí)驗(yàn)總結(jié):對(duì)上機(jī)實(shí)踐結(jié)果進(jìn)行分析,問(wèn)題回答,上機(jī)的心得體會(huì)及改進(jìn)意 見(jiàn)。實(shí)驗(yàn)一 繼承與多態(tài)編程練習(xí)【實(shí)驗(yàn)?zāi)康摹?. 理解繼承的含義,拿握派生類的定義方法和實(shí)現(xiàn);2. 理解虛函數(shù)在類的繼承層次中的作用,虛函數(shù)的引入對(duì)程

3、序運(yùn)行時(shí)的影響,能夠?qū)?使用虛函數(shù)的簡(jiǎn)單程序?qū)懗龀绦蚪Y(jié)果。3. 編寫體現(xiàn)類的繼承性(成員變量,成員方法,成員變量隱藏)的程序;4. 編寫體現(xiàn)類多態(tài)性(成員方法重載,構(gòu)造方法重載)的程序?!緦?shí)驗(yàn)要求】1. 寫出程序,并調(diào)試程序,要給出測(cè)試數(shù)據(jù)和實(shí)驗(yàn)結(jié)果。2. 整理上機(jī)步驟,總結(jié)經(jīng)驗(yàn)和體會(huì)。3. 完成實(shí)驗(yàn)日志和上交程序?!緦?shí)驗(yàn)內(nèi)容】一、類的繼承和構(gòu)造函數(shù)的靈活應(yīng)用1、編寫一個(gè)學(xué)生和教師數(shù)據(jù)輸入和顯示程序,學(xué)生數(shù)據(jù)有編號(hào)、姓名、班級(jí)和成績(jī),教師 數(shù)據(jù)有編號(hào)、姓名、職稱和部門。要求將編號(hào)、姓名輸入和顯示設(shè)計(jì)成-個(gè)類person,并作 為學(xué)生數(shù)據(jù)操作類student和教師類數(shù)據(jù)操作類teacher的基類

4、。二、類的多態(tài)性練習(xí)雇員系統(tǒng),定義雇員基類,共同的屬性,姓名、地址和出牛h期,子類:程序員,秘書, 高層管理,淸潔工,他們有不同的工資算法,其中髙級(jí)主管和程序員采用底薪加提成的方式, 高級(jí)主管和程序員的底薪分別是500()元和2000元,秘書和清潔工采川工資的方式,工資 分別是3()(x)和1000,以多態(tài)的方式處理程序,要求主程序的多態(tài)變量部分川數(shù)組實(shí)現(xiàn)。實(shí)驗(yàn)二操作符重載編程練習(xí)【實(shí)驗(yàn)?zāi)康摹?. 了解操作符重載的意義,掌握操作符重載的一般方法。2. 理解操作符對(duì)的重載實(shí)現(xiàn),編寫相應(yīng)的程序?!緦?shí)驗(yàn)要求】1. 寫岀程序,并調(diào)試程序,要給出測(cè)試數(shù)據(jù)和實(shí)驗(yàn)結(jié)果。2. 整理上機(jī)步驟,總結(jié)經(jīng)驗(yàn)和體會(huì)。3

5、. 完成實(shí)驗(yàn)日志和上交程序。【實(shí)驗(yàn)內(nèi)容】1、定義一個(gè)complex類,在類中實(shí)現(xiàn)“ + ”運(yùn)算符的重載,從鍵盤上輸入兩個(gè)復(fù)數(shù),用“ + ” 實(shí)現(xiàn)兩個(gè)復(fù)數(shù)的加法。實(shí)驗(yàn)三接口編程練習(xí)【實(shí)驗(yàn)?zāi)康摹?. 了解什么是接口,接口和抽象類的異同,掌握接口的方法實(shí)現(xiàn),接口方法的重定義。【實(shí)驗(yàn)要求】1. 寫出程序,并調(diào)試程序,要給出測(cè)試數(shù)據(jù)和實(shí)驗(yàn)結(jié)果。2. 整理上機(jī)步驟,總結(jié)經(jīng)驗(yàn)和體會(huì)。3. 完成實(shí)驗(yàn)日志和上交程序。【實(shí)驗(yàn)內(nèi)容】一、分析實(shí)現(xiàn)接口的程序文件分析以下實(shí)現(xiàn)接口的程序文件并冋答問(wèn)題: 本程序中的接口包含方法的構(gòu)成是哪些; 實(shí)現(xiàn)接口的類包含哪些元素? 類實(shí)現(xiàn)接11方法的參數(shù)如何變換實(shí)現(xiàn)的? 給出程序的輸出

6、結(jié)果。 代碼如下:using system;public interface 1comparableint compareto(1comparable comp);public class timespan : tcomparableprivate uint lotalseconds;public timespan() totalseconds = 0;public timespan(uint initislseconds) totalseconds = initialseconds;public uint secondsgetreturn totalseconds;settotalsecon

7、ds = value;public int compareto(icomparable comp) timespan comparetime = (timespan) comp;if(totalseconds > comparetime. seconds) return 1;else if(comparetime.seconds = totalseconds) return 0;elsereturn t;class testerpublic static void main()timespan mytime = new timespan(3450);timespan worldrecor

8、d = new timespan(1239);if(mytimecompareto(worldrocord) < 0)console- writelinec'my time is below the world record'7);else if(mytime- compareto(worldrecord) = 0)console- writelinec'my time is the same as the world record''); elsecon sole. wri teline (,zt spe nt more time tha n t

9、he world record holder"); 實(shí)驗(yàn)四異常處理編程練習(xí)【實(shí)驗(yàn)?zāi)康摹?. 理解什么是異常及異??赡墚a(chǎn)生的原因;2. 掌握杲常拋岀和捕獲語(yǔ)句;3理解專有catch塊的使用;【實(shí)驗(yàn)要求】1. 調(diào)試程序,要給出測(cè)試數(shù)據(jù)和實(shí)驗(yàn)結(jié)果。2. 整理上機(jī)步驟,總結(jié)經(jīng)驗(yàn)和體會(huì)。3. 完成實(shí)驗(yàn)h志和上交程序。【實(shí)驗(yàn)內(nèi)容】一、異常處理部分建立一個(gè)名字為meteorologist的類,其屮含有一個(gè)12個(gè)int類型元素的數(shù)組rainfall,通 過(guò)構(gòu)造函數(shù)給賦值;一個(gè)方法頭為public int getrainfall(int index),此方法返回rainfall元素 中與給定得inde

10、x對(duì)應(yīng)的值。在getrainfall添加處理任何從getrainfall方法中拋出的越界異 常所需要的代碼;讀取每月降雨從空中吸收并帶到地血得污染物,在類中添加數(shù)組pollution, 也包含12個(gè)元索,在構(gòu)造方法中賦任意值;編寫一個(gè)方法,頭為:public intgetaveragcpollution(int index),來(lái)計(jì)算給定月份單位降雨量中的污染物,例如,計(jì)算4 m 份單位降雨量所含污染物用以下計(jì)算來(lái)實(shí)現(xiàn): averagepollution=pollutin3/rainfall 3;實(shí)現(xiàn)處理異常的代碼,注意,此方法既可以 拋出索引越界異常,也可以拋出被0除異常;假定getavera

11、gepollutin方法在執(zhí)行中打開(kāi) 了一個(gè)文件,此文件必須在方法退出前關(guān)閉。編寫實(shí)現(xiàn)的代碼,用下列語(yǔ)句關(guān)閉文件 console. writeline(<4closing weatherxyz file”);最好編寫測(cè)試代碼。實(shí)驗(yàn)五委托與事件編程練習(xí)【實(shí)驗(yàn)?zāi)康摹?. 了解委托的概念,掌握委托的使用;2. 掌握多重委托應(yīng)用;3. 理解事件的含義,掌握事件的使用;【實(shí)驗(yàn)要求】1. 理解委托和事件應(yīng)用的程序;2. 寫出委托和事件應(yīng)用程序;3. 調(diào)試程序,要給出測(cè)試數(shù)據(jù)和實(shí)驗(yàn)結(jié)果。4. 整理上機(jī)步驟,總結(jié)經(jīng)驗(yàn)和體會(huì)。5. 完成實(shí)驗(yàn)日志和上交程序。【實(shí)驗(yàn)內(nèi)容】%1. 委托及其方法的實(shí)現(xiàn)程序程序功能

12、:定義一個(gè)含有兩個(gè)整型參數(shù)名叫calculation返回類型為double的委托,分別 實(shí)現(xiàn)兩個(gè)匹配的求和、求平均值的方法,并在主函數(shù)中測(cè)試它。二、一個(gè)事件驅(qū)動(dòng)汽車游戲分析以下程序回答問(wèn)題: 事件和多重委托的區(qū)別? 程序中類之i'可的功能關(guān)系? car類對(duì)事件的應(yīng)用方式有哪些?car類如何實(shí)現(xiàn)對(duì)事件的預(yù)定使用?using system;enum moverequesttype fastforward, siowforward, reverse;class moverequesteventargs : eventargsprivate moverequesttype request;pu

13、blic moverequesteventargs (moverequesttype initrequest) : base ()request = initrequest;public moverequesttype requestgetreturn request;class gamecontrol1 erpublic delegate void moverequest(object sender, moverequesteventargs e);public event moverequest onmoverequest;car gamecars = new car10;string c

14、arname:int speedparam = 0;int carcounter = 0;int carnumber = 0;public void run()stri ng answer;consol e. wr it el,i ne ("please sei ect from the fol 1 owl ng menu: “);consolewriteline(a)dd new car");consolewriteline(c)ar. subscribe to events");con sole writel in e (unsubscribe from ev

15、e nts");console. writeline(z/l) ist cars in current game");console. writelineczf)ast forward7');console. writeline("s)low forwardz/);console writeline(r)everse);console writeline(,t)erminatez,);docon sol e< wri tel in e("select new option:,z); answer = console. readline().

16、 toupper ();switch(answer)case a :console. write(/zenter name of the new car: “); car name = console. readlineo ;console. write (''enter car speed parameter of the new car: “); speedparam = convert. totnt32(console. readline(); gamecarscarcounter = new car (speedparam, carname); carcounter+;

17、break;八case c :console .write("enter array index of car you want to subscribe to events: “);carnumber = convert. toint32(console.readli ne (); gamecarscarnumber. subscribe (this);break;case u :con sole wri te ("enter array in dex of car you wa nt to unsubscribe from events: “);carnumber =

18、convert. tolnt32 (c on sole- readlineo); gamecarscarnumber. unsubscribe(this);break;t case l :for(int i=0; i < carcounter; i+)console- writeline(gamecarsi);break;廠case 卜:if (onmoverequest != nul1) onmoverequest (this, newmoverequesteventargs(moverequesttype fastforward);break;case s :if (onmovere

19、quest != null) onmoverequest(this, newmoverequesteventargs(moverequesttype. slowforward);break;門case r :if (onmoverequest != null)onmoverequest(this, new moverequesteventargs(moverequesttype. reverse);break;fcase t :break;default:console.writeline("invalid choice please try again); break; while

20、(answer != "t");class carprivate int distance;private int speedparam;private string name;public car(int initspeedparam, string initname)speedparam = initspeedparam;distance = 0;name 二 initname;public voicl subscribe(gamecontroller controller)controller. onmovcrcqucst +二 new gamecontroller

21、moverequest (moverequesthandler);publi c voi d unsubscribe(gamecontrol1 er control 1 er)controller onmoverequest -二 new gamecontroller moverequest(moverequesthandler);public void moverequesthandler(object sender, moverequesteventargs e)swi tch (e. request)case moverequesttype slowforward:distance +二

22、 speedparam;console. writeline(,?car name: " + name + " moving slowly. distance: "+ distance);break;case moverequesttype. fastforward:distance +二 speedparam * 2;consolewriteline("car name: " + name + " moving fast distanee: "+ distance);break;case moverequesttype.r

23、everse:distance 一二 5;con sole. writ eline (z,car name: " + n ame + reversi ng. dis tance:" + distanee);break;publ ic override string tostringoreturn name;class testerpublic static void main()gamecontroller control 1 er = new gamecontroller(); controller. run();實(shí)驗(yàn)六數(shù)組編程練習(xí)【實(shí)驗(yàn)?zāi)康摹?. 了解數(shù)組的概念,掌握數(shù)組的聲明、初始化方式;2. 熟練拿握f(shuō)or each語(yǔ)句的川法,理解params關(guān)鍵字的使川;4. 掌握數(shù)組轉(zhuǎn)換方法的使用;5. 理解索引器的概念,掌握在整數(shù)索引和在字符串上索引的應(yīng)用;【實(shí)驗(yàn)要求】1. 調(diào)試程序,要給出測(cè)試數(shù)據(jù)和實(shí)驗(yàn)結(jié)果。2. 整理上機(jī)步驟,總結(jié)經(jīng)驗(yàn)和體會(huì)。3. 完成實(shí)驗(yàn)日志和上交程序。【實(shí)驗(yàn)內(nèi)容】數(shù)組和循環(huán)語(yǔ)句的結(jié)合應(yīng)用程序功能要求

溫馨提示

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

評(píng)論

0/150

提交評(píng)論