net程序設(shè)計實驗指導(dǎo)_第1頁
net程序設(shè)計實驗指導(dǎo)_第2頁
net程序設(shè)計實驗指導(dǎo)_第3頁
net程序設(shè)計實驗指導(dǎo)_第4頁
net程序設(shè)計實驗指導(dǎo)_第5頁
已閱讀5頁,還剩40頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、實驗一 簡單程序設(shè)計1熟悉visual studio.net的ide界面,練習(xí)窗口的浮動、??浚约肮ぞ邫诘亩ㄖ?。2模仿書中的例子,編寫“hello”程序。3學(xué)會使用幫助系統(tǒng),在編寫程序時使“動態(tài)幫助”始終打開,注意觀察“動態(tài)幫助”窗口中內(nèi)容的變化。4在“幫助”菜單下選擇“對幫助的幫助”,閱讀其中的內(nèi)容,學(xué)習(xí)幫助的使用。/ this is our first example: c# version hello world!using system;class helloworldpublic static void main()console.writeline(hello world!);實

2、驗二 c#.net面向?qū)ο蟪绦蛟O(shè)計實驗1為某公司創(chuàng)建一個類來建立員工的人事記錄:包括員工的姓名、性別、工資、到公司的日期、部門以及聯(lián)系方式等信息。構(gòu)建該類,并做出適當(dāng)?shù)臏y試。2從上面的類中派生出一個類,來記錄公司干部的情況。包括職位、提職時間、管理的員工人數(shù)及姓名。3編寫程序,使得一個大學(xué)書店可以用它來記錄和確定教科書的零售價。所有計算應(yīng)該用一個類textbook的實例來完成。這個類應(yīng)該具有屬性title(書名)、author(作者)、cost(批發(fā)費用)、quantity(庫存量)和price(零售價)。同時假設(shè)零售價是批發(fā)價的1.25倍。4編寫程序相加兩個分?jǐn)?shù),并將它們的和以化簡后的分?jǐn)?shù)形

3、式表現(xiàn)出來。程序使用類fraction來存放分?jǐn)?shù)的分子和分母,具有方法reduce來化簡結(jié)果。using system;namespace testclassapp/ / class1 的摘要說明。/ class class1/ / 應(yīng)用程序的主入口點。/ stathreadstatic void main(string args)/ todo: 在此處添加代碼以啟動應(yīng)用程序/double len = 2.5;double wid = 3.0;double rad = 4.1;rectangle arect = new rectangle();arect.length = len;arect.

