



版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、c#基礎編程設計實驗報告 c# 基礎編程 設計實驗報告 一、實驗目的 1、熟悉 visual studio .net 開發環境。 2、掌握 c#應用程序的基本操作過程。 3、掌握 c#的數據類型,運算符以及表達式的使用。 4、掌握分支和循環語句的使用方法。 5、掌握一維數組,二維數組及數組型數組的使用。 二、實驗要求 (1)編寫程序要規范、正確,上機調試過程和結果要有記錄 (2)做完實驗后給出本實驗的實驗報告。 三、實驗設備、環境 安裝有 visual studio .net 軟件。 四、實驗步驟 1、分析題意。 2、根據題目要求,新建項目。 3、編寫并輸入相關的程序代碼。 5、運行與調試項目
2、。 6、保存項目。 五、實驗內容 1、編寫一個簡單的控制臺應用程序,打印一行文字(如你的姓名)。 using system; using system.collections.generic; using system.linq; using system.text; namespace one.first class program static void main(string args) system.console.writeline(quot;我叫王蕾!quot;); 2、編寫一個簡單的 windows 應用程序,在窗體 load 事件中書寫代碼,標簽中顯示你的姓名。 using s
3、ystem; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; namespace one.second public partial class form1 : form public form1() initializecomponent(); private void form1_load(object
4、 sender, eventargs e) this.text = quot;windows 程序quot; label lblshow = new label(); lblshow.location = new point(20, 30); lblshow.autosize = true; lblshow.text = quot;王蕾!quot; this.controls.add(lblshow); 3、編寫一個一個程序,用來判斷輸入的是大寫字母,小寫字母,數字還是其他的字符。 using system; using system.collections.generic; using sy
5、stem.text; namespace one.third class program static void main(string args) console.writeline(quot;請輸入一個字符:quot;); char c = convert.tochar(console.readline(); if (cgt;="a"amp;amp;clt;="z")|(cgt;="a"amp;amp;clt;="z") console.writeline(quot;這是一個字母quot;); if (char
6、.isdigit(c) console .writeline(quot;這是一個數字quot;); 4、分別用 while,do-while,for 循環求 1 到 100 的和。 using system; using system.collections.generic; using system.text; namespace one.forth.one class program static void main(string args) int i = 1, sum = 0; while (i lt;= 100) sum = sum + i; i+; console.writelin
7、e(quot;1 到 100 的自然數之和為:quot; + sum); using system; using system.collections.generic; using system.text; namespace one.forth.two class program static void main(string args) int i = 1, sum = 0; do sum = sum + i; i+; while (i lt;= 100); console .writeline(quot;1 到 100 的自然數的和為:quot; + sum ); using syste
8、m; using system.collections.generic; using system.text; namespace one.forth.three class program static void main(string args) int i , sum = 0; for (i = 1; i lt;= 100; i+) sum = sum + i; console.writeline(quot;1 到 100 的自然數的和為:quot; + sum); 5、定義一個一維數組,用隨機數為此賦值,用 foreach 循環輸 出其中的內容。 using system; using
9、 system.collections.generic; using system.linq; using system.text; namespace first.five class program static void main(string args) int a = 0,1,2,3,4; foreach (int i in a) console.writeline(ai); 6、實現二維數組的輸入和輸出。 using system; using system.collections.generic; using system.linq; using system.text; nam
10、espace first.six class program static void main(string args) int, a = new int2, 3 1, 2, 3 , 4, 5, 6 ; for (int i = 0; i lt; 2; i+) for (int j = 0; j lt; 3; j+) console.writeline(ai, j); 7、實現數組型數組的輸入和輸出。 using system; using system.collections.generic; using system.linq; using system.text; namespace f
11、irst.seven class program static void main(string args) int a = new int new int 1, 2, 3 , new int 4, 5, 6 ; for (int i = 0; i lt; a.length; i+) for (int j = 0; j lt; ai.length; j+) console.writeline(aij); 六、實驗體會(遇到問題及解決辦法,編程后的心得體會) 剛開始編程的時候覺得無從下手,盡管我們已經學了好幾種高級編程語言,但每個都有其獨特的地方,稍不留神就會混淆。 通過這次實驗,我體會到課后復
12、習鞏固的重要性。在編程的時候,很多內容都不記得,需要去翻書。不得不說,實驗是鞏固課程的好方法!本次實驗,我熟悉 visual studio .net 開發環境;掌握了 c#應用程序的基本操作過程;掌握了 c#的數據類型,運算符以及表達式的使用;掌握了分支和循環語句的使用方法以及一維數組,二維數組及數組型數組的使用。 實驗項目名稱: 類與對象 實驗學時: 6 同組學生姓名: 實驗地點: 1318 實驗日期: 10 月 26 日-11 月 9 日 實驗成績: 批改教師: 批改時間: 實驗 2 類與對象 一、實驗目的、要求 (1)掌握類的定義和使用; (2)掌握類的數據成員,屬性的定義和使用; (3
13、)掌握方法的定義,調用和重載以及方法參數的傳遞; (4)掌握構造函數的定義和使用。 二、實驗要求 (1)編寫程序要規范、正確,上機調試過程和結果要有記錄; (2)做完實驗后給出本實驗的實驗報告。 三、實驗設備、環境 安裝有 visual studio .net 軟件。 四、實驗步驟 1、分析題意; 2、根據題目要求,新建項目; 3、編寫并輸入相關的程序代碼; 5、運行與調試項目; 6、保存項目。 五、實驗內容 1、定義一個方法,實現兩個數的交換(分別把參數按值傳遞和按引用傳遞)。 using system; using system.collections.generic; using sys
14、tem.text; namespace second.one class program static void main(string args) swaper s = new swaper(); console.writeline(quot;輸入 x 的值:quot;); int a = convert.toint32(console.readline(); console.writeline(quot;輸入 y 的值:quot;); int b=convert.toint32(console.readline(); console.writeline(s.swap(a, b); cons
15、ole.writeline(s.swap(ref a,ref b); class swaper public string swap(int x, int y) int temp; temp = x; x = y; y = temp; return string.format(quot;按值傳參交換之后:x=0,y=1quot;,x,y); public string swap(ref int x, ref int y) int temp; temp = x; x = y; y = temp; return string.format(quot;按引用傳參交換之后:x=0,y=1quot;,
16、x, y); 2、定義一個方法,實現數組的排序。 using system; using system.collections.generic; using system.text; namespace second.two class program public class sort public void change(int a) console.writeline(quot;排序前,數組順序為:quot;); show(a); int i, j, m; for (i = 0; i lt; 10; i+) m = ai; j = i - 1; /aj為數組前一個值 while (j g
17、t;= 0 amp;amp; m gt; aj)/判斷 i 下標的數是否大于 j 下標的數 aj + 1 = aj;/如果 i 下標大于j 把 j 往后移一個位 j-; aj+1 = m; /當不大于 j 的時候就把 m的值放到 i 下標下面 j+1 是為了下標減到最前時考慮 -1 + 1 還是下標的最前面 console.writeline(quot;排序后,數組順序為:quot;); show(a); void show(int a) int i; for (i = 0; i lt; 10; i+) console.write(quot;0 quot;, ai); console.writ
18、eline(); static void main(string args) int a = 4, 7, 1, 2, 5, 8, 9, 10, 3, 6 ; sort s=new sort(); s.change(a); 3、定義一個學生類,把學生類當作對象來傳遞。 using system; using system.collections.generic; using system.linq; using system.text; namespace second.three class program public class student public void st() int a
19、 = 999; public class st public void aa(student s) console.writeline(s); static void main(string args) student s=new student(); st s1 = new st(); s1.aa(s); 4、定義一個方法,求兩個數的和和差,通過參數把這兩個值帶回。 using system; using system.collections.generic; using system.linq; using system.text; namespace second.four class
20、program public class sum public void ab(out int m, out int n,int a, int b) m = a + b; n = a - b; static void main(string args) sum s = new sum(); int a = 10; int b = 3; int m, n; s.ab(out m, out n, a, b); console.writeline(quot;0+1=2;0- 1=3quot;,a,b,m,n); 5、用構造函數重載,實現矩形的面積,圓的面積,梯形的面積; using system;
21、using system.collections.generic; using system.linq; using system.text; namespace secong.five class program public class square public double area; public square() public square(double a) area = a * a * 3.14; public square(double a, double b) area = a * b; public square(double a, double b, double h)
22、 area = (a + b) / 2 * h; static void main(string args) double a, b, h,area; a = 2; b = 5; h = 3; square s = new square(a,b); console.writeline(quot;求矩形面積,長為 a=0,寬為 b=1,面積 area=2quot;,a,b,s.area); square i = new square(a); console.writeline(quot;求圓形面積,半徑 a=0,面積 area=1quot;, a, i.area); square j = new
23、 square(a, b, h); console.writeline(quot;求梯形面積,上底為a=0,下底為 b=1,高為 h=2面積 area=3quot;, a, b,h, j.area); 6、設計一個 windows 應用程序,在該程序中定義一個學生類和班級類,以處理每個學生的學號,姓名,語文,數學和英語成績,要求: 1)能查詢每個學生的總成績。 2)能顯示全班前三名的.。 3)能顯示單科成績最高分和不及格的學生.。 4)能統計全班學生的平均成績。 5)能顯示各科成績不同分數段的學生人數的百分比。 student 類: using system; using system.col
24、lections.generic; using system.text; namespace test2_6 public class student public string stuno; public string name; public double chinese; public double math; public double english; public double sumscore get return chinese + math + english; studentlist 類: using system; using system.collections.gen
25、eric; using system.text; namespace test2_6 public class studentlist:student int snums; public student stu=new student50; public studentlist() snums = 0; public void addstu(student s) stusnums = s; snums+; public int searchstu(string name) int i; for (i = 0; i lt; snums; i+) if ( = name) bre
26、ak; if (i = snums) return -1; else return i; /給所有成績排序,用后面實現前三名的排名 public void prothree() for (int i = 0; i lt; snums; i+) int k = i; for (int j = i + 1; j lt; snums; j+) if (stuj.sumscore gt; stuk.sumscore) k = j; if (k != i) student temp; temp = stuk; stuk = stui; stui = temp; /顯示單科成績的最高分 public in
27、t highscore(int k) int p = 0; if (k = 0) for (int i = 1; i lt; snums; i+) if (stui.math gt; stup.math) p = i; else if (k = 1) for (int i = 1; i lt; snums; i+) if (stui.chinese gt; stup.chinese) p = i; else for (int i = 1; i lt; snums; i+) if (stui.chinese gt; stup.chinese) p = i; return p; /顯示不及格. p
28、ublic string buhgname(int k) string name=quot; quot; if (k = 0) for (int i = 0; i lt; snums; i+) if (stui.math lt; 60) name +=+quot;nquot; else if (k = 1) for (int i = 0; i lt; snums; i+) if (stui.chinese lt; 60) name += + quot;nquot; else for (int i = 0; i lt; snums; i+) if (stui
29、.english lt; 60) name += + quot;nquot; return name; public string gethl() string maxer = quot; quot;, loser = quot; quot; maxer += quot; 單 科 數 學 最 高 : quot; + stuhighscore(0).name + quot;nquot; maxer += quot; 單 科 語 文 最 高 : quot; + stuhighscore(1).name + quot;nquot; maxer += quot; 單 科 英 語 最
30、 高 : quot; + stuhighscore(2).name + quot;nquot; loser += quot;單科數學掛科.:quot; +buhgname(0) + quot;nquot; loser += quot;單科語文掛科.:quot; + buhgname(1) + quot;nquot; loser += quot;單科英語掛科.:quot; + buhgname(2) + quot;nquot; return maxer + quot;nquot; + loser; /全班的平均成績 public string sumscore() double sum = 0;
31、 double avg=0; for (int i = 0; i lt; snums; i+) sum = sum + stui.sumscore; avg = sum / snums; return quot;班級總分平均分:quot;+avg; /各科成績不同分數段的學生百分比 /英語成績各分數段百分比 public string perc() double per1, per2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (int i = 0; i lt; snu
32、ms; i+) if (stui.chinese gt; 90) amp;amp; (stui.chinese lt;= 100) sumc1+; else if (80 lt;= stui.chinese) amp;amp; (stui.chinese lt; 90) sumc2+; else if(70lt;=stui.chinese)amp;amp; (stui.chinese lt; 80) sumc3+; else if(60lt;=stui.chinese)amp;amp;(stui.chinese lt; 70) sumc4+; else sumc5+; per1 = sumc1
33、 / snums; per2 = sumc2 / snums; per3 = sumc3 / snums; per4 = sumc4 / snums; per5 = sumc5 / snums; return quot; 語 文 成 績 百 分 比 :quot;+quot;nquot;+quot;90100:quot;+per1+quot; 8090:quot;+per2+quot; 8070:quot;+per3+quot; 7060:quot;+per4+quot; 60 以下的:quot;+per5; /數學成績各分數段百分比 public string perm() double pe
34、r1, per2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (int i = 0; i lt; snums; i+) if (stui.mathgt; 90) amp;amp;(stui.math lt;= 100) sumc1+; else if (80 lt;= stui.math) amp;amp; (stui.math lt; 90) sumc2+; else if (70 lt;= stui.math) amp;amp; (stui.math lt; 80)
35、 sumc3+; else if (60 lt;= stui.math) amp;amp; (stui.math lt; 70) sumc4+; else sumc5+; per1 = sumc1 / snums; per2 = sumc2 / snums; per3 = sumc3 / snums; per4 = sumc4 / snums; per5 = sumc5 / snums; return string.format(quot;數學成績百分比:quot; + quot;nquot; + quot;90100:quot; + per1 + quot; 8090:quot; + per
36、2 + quot; 8070:quot; + per3 + quot; 7060:quot; + per4 + quot; 60 以下的:quot; + per5); /英語成績各分數段百分比 public string pere() double per1, per2, per3, per4, per5; double sumc1 = 0, sumc2 = 0, sumc3 = 0, sumc4 = 0, sumc5 = 0; for (int i = 0; i lt; snums; i+) if (stui.english gt; 90) amp;amp; (stui.english lt
37、;= 100) sumc1+; else if (80 lt;= stui.english) amp;amp; (stui.english lt; 90) sumc2+; else if (70 lt;= stui.english) amp;amp; (stui.english lt; 80) sumc3+; else if (60 lt;= stui.english) amp;amp; (stui.english lt; 70) sumc4+; else sumc5+; per1 = sumc1 / snums; per2 = sumc2 / snums; per3 = sumc3 / sn
38、ums; per4 = sumc4 / snums; per5 = sumc5 / snums; return string.format(quot;數學成績百分比:quot; + quot;nquot; + quot;90100:quot; + per1 + quot; 8090:quot; + per2 + quot; 8070:quot; + per3 + quot; 7060:quot; + per4 + quot; 60 以下的:quot; + per5); from 窗體代碼: using system; using system.collections.generic; usin
39、g system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; namespace test2_6 public partial class form1 : form public form1() initializecomponent(); public studentlist sl = new studentlist(); private void btnadd_click(object sender, eventargs e)
40、student s = new student(); s.stuno = txtstuno.text; = txtname.text; s.chinese = convert.todouble(txtchina.text); s.math = convert.todouble(txtmath.text); s.english = convert.todouble(txteng.text); sl.addstu(s); messagebox.show(quot;添加成功quot;); private void btnsearch_click(object sender, event
41、args e) int pos = sl.searchstu(this.textbox1.text); if (pos != -1) label7.text = this.textbox1.text + quot;的總成績:quot; + sl.stupos.sumscore; else messagebox.show(quot;不存在這個人!quot;); private void btnfinish_click(object sender, eventargs e) label7.text = quot;前 3 名:quot;+quot;nquot; for (int i = 0; i l
42、t; 3; i+) sl.prothree(); label7.text+= +quot;nquot; label7.text += sl.gethl()+quot;nquot; label7.text += convert.tostring(sl.sumscore()+quot;nquot; label7.text += sl.perc()+quot;nquot; label7.text += sl.perm()+quot;nquot; label7.text += sl.pere()+quot;nquot; 六、實驗體會(遇到問題及解決辦法,編程后的心得體會) 通過
43、本次實驗,我掌握了類的定義與使用;掌握了類的數據成員,屬性的定義和使用;掌握了方法的定義,調用和重載以及方法參數的傳遞以及構造函數的定義和使用。值得注意的是:本次實驗中 return的使用以及所在的位置,類型轉換時也經常用到 實驗項目名稱: 繼承與多態 實驗學時: 6 同組學生姓名: 實驗地點: 1318 實驗日期: 11 月 16 日-11 月 30 日 實驗成績: 批改教師: 批改時間: 實驗 3 繼承與多態 一、實驗目的、要求 (1)掌握類的繼承性與多態性; (2)掌握虛方法的定義以及如何使用虛方法實現多態; (3)掌握抽象類的定義以及如何使用抽象方法實現多態; 二、實驗要求 (1)編寫
44、程序要規范、正確,上機調試過程和結果要有記錄; (2)做完實驗后給出本實驗的實驗報告。 三、實驗設備、環境 安裝有 visual studio .net 軟件。 四、實驗步驟 1、分析題意; 2、根據題目要求,新建項目; 3、編寫并輸入相關的程序代碼; 5、運行與調試項目; 6、保存項目。 五 、實驗內容 1、設計一個 windows 應用程序,在該程序中首先構造一個學生基本類,再分別構造小學生、中學生、大學生派生類,當輸入相關數據,單擊不用的按鈕時,將分別創建不同的學生類對象,并輸出當前學生的總人數,該學生的姓名,學生類型,平均成績。 student 類: using system; using system.collections.generic; using system.text; namespace test3_1 public abstract class student protected string name; protected int age; public stati
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 藥渣委托處理協議書
- 酒店事故賠償協議書
- 路政改革擴建協議書
- 酒店經營管理協議書
- 鄰居違建協商協議書
- 門面轉讓退款協議書
- 項目資料移交協議書
- 解除店長職位協議書
- 鄰居物資互換協議書
- 隱名股東股東協議書
- 衛通通信系統-FDMA方式
- 肥胖癥康復課件
- SYT 0447-2014《 埋地鋼制管道環氧煤瀝青防腐層技術標準》
- 物理高考最后一課課件
- 電解質紊亂的心電圖表現
- 2022年修改后的銀行業G32表填報說明
- 巨量-信息流(初級)認證考試(重點)題庫(含答案)
- 硫磺車間風險辨識表
- 鑄造行業的危險因素辨識及預防措施
- 起重裝卸機械操作工(高級工)考試題庫(含答案)
- 三相照明配電干線的各相負荷平衡情況檢測記錄表2
評論
0/150
提交評論