C#程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告2_第1頁
C#程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告2_第2頁
C#程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告2_第3頁
C#程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告2_第4頁
C#程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告2_第5頁
已閱讀5頁,還剩19頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、實(shí)驗(yàn)報(bào)告二姓 名專業(yè)軟件工程課程名稱C#程序設(shè)計(jì)一、 實(shí)驗(yàn)名稱:實(shí)驗(yàn)2二、 實(shí)驗(yàn)?zāi)康模赫莆帐褂妹钚虚_發(fā)簡單的C#應(yīng)用程序掌握使用Visual Studio編寫控制臺應(yīng)用程序掌握Visual Studio環(huán)境下程序的跟蹤調(diào)試了解Visual Studio在線幫助的使用掌握應(yīng)用程序命令行參數(shù)的使用三、實(shí)驗(yàn)內(nèi)容及要求利用ADO.NET完成數(shù)據(jù)的增、刪、改、查1.1 鼠標(biāo)、窗口、菜單的操作1.2 用戶賬戶的管理1.3 桌面圖標(biāo)的排列、設(shè)置桌面背景和屏幕保護(hù)程序1.4 設(shè)置任務(wù)欄、語言欄1.5 選擇輸入法、在“記事本”文件中輸入各種符號2.1了解“資源管理器的使用”2.2 設(shè)置文件夾選項(xiàng)、查找文件或文

2、件夾2.3 文件/文件夾操作2.4 使用回收站具體要求請見大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)學(xué)習(xí)指導(dǎo)P37P48四、實(shí)驗(yàn)材料、工具、或軟件Windows XP Professional SP3Visual Studio 2005五、實(shí)驗(yàn)步驟、結(jié)果(或記錄)實(shí)驗(yàn)二:程序流程控制2-1輸入半徑,求對應(yīng)的圓的周長、面積、對應(yīng)球體的體積。運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_1 class Program static void Main(stri

3、ng args) const double PI = 3.14159; double r, perimeter, area, volume; Console.Write ("請輸入半徑:"); String s = Console.ReadLine(); r = double.Parse(s); Console.WriteLine("圓的半徑為=0",r); perimeter = 2 * PI * r; area = PI * r * r; volume = 4 / 3 * PI * Math.Pow(r, 3); Console.WriteLine(

4、"圓的周長為=0,面積為=1",perimeter ,area ); Console.WriteLine("球體的體積=0",volume ); Console.ReadLine(); 2-2求三角形的周長和面積運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_2 class Program static void Main(string args) double a, b, c, p, h, a

5、rea; Console.Write("請輸入三角形的邊a:"); string s = Console.ReadLine(); a = double.Parse(s); Console .Write ("請輸入三角形的邊b:"); s = Console.ReadLine(); b = double.Parse(s); Console.Write("請輸入三角形的邊c:"); s = Console.ReadLine(); c = double.Parse(s); if (a > 0 && b > 0 &

6、amp;& c > 0 && a + b > c && a + c > b && b + c > a) Console.WriteLine("三角形三邊分別為:a=0,b=1,c=2",a,b,c); p = a + b + c; h = p / 2; area = Math.Sqrt(h * (h - a) * (h - b) * (h - c); Console.WriteLine("三角形的周長=0,面積為=1",p,area); else Console.WriteL

7、ine("無法構(gòu)成三角形!"); Console.ReadKey(); 2-3分段函數(shù)的實(shí)現(xiàn)運(yùn)行結(jié)果實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_3_2 class Program static void Main(string args) double x, y; Console .Write ("請輸入x:"); string s = Console.ReadLine(); x = double.P

8、arse(s); y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x); if(x<0) y=Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math.E ,4)-Math .Pow (x+1,3); Console .WriteLine ("方法一:x=0,y=1",x,y); if(x>=0) y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x); if(x<0) y=M

9、ath.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math.E,4)-Math .Pow (x+1,3); Console .WriteLine ("方法二:x=0,y=1",x,y); if(x>=0) y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x); else y=Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math .E,4)-Math .Pow (x+1,3); Consol

10、e .WriteLine ("方法三:x=0,y=1",x,y); y=(x>=0)?(x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x):Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math .E,4)-Math .Pow (x+1,3); Console .WriteLine ("方法四:x=0,y=1",x,y); Console .ReadKey (); 2-4三個數(shù)比較大小運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;us