4、width = wid;circle acirc = new circle (rad);console.writeline (area of rect is:0,arect.area ();console.writeline (area of circ is:0,acirc.area ();abstract class shape/抽象基類,不可實例化public const double pi=3.14;/常量protected double x, y;/私有,可繼承變量public shape()/默認(rèn)構(gòu)造函數(shù)x=y=0;public shape(double x,double y)/帶參

5、數(shù)構(gòu)造函數(shù)this.x = x;this.y = y;public abstract double area();/抽象方法,需重載class rectangle: shapepublic rectangle():base()public rectangle(double x, double y): base(x,y)/使用基類構(gòu)造函數(shù)public override double area()/函數(shù)重載return (x*y);public double length/屬性:矩形長度getreturn x;setif (value0)x = value;public double width/

6、屬性:矩形寬度getreturn y;setif (value0)y = value;class ellipse: shapepublic ellipse(double x, double y):base(x,y)/使用基類shape的構(gòu)造函數(shù)public override double area()/函數(shù)重載return pi*x*y;class circle: ellipsepublic circle(double r):base(r,0)/使用基類ellipse的構(gòu)造函數(shù)public override double area()/函數(shù)重載return pi*x*x;實驗三 文本編輯器設(shè)計

7、1假設(shè)有要排序的20個數(shù)存在文件data.txt中。編寫程序,打開該文件并將排好序的數(shù)重新寫回該文件。2重新打開第1題創(chuàng)建的文件,在文件的結(jié)尾再添加10個隨機數(shù)。3參考windows的記事本程序,編寫一個簡單的文本編輯器程序。using system;using system.drawing;using system.collections;using system.componentmodel;using system.windows.forms;using system.data;namespace editerapp/ / form1 的摘要說明。/ public class form1

8、 : system.windows.forms.formprivate system.windows.forms.mainmenu mainmenu1;private system.windows.forms.menuitem menuitem1;private system.windows.forms.menuitem menuitem2;private system.windows.forms.menuitem menuitem3;private system.windows.forms.menuitem menuitem4;private system.windows.forms.men

9、uitem menuitem5;private system.windows.forms.menuitem menuitem6;private system.windows.forms.menuitem menuitem7;private system.windows.forms.openfiledialog openfiledialog1;private system.windows.forms.savefiledialog savefiledialog1;private system.windows.forms.richtextbox myrtbox; private system.win

10、dows.forms.statusbar mystatus; private icontainer components;public form1()/ windows 窗體設(shè)計器支持所必需的/initializecomponent();/ todo: 在 initializecomponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼/ / 清理所有正在使用的資源。/ protected override void dispose( bool disposing )if( disposing )if (components != null) components.dispose();base.dispos

11、e( disposing );#region windows form designer generated code/ / 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改/ 此方法的內(nèi)容。/ private void initializecomponent() ponents = new system.componentmodel.container(); this.myrtbox = new system.windows.forms.richtextbox(); this.mystatus = new system.windows.forms.statusbar(); this.main

12、menu1 = new system.windows.forms.mainmenu(ponents); this.menuitem1 = new system.windows.forms.menuitem(); this.menuitem3 = new system.windows.forms.menuitem(); this.menuitem2 = new system.windows.forms.menuitem(); this.menuitem4 = new system.windows.forms.menuitem(); this.menuitem5 = new system.wind

13、ows.forms.menuitem(); this.menuitem6 = new system.windows.forms.menuitem(); this.menuitem7 = new system.windows.forms.menuitem(); this.openfiledialog1 = new system.windows.forms.openfiledialog(); this.savefiledialog1 = new system.windows.forms.savefiledialog(); this.suspendlayout(); / / myrtbox / th

14、is.myrtbox.dock = system.windows.forms.dockstyle.fill; this.myrtbox.location = new system.drawing.point(0, 0); this.myrtbox.name = myrtbox; this.myrtbox.size = new system.drawing.size(292, 273); this.myrtbox.tabindex = 0; this.myrtbox.text = ; / / mystatus / this.mystatus.location = new system.drawi

15、ng.point(0, 251); this.mystatus.name = mystatus; this.mystatus.size = new system.drawing.size(292, 22); this.mystatus.tabindex = 1; this.mystatus.text = 新建文件; / / mainmenu1 / this.mainmenu1.menuitems.addrange(new system.windows.forms.menuitem this.menuitem1, this.menuitem7); / / menuitem1 / this.men

16、uitem1.index = 0; this.menuitem1.menuitems.addrange(new system.windows.forms.menuitem this.menuitem3, this.menuitem2, this.menuitem4, this.menuitem5, this.menuitem6); this.menuitem1.text = 文件(&f); / / menuitem3 / this.menuitem3.index = 0; this.menuitem3.text = 新建(&n); this.menuitem3.click += new sys

17、tem.eventhandler(this.menuitem3_click); / / menuitem2 / this.menuitem2.index = 1; this.menuitem2.text = 打開(&o); this.menuitem2.click += new system.eventhandler(this.menuitem2_click); / / menuitem4 / this.menuitem4.index = 2; this.menuitem4.text = 保存(&s); this.menuitem4.click += new system.eventhandl

18、er(this.menuitem4_click); / / menuitem5 / this.menuitem5.index = 3; this.menuitem5.text = -; / / menuitem6 / this.menuitem6.index = 4; this.menuitem6.text = 退出(&x); this.menuitem6.click += new system.eventhandler(this.menuitem6_click); / / menuitem7 / this.menuitem7.index = 1; this.menuitem7.text =

19、關(guān)于(&a); / / openfiledialog1 / this.openfiledialog1.filter = text files(*.txt)|*.txt|rich text format files(*.rtf)|*.rtf|all files(*.*)|*.*; / / savefiledialog1 / this.savefiledialog1.filename = doc1; this.savefiledialog1.filter = text files(*.txt)|*.txt|rich text format files(*.rtf)|*.rtf|all files(

20、*.*)|*.*; / / form1 / this.autoscalebasesize = new system.drawing.size(6, 14); this.clientsize = new system.drawing.size(292, 273); this.controls.add(this.mystatus); this.controls.add(this.myrtbox); this.menu = this.mainmenu1; this.name = form1; this.text = editorapp; this.resumelayout(false);#endre

21、gion/ / 應(yīng)用程序的主入口點。/ stathreadstatic void main() application.run(new form1();private void checksave()if (myrtbox.text != )if (messagebox.show (是否保存當(dāng)前文件?,確認(rèn) ,messageboxbuttons.okcancel ) = dialogresult.ok )mysavefile();private void mynewfile()checksave(); /檢查是否保存當(dāng)前文件myrtbox.clear ();mystatus.text = 新建

22、文件;private void mysavefile()mystatus.text = 保存文件;if (savefiledialog1.showdialog () = dialogresult.ok )myrtbox.savefile (savefiledialog1.filename );private void myopenfile()checksave(); /檢查是否保存當(dāng)前文件if (openfiledialog1.showdialog () = dialogresult.ok )myrtbox.loadfile (openfiledialog1.filename ,richtex

23、tboxstreamtype.plaintext );mystatus.text = 打開文件;private void myexit()checksave(); /檢查是否保存當(dāng)前文件application.exit ();private void menuitem3_click(object sender, system.eventargs e)mynewfile(); /新建文件private void menuitem2_click(object sender, system.eventargs e)myopenfile();/打開文件private void menuitem4_cl

24、ick(object sender, system.eventargs e)mysavefile();/保存文件private void menuitem6_click(object sender, system.eventargs e)myexit();/退出程序4編寫程序,在用戶選擇了一個目錄后,找出該目錄及其子目錄中所有后綴名為doc的文件。using system;using system.drawing;using system.collections;using system.componentmodel;using system.windows.forms;using syste

25、m.data;using system.io;namespace filemanagerapp/ / form1 的摘要說明。/ public class form1 : system.windows.forms.formprivate system.windows.forms.treeview dirtree;private system.windows.forms.splitter splitter1;private system.windows.forms.listview filelist;private system.windows.forms.mainmenu mainmenu1;

26、private system.windows.forms.menuitem menuitem1;private system.windows.forms.menuitem menuitem2;private system.windows.forms.menuitem menuitem3;private system.windows.forms.menuitem menuitem4;private system.windows.forms.menuitem menuitem5;private system.windows.forms.menuitem menuitem6;private syst

27、em.windows.forms.menuitem menuitem7;/ / 必需的設(shè)計器變量。/ private system.componentmodel.container components = null;public form1()/ windows 窗體設(shè)計器支持所必需的/initializecomponent();/ todo: 在initializecomponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼/treenode mycomputernode = new treenode (我的電腦);dirtree.nodes.add (mycomputernode);filelists

28、how(mycomputernode);/初始化listview控件private void filelistshow(treenode adirnode)filelist.clear ();tryif (adirnode.parent = null)foreach (string drvname in directory.getlogicaldrives ()listviewitem aitem = new listviewitem(drvname);filelist.items.add (aitem);elseforeach(string dirname in directory.getd

29、irectories (string)adirnode.tag )listviewitem aitem = new listviewitem(dirname);filelist.items.add (aitem);foreach(string filename in directory.getfiles (string)adirnode.tag )listviewitem aitem = new listviewitem(filename);filelist.items.add (aitem);catchprivate void filelistshow(string adirname)fil

30、elist.clear ();tryforeach(string dirname in directory.getdirectories (adirname )listviewitem aitem = new listviewitem(dirname);filelist.items.add (aitem);foreach(string filename in directory.getfiles (adirname)listviewitem aitem = new listviewitem(filename);filelist.items.add (aitem);catchprivate vo

31、id dirtreeshow( treenode adirnode )tryif (adirnode.nodes.count = 0)if (adirnode.parent = null)foreach (string drvname in directory.getlogicaldrives ()treenode anode = new treenode(drvname);anode.tag = drvname;adirnode.nodes.add (anode);else foreach (string dirname in directory.getdirectories(string)

32、adirnode.tag )treenode anode = new treenode (dirname);anode.tag = dirname;adirnode.nodes.add (anode);catch/ / 清理所有正在使用的資源。/ protected override void dispose( bool disposing )if( disposing )if (components != null) components.dispose();base.dispose( disposing );#region windows form designer generated c

33、ode/ / 設(shè)計器支持所需的方法- 不要使用代碼編輯器修改/ 此方法的內(nèi)容。/ private void initializecomponent()this.dirtree = new system.windows.forms.treeview();this.splitter1 = new system.windows.forms.splitter();this.filelist = new system.windows.forms.listview();this.mainmenu1 = new system.windows.forms.mainmenu();this.menuitem1 =

34、 new system.windows.forms.menuitem();this.menuitem6 = new system.windows.forms.menuitem();this.menuitem2 = new system.windows.forms.menuitem();this.menuitem3 = new system.windows.forms.menuitem();this.menuitem4 = new system.windows.forms.menuitem();this.menuitem5 = new system.windows.forms.menuitem(

35、);this.menuitem7 = new system.windows.forms.menuitem();this.suspendlayout();/ / dirtree/ this.dirtree.dock = system.windows.forms.dockstyle.left;this.dirtree.imageindex = -1;this.dirtree.name = dirtree;this.dirtree.selectedimageindex = -1;this.dirtree.size = new system.drawing.size(121, 273);this.di

36、rtree.tabindex = 0;this.dirtree.afterselect += new system.windows.forms.treevieweventhandler(this.dirtree_afterselect);/ / splitter1/ this.splitter1.location = new system.drawing.point(121, 0);this.splitter1.name = splitter1;this.splitter1.size = new system.drawing.size(3, 273);this.splitter1.tabind

37、ex = 1;this.splitter1.tabstop = false;/ / filelist/ this.filelist.dock = system.windows.forms.dockstyle.fill;this.filelist.location = new system.drawing.point(124, 0);this.filelist.multiselect = false;this.filelist.name = filelist;this.filelist.size = new system.drawing.size(168, 273);this.filelist.

38、tabindex = 2;this.filelist.view = system.windows.forms.view.list;this.filelist.doubleclick += new system.eventhandler(this.filelist_doubleclick);this.filelist.selectedindexchanged += new system.eventhandler(this.filelist_selectedindexchanged);/ / mainmenu1/ this.mainmenu1.menuitems.addrange(new syst

39、em.windows.forms.menuitem this.menuitem1, this.menuitem2, this.menuitem7);/ / menuitem1/ this.menuitem1.index = 0;this.menuitem1.menuitems.addrange(new system.windows.forms.menuitem this.menuitem6);this.menuitem1.text = 文件(&f);/ / menuitem6/ this.menuitem6.index = 0;this.menuitem6.text = exit;this.m

40、enuitem6.click += new system.eventhandler(this.menuitem6_click);/ / menuitem2/ this.menuitem2.index = 1;this.menuitem2.menuitems.addrange(new system.windows.forms.menuitem this.menuitem3, this.menuitem4, this.menuitem5);this.menuitem2.text = 編輯(&e);/ / menuitem3/ this.menuitem3.index = 0;this.menuit

41、em3.shortcut = system.windows.forms.shortcut.ctrlc;this.menuitem3.text = 復(fù)制;this.menuitem3.click += new system.eventhandler(this.menuitem3_click);/ / menuitem4/ this.menuitem4.index = 1;this.menuitem4.shortcut = system.windows.forms.shortcut.ctrlv;this.menuitem4.text = 粘貼;this.menuitem4.click += new

42、 system.eventhandler(this.menuitem4_click);/ / menuitem5/ this.menuitem5.index = 2;this.menuitem5.shortcut = system.windows.forms.shortcut.ctrlx;this.menuitem5.text = 剪切;/ / menuitem7/ this.menuitem7.index = 2;this.menuitem7.text = 關(guān)于(&a);/ / form1/ this.autoscalebasesize = new system.drawing.size(6

43、, 14);this.clientsize = new system.drawing.size(292, 273);this.controls.addrange(new system.windows.forms.control this.filelist, this.splitter1, this.dirtree);this.menu = this.mainmenu1;this.name = form1;this.text = filemanagerapp;this.resumelayout(false);#endregion/ / 應(yīng)用程序的主入口點。/ stathreadstatic void main() application.run(new form1();private void dirtree_afterselect(object sender, system.windows.forms.treevieweventargs e)filelistshow( e.node );dirtreeshow( e.node );private void filelist_doubleclick(object sender, system.eventargs e)foreach (int listindex in filelis

溫馨提示

  • 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論