11、ing System.Collections.Generic;using System.Linq;using System.Text;namespace _2_4 class Program static void Main(string args) int a, b, c, a1, b1, c1, t, Nmax, Nmin, Nmid; Random rMun = new Random(); a = rMun.Next(101); b = rMun.Next(101); c= rMun.Next(101); Console.WriteLine("原始值:a=0,b=1,c=2&q

12、uot;,a,b,c); a1 = a; b1 = b; c1 = c; if (a > b) t = a; a = b; b = t; if (a > c) t = a; a = c; c = t; if (b > c) t = b; b = c; c = t; Console.WriteLine("(方法一)升序值:a=0,b=1,c=2"),a,b,c); a = a1; b = b1; c = c1; Nmax =Math .Max (Math .Max (a,b),c); Nmin = Math.Min(Math.Min(a, b), c); N

13、mid = a + b + c - Nmax - Nmin; a = Nmin; b = Nmid; c = Nmax; Console.WriteLine("(方法二)升序值:a=0,b=1,c=2",a,b,c); Console.ReadKey(); 2-5求解一元二次方程運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;using System.Text;namespace Console2_5 class Program static void Main(string args) double a, b

14、, c, delta, x1, x2, realPart, imagePart; Console.Write("請輸入系數(shù)a:"); String s = Console.ReadLine(); a = double.Parse(s); Console.Write("請輸入系數(shù)b:"); s = Console.ReadLine(); b = double.Parse(s); Console.Write("請輸入系數(shù)c:"); s = Console.ReadLine(); c = double.Parse(s); if(a=0) i

15、f(b=0) Console.WriteLine("此方程無解!"); else Console.WriteLine("此方程的解為:0",-c/b); else delta=b*b-4*a*c; if(delta>0) x1=(-b+Math.Sqrt(delta)/(2*a); x2=(-b-Math.Sqrt(delta)/(2*a); Console.WriteLine("此方程有兩個不等實(shí)根:0,1",x1,x2); else if(delta =0)Console.WriteLine("此方程有兩個相等實(shí)根

16、:0",-b/(2*a); else realPart=-b/(2*a); imagePart=Math.Sqrt(-delta)/(2*a); Console.WriteLine("此方程有兩個不等實(shí)根:0+1i和0-1i",realPart,imagePart); Console.ReadKey(); 2-6switch語句實(shí)現(xiàn)多重分支運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1 class Prog

17、ram static void Main(string args) int i; Console.Write("輸入一個數(shù)字(17):"); String s = Console.ReadLine(); i = int.Parse(s); switch(i) case 1: Console.WriteLine("對應(yīng)的星期為:星期一"); break; case 2: Console.WriteLine("對應(yīng)的星期為:星期二"); break; case 3: Console.WriteLine("對應(yīng)的星期為:星期三&q

18、uot;); break; case 4: Console.WriteLine("對應(yīng)的星期為:星期四"); break; case 5: Console.WriteLine("對應(yīng)的星期為:星期五"); break; case 6: Console.WriteLine("對應(yīng)的星期為:星期六"); break; case 7: Console.WriteLine("對應(yīng)的星期為:星期日"); break; default: Console.WriteLine("輸入錯誤!"); break ;

19、 Console.ReadKey(); 2-7分別使用if語句和switch語句實(shí)現(xiàn)多分支結(jié)構(gòu)方法一:運(yùn)行結(jié)果(if語句)using System;using System.Collections.Generic;using System.Text;namespace Console2_7 class Program static void Main(string args) int c; double f = 0; Console.Write("請輸入有固定工資收入的黨員的月工資:"); int salary = int.Parse(Console.ReadLine();

20、 if (salary > 1500) c = 15; else c = (salary - 1) / 100; switch (c) case 0: case 1: case 2: case 3: f = 0.5 / 100 * salary; break; case 6: case 7: f = 1.5 / 100 * salary; break; case 8: case 9: case 10: case 11: case 12: case 13: case 14: f = 2.0 / 100 * salary; break; case 15: f = 3.0 / 100 * sa

21、lary; break; Console.WriteLine("月工資=0,交納黨費(fèi)=1", salary, f); Console.ReadKey(); 法二運(yùn)行結(jié)果:代碼:(if語句)using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_7_2 class Program static void Main(string args) int c; double f = 0; Console.Write("請輸入有固定收入的黨員的

22、月工資:"); int salary = int.Parse(Console.ReadLine(); if (salary > 0 && salary <= 400) f = 0.5 / 100 * salary; else if (salary > 400 && salary <= 600) f = 1.0 / 100 * salary; else if (salary > 600 && salary <= 800) f = 1.5 / 100 * salary; else if (salary &

23、gt; 800 && salary <= 1500) f = 2.0 / 100 * salary; else if (salary > 1500) f = 3.0 / 100 * salary; else Console.WriteLine("月工資輸入有誤!"); Console.WriteLine("月工資=0,交納黨費(fèi)=1", salary, f); Console.ReadKey(); 實(shí)驗(yàn)三:3-1運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;usi

24、ng System.Linq;using System.Text;namespace _3_1 class Program static void Main(string args) int i, n, fac = 1; string s; n = -1; while (n < 0) Console.Write("請輸入非負(fù)整數(shù)n:"); s = Console.ReadLine(); n = int.Parse(s); /方法一:for循環(huán) for (i = 1; i <= n; i+) fac *= i; Console.WriteLine(" F

25、or循環(huán):0!=1", n, fac); /方法二:while語句循環(huán) i = 1; fac = 1; while (i <= n) fac *= i+; Console.WriteLine(" while循環(huán):0!=1", n, fac); /方法三:do.while語句循環(huán) i = 1; fac = 1; do fac *= i; i+; while (i <= n); Console.WriteLine(" do.while循環(huán):0!=1", n, fac); Console.ReadKey(); 3-2運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:u

26、sing System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_2 class Program static void Main(string args) int f1 = 1, f2 = 1, f3, num = 2; Console.Write("0,5t0,5t", f1, f2); f3 = f1 + f2; while (f3 <= 10000) Console.Write("0,5t", f3); num+; if

27、 (num % 5 = 0) Console.WriteLine(); f1 = f2; f2 = f3; f3 = f1 + f2; Console.ReadKey(); 3-3、雞兔同籠問題運(yùn)行結(jié)果:代碼:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_3 class Program static void Main(string args) int c, r; Console.Write("請輸入總頭數(shù):"); string s

28、 = Console.ReadLine(); int h = int.Parse(s); int f = 1; while (f % 2 != 0) Console.Write("請輸入總腳數(shù)(必須是偶數(shù)):"); s = Console.ReadLine(); f = int.Parse(s); /方法一:利用循環(huán) bool solution = false; for (c = 0; c <= h; c+) r = h - c; if (2 * c + 4 * r = f) Console.WriteLine("方法一:雞:0只,兔:1只",c

29、,r ); solution = true; if (!solution) Console.Write("方法一:無解,請重新運(yùn)行測試!"); /方法二:解方程 r = f / 2 - h; c = h - r; solution = false; if (r>=0&&c>=0) Console .WriteLine ("方法二:雞:0只,兔:1只",c ,r); solution =true ; if (!solution) Console.WriteLine("方法二:無解,請重新運(yùn)行測試!"); Co

30、nsole .ReadKey (); 3-4利用級數(shù)和求PI運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Consolejishuhe3_4 class Program static void Main(string args) float n, t,pi; int s; pi = 0; t = 1; n = 1; s = 1; while (Math.Abs(t) >= Math.Pow(10, -6) pi += t; n +=

31、 2; s = -s; t = s / n; pi *= 4; Console.WriteLine("pi=0", pi); Console.ReadKey(); 3-5運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleG_3_6 class Program static void Main(string args) int m,n, r, m1, n1; Random rNum = new Random()

32、; m1 = rNum.Next(101); n1 = rNum.Next(101); Console.WriteLine("整數(shù)1=0,整數(shù)2=1", m1, n1); if (m1 > n1) m = m1; n = n1; else m = n1; n = m1; do r =m %n; m =n ; n =r ; while (r !=0); Console .WriteLine ("最大公約數(shù)=0,最小公約數(shù)=1",m ,m1 *n1 /m ); Console .ReadKey (); 3-6打印九九乘法表運(yùn)行結(jié)果:代碼:using S

33、ystem;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_5 class Program static void Main(string args) string s; / Console.WriteLine(" 九九乘法表"); for (int i = 1; i <= 9; i+) s = "" for (int j = 1; j <= i; j+) s += (string.Format("0*1=2"

34、;, i, j, i * j).PadRight(8); Console.WriteLine(s); / Console.WriteLine(""); Console.WriteLine(" 九九乘法表"); for (int i = 1; i <= 9; i+) s = "" s += s.PadRight(8 * (i - 1) + 1); for (int j = i ; j <= 9; j+) s += (string.Format("0*1=2", i, j, i * j).PadRight(

35、8); Console.WriteLine(s); Console.ReadKey(); 3-7運(yùn)行結(jié)果:實(shí)驗(yàn)代碼:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_7 class Program static void Main(string args) int m, k, i, num = 0; /方法一:利用for循環(huán)和break語句 Console.WriteLine("方法一:1100間所有的素?cái)?shù)為:"); for (m = 2; m <= 100; m+) k

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論