




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上學(xué) 生 實(shí) 驗(yàn) 報(bào) 告 冊(cè)(理工類(lèi))課程名稱(chēng): C#程序設(shè)計(jì)實(shí)驗(yàn) 專(zhuān)業(yè)班級(jí):14計(jì)算機(jī)科學(xué)與技術(shù)(單)(1) 學(xué)生學(xué)號(hào): 學(xué)生姓名: 邵佳楠 所屬院部: 計(jì)算機(jī)工程學(xué)院 指導(dǎo)教師: 馬xx 2016 2017學(xué)年 第 1 學(xué)期 金陵科技學(xué)院教務(wù)處制專(zhuān)心-專(zhuān)注-專(zhuān)業(yè)實(shí)驗(yàn)項(xiàng)目名稱(chēng): C#基礎(chǔ)編程 實(shí)驗(yàn)學(xué)時(shí): 6 同組學(xué)生姓名: 無(wú) 實(shí)驗(yàn)地點(diǎn): A104 實(shí)驗(yàn)日期: 實(shí)驗(yàn)成績(jī): 批改教師: 馬青霞 批改時(shí)間: 實(shí)驗(yàn)1 C#基礎(chǔ)編程一、實(shí)驗(yàn)?zāi)康?、熟悉Visual Studio .NET開(kāi)發(fā)環(huán)境;2、掌握C#應(yīng)用程序的基本操作過(guò)程;3、掌握C#的數(shù)據(jù)類(lèi)型,運(yùn)算符以及表達(dá)式的使
2、用;4、掌握分支和循環(huán)語(yǔ)句的使用方法;5、掌握一維數(shù)組,二維數(shù)組及數(shù)組型數(shù)組的使用。二、實(shí)驗(yàn)要求1、編寫(xiě)程序要規(guī)范、正確,上機(jī)調(diào)試過(guò)程和結(jié)果要有記錄;2、做完實(shí)驗(yàn)后給出本實(shí)驗(yàn)的實(shí)驗(yàn)報(bào)告。三、實(shí)驗(yàn)設(shè)備、環(huán)境安裝有Visual Studio .NET2005以上版本軟件。四、實(shí)驗(yàn)步驟1、 采用VS編寫(xiě)一個(gè)簡(jiǎn)單的控制臺(tái)應(yīng)用程序(1)打開(kāi)VS開(kāi)發(fā)工具。(2)在新建項(xiàng)目對(duì)話(huà)框中選擇Visual C#,模板選擇控制臺(tái)應(yīng)用程序,給項(xiàng)目命名為HelloConsole,然后點(diǎn)“瀏覽”按鈕,選擇項(xiàng)目的存儲(chǔ)目錄。(3)在Program.cs文件中,鍵入代碼如下:using System;Namespace Hell
3、oConsole class Program static void Main(string args) String name; Console.Write("請(qǐng)輸入姓名:"); name = Console.ReadLine(); Console.WriteLine("歡迎0光臨", name); Console.ReadLine(); (4)按F5或者點(diǎn)啟動(dòng)調(diào)試按鈕運(yùn)行程序,在控制臺(tái)中輸入“你的姓名”,回車(chē)。2、采用VS編寫(xiě)一個(gè)簡(jiǎn)單的windows窗體應(yīng)用程序(1)打開(kāi)開(kāi)發(fā)工具。(2)在新建項(xiàng)目對(duì)話(huà)框中選擇Visual C#,模板選擇windows
4、窗體應(yīng)用程序,給項(xiàng)目命名為HelloForm,然后點(diǎn)“瀏覽”按鈕,選擇項(xiàng)目的存儲(chǔ)目錄。(3)在Form1窗體中拖放一個(gè)TextBox文本框、Label標(biāo)簽和Button按鈕控件,修改Label的Text屬性為”, 修改Button1的Text屬性為”確定”。(4)雙擊Command1進(jìn)入Form1.cs的代碼界面,在button1_Click事件中鍵入代碼如下:private void button1_Click(object sender, EventArgs e) label1.Text = "歡迎" + textBox1.Text + "光臨" /
5、或者 label1.Text = string.Format("歡迎0光臨",textBox1.Text); (5)按F5或者點(diǎn)啟動(dòng)調(diào)試按鈕運(yùn)行程序,在文本框中輸入“你的姓名”,單擊“確定”按鈕。運(yùn)行結(jié)果(請(qǐng)截圖):1、 采用VS編寫(xiě)一個(gè)簡(jiǎn)單的控制臺(tái)應(yīng)用程序2、采用VS編寫(xiě)一個(gè)簡(jiǎn)單的windows窗體應(yīng)用程序五、實(shí)驗(yàn)內(nèi)容1、編寫(xiě)一個(gè)控制臺(tái)應(yīng)用程序,輸入自己的班級(jí)、學(xué)號(hào)、姓名并顯示。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Thr
6、eading.Tasks;namespace student class Program static void Main(string args) String grade; String name; String number; Console.WriteLine("請(qǐng)輸入班級(jí):"); grade = Console.ReadLine(); Console.WriteLine("請(qǐng)輸入姓名:"); name = Console.ReadLine(); Console.WriteLine("請(qǐng)輸入學(xué)號(hào):"); number = Co
7、nsole.ReadLine(); Console .WriteLine ("班級(jí):0,姓名:1,學(xué)號(hào):2",grade,name ,number ); Console .ReadLine (); 2、編寫(xiě)一個(gè)Windows窗體應(yīng)用程序,輸入自己的班級(jí)、學(xué)號(hào)、姓名并顯示。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using
8、 System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication2 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) MessageBox .Show ("班級(jí):"+textBox1.Text+"n姓名:"+textBox2.Text +"n
9、學(xué)號(hào):"+textBox3 .Text ); 3、編寫(xiě)一個(gè)程序,用來(lái)判斷輸入的是大寫(xiě)字母,小寫(xiě)字母,數(shù)字還是其他的字符(if)。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1 class Program static void Main(string args) Console.WriteLine("請(qǐng)輸入一個(gè)字符:"); char
10、c = Convert.ToChar(Console.ReadLine(); if (c >= 'a' && c <= 'z') Console.WriteLine("該字母是小寫(xiě)字母"); else if (c >= 'A' && c <= 'Z') Console.WriteLine("該字母是大寫(xiě)字母"); else if (char.IsDigit(c) Console.WriteLine("該字母是數(shù)字")
11、; else Console.WriteLine("其它字符"); Console.ReadLine(); 4、編寫(xiě)一個(gè)程序,實(shí)現(xiàn)簡(jiǎn)單的加、減、乘、除的運(yùn)算(switch)。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsAppli
12、cation3 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) int num1 = int.Parse(txtnum1.Text); int num2 = int.Parse(txtnum2.Text); switch (txtop.Text) case "+": txtresult.Text = (num1 + num2) + "" break;
13、case "-": txtresult.Text = (num1 - num2) + ""break; case "*": txtresult.Text = (num1 * num2) + ""break; case "/": txtresult.Text = (num1 / num2) + ""break; default: txtresult.Text = "error!"break; 5、定義一個(gè)一維數(shù)組,通過(guò)鍵盤(pán)輸入10個(gè)兩位整數(shù),用foreach
14、循環(huán)輸出其中的內(nèi)容。并求出其中的最大值和平均值,把結(jié)果顯示出來(lái)。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication2 class Program static void Main(string args) int a = new int10; int i = 0; while (i < a.Length) Console.Write("請(qǐng)輸入第0個(gè)數(shù)據(jù):
15、", i + 1); ai = Convert.ToInt32(Console.ReadLine(); if (ai >= 10 && ai <= 99) i+; Console.Write(" 數(shù)組內(nèi)容為:"); foreach (int j in a) Console.Write("0 ", j); Console.WriteLine(); Console.WriteLine("最大值: " + a.Max(); Console.WriteLine("平均值: " + a.
16、Average(); Console.ReadLine(); 6、定義一個(gè)5行5列二維數(shù)組,用隨機(jī)數(shù)給二維數(shù)組賦值,按照5行5列的格式顯示出二維數(shù)組的內(nèi)容,把最大值顯示出來(lái)。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication2 class Program static void Main(string args) int, a = new int5, 5; int ma
17、x; Random rnd = new Random(); Console.WriteLine("二維數(shù)組的內(nèi)容為:"); for (int i = 0; i < 5; i+) for (int j = 0; j < 5; j+) ai, j = rnd.Next(10, 99); Console.Write("0 ", ai, j); Console.WriteLine(); max = a0, 0; for (int i = 0; i < 5; i+) for (int j = 0; j < 5; j+) if (ai, j
18、> max) max = ai, j; Console.WriteLine("最大值:" + max); Console.ReadLine(); 實(shí)驗(yàn)項(xiàng)目名稱(chēng): 面向?qū)ο缶幊?實(shí)驗(yàn)學(xué)時(shí): 6 同組學(xué)生姓名: 無(wú) 實(shí)驗(yàn)地點(diǎn): A104 實(shí)驗(yàn)日期: 實(shí)驗(yàn)成績(jī): 批改教師: 馬青霞 批改時(shí)間: 實(shí)驗(yàn)2 面向?qū)ο缶幊桃?、?shí)驗(yàn)?zāi)康?、要?、理解面向?qū)ο蟪绦蛟O(shè)計(jì)的思想和基本概念;2、掌握類(lèi)的定義和使用;3、掌握類(lèi)的數(shù)據(jù)成員,屬性的定義和使用;4、掌握方法的定義,調(diào)用和重載以及方法參數(shù)的傳遞;5、掌握構(gòu)造函數(shù)和析構(gòu)函數(shù)的定義和使用。7、掌握虛方法的定義以及如何用虛方法實(shí)現(xiàn)多態(tài);8、
19、掌握抽象類(lèi)的定義以及如何用用抽象方法實(shí)現(xiàn)多態(tài);9、掌握集合的創(chuàng)建和操作方法;10、掌握接口的定義及使用方法。二、實(shí)驗(yàn)要求1、編寫(xiě)程序要規(guī)范、正確,上機(jī)調(diào)試過(guò)程和結(jié)果要有記錄;2、做完實(shí)驗(yàn)后給出本實(shí)驗(yàn)的實(shí)驗(yàn)報(bào)告。三、實(shí)驗(yàn)設(shè)備、環(huán)境安裝有VS.Net 2005以上版本軟件。四、實(shí)驗(yàn)內(nèi)容1、利用方法的重載兩個(gè)整數(shù)和兩個(gè)雙精度類(lèi)型數(shù)據(jù)求和。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _1 class Pro
20、gram static void Main(string args) Console.WriteLine("整型數(shù)據(jù)相加:"); Add intadd = new Add(1, 2); intadd.Result(); Console.WriteLine("雙精度數(shù)據(jù)相加:"); Add doubleadd = new Add(1.1, 2.5); doubleadd.Result(); class Add public double add = 0; public Add(double x, double y) add = x + y; public
21、Add(int x, int y) add = x + y; public void Result() Console.WriteLine(add); 2、定義一個(gè)Area類(lèi),用構(gòu)造函數(shù)重載,實(shí)現(xiàn)矩形的面積,圓的面積,梯形的面積,定義一個(gè)ShowArea方法,顯示結(jié)果。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Win
22、dows.Forms;namespace WindowsFormsApplication4 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) double len = double.Parse(txtlength.Text); double wid = double.Parse(txtwidth.Text); double r = double.Parse(txtr.Text); double
23、 sd = double.Parse(txtsd.Text); double xd = double.Parse(txtxd.Text); double hei = double.Parse(txtheight.Text); Area a1 = new Area(len,wid); Area a2 = new Area(r); Area a3 = new Area(sd, xd, hei); txtrec.Text = a1.ShowArea(len,wid); txtcir.Text = a2.ShowArea(r); txtech.Text = a3.ShowArea(sd, xd, he
24、i); using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace WindowsFormsApplication4 class Area double len, wid, r, sd, xd, hei; public Area(double len, double wid) this.len = len; this.wid = wid; public Area(double r) this.r = r; public Area(double sd, double xd,
25、 double hei) this.sd = sd; this.xd = xd; this.hei = hei; public string ShowArea(double len,double wid) return (len * wid) + "" public string ShowArea(double r) return (3.14 * r * r) + "" public string ShowArea(double sd, double xd, double hei) return (sd + xd) * hei * 0.5) + &quo
26、t;" 3、定義一個(gè)Students類(lèi),包括學(xué)號(hào)、姓名、性別、年齡4個(gè)屬性,要求在性別屬性中增加對(duì)性別的判斷(只能輸入男和女),在年齡屬性中提供對(duì)不合法(年齡在10至50之間)輸入的判斷,并提供方法顯示學(xué)生信息。構(gòu)建該類(lèi),并測(cè)試。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _3 class Student int id, age; string name, sex; public int
27、_id get return id; set id = value; public int _age get return age; set age = value; public string _name get return name; set name = value; public string _sex get return sex; set sex = value; class Program static void Main(string args) Student mz = new Student(); mz._id = ; mz._name = "周慧博"
28、 mz._sex = "男" mz._age = 20; Console.WriteLine("學(xué)號(hào):0rn姓名:1rn性別:2rn年齡:3", mz._id, mz._name, mz._sex, mz._age); Console.ReadKey(); 4、設(shè)計(jì)一個(gè)Windows應(yīng)用程序,在該程序中首先構(gòu)造一個(gè)學(xué)生基本類(lèi),再分別構(gòu)造小學(xué)生、中學(xué)生、大學(xué)生派生類(lèi),當(dāng)輸入相關(guān)數(shù)據(jù),單擊不用的按鈕時(shí),將分別創(chuàng)建不同的學(xué)生類(lèi)對(duì)象,并輸出當(dāng)前學(xué)生的總?cè)藬?shù),該學(xué)生的姓名,學(xué)生類(lèi)型,平均成績(jī)。程序要求:(1)每個(gè)學(xué)生都有的字段為姓名、年齡。(2)小學(xué)生的字段還有語(yǔ)
29、文,數(shù)學(xué),用來(lái)表示這兩科的成績(jī)。(3)中學(xué)生在此基礎(chǔ)上增加英語(yǔ)成績(jī)。(4)大學(xué)生分為必修課和選修課兩項(xiàng)成績(jī)。(5)學(xué)生類(lèi)提供方法來(lái)統(tǒng)計(jì)自己的總成績(jī)并輸出。(6)通過(guò)靜態(tài)成員自動(dòng)記錄學(xué)生總?cè)藬?shù)。(7)成員初始化通過(guò)構(gòu)造函數(shù)完成。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using Sys
30、tem.Windows.Forms;namespace WindowsFormsApplication5 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) int age = Convert.ToInt32(txtAge.Text); double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txt
31、Sub2.Text); Pupil p = new Pupil(txtName.Text, age, sub1, sub2); lblShow.Text += p.getInfo(); private void button2_Click(object sender, EventArgs e) int age = Convert.ToInt32(txtAge.Text); double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txtSub2.Text); double sub3 = Conver
32、t.ToDouble(txtSub3.Text); Middle p = new Middle(txtName.Text, age, sub1, sub2, sub3); lblShow.Text += p.getInfo(); private void button3_Click(object sender, EventArgs e) int age = Convert.ToInt32(txtAge.Text); double sub1 = Convert.ToDouble(txtSub1.Text); double sub2 = Convert.ToDouble(txtSub2.Text)
33、; double sub3 = Convert.ToDouble(txtSub3.Text); College p = new College(txtName.Text, age, sub1, sub2, sub3); lblShow.Text += p.getInfo(); using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApplication5 public abstract
34、 class Student protected string name; protected int age; public static int number; public Student(string name, int age) = name; this.age = age; number+; public string Name get return name; public virtual string type get return "學(xué)生" public abstract double total(); public string ge
35、tInfo() string result = string.Format("總?cè)藬?shù):0,姓名:1,2,3歲", number, Name, type, age); if (type = "小學(xué)生²") result += string.Format(",平均成績(jī)?yōu)?:N2:n", total() / 2); else if (type = "中學(xué)生") result += string.Format(",平均成績(jī)?yōu)?:N2:n", total() / 3); else result
36、+= string.Format(",總學(xué)分為0:N2:n", total(); return result; using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApplication5 public class Pupil : Student protected double chinese; protected double math; public Pup
37、il(string name, int age, double chinese, double math) : base(name, age) this.chinese = chinese; this.math = math; public override string type get return "小學(xué)生" public override double total() return chinese + math; using System;using System.Collections.Generic;using System.Linq;using System.
38、Text;using System.Threading.Tasks;namespace WindowsFormsApplication5 public class Middle : Student protected double chinese; protected double math; protected double english; public Middle(string name, int age, double chinese, double math, double english) : base(name, age) this.chinese = chinese; thi
39、s.math = math; this.english = english; public override string type get return "中學(xué)生" public override double total() return chinese + math + english; using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApplicati
40、on5 public class College : Student protected double chinese; protected double math; protected double english; public College(string name, int age, double chinese, double math, double english) : base(name, age) this.chinese = chinese; this.math = math; this.english = english; public override string t
41、ype get return "本科生" public override double total() return chinese + math + english; 5、設(shè)計(jì)一個(gè)Windows應(yīng)用程序,在該程序中定義平面圖形抽象類(lèi)Figure和派生類(lèi)圓(Circle)、矩形(Rectangle)和三角形(Triangle)。該程序?qū)崿F(xiàn)的功能包括:輸入相應(yīng)圖形的參數(shù),如矩形的長(zhǎng)和寬,單擊相應(yīng)的按鈕,根據(jù)輸入?yún)?shù)創(chuàng)建圖形類(lèi)并輸出該對(duì)象的面積。using System;using System.Collections.Generic;using System.Componen
42、tModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApplication7 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e)
43、double r = Convert.ToDouble(textBox1.Text); Circle c = new Circle(r); lblShow.Text += "圓面積為:" + c.Area() + "n" private void button2_Click(object sender, EventArgs e) double len = Convert.ToDouble(textBox1.Text); double wid = Convert.ToDouble(textBox2.Text); Rectangle r = new Rectangle(len, wid); lblShow
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 年中國(guó)新材料產(chǎn)業(yè)行業(yè)運(yùn)營(yíng)態(tài)勢(shì)及發(fā)展趨勢(shì)研究報(bào)告
- 汽車(chē)升降玻璃項(xiàng)目可行性研究報(bào)告
- 物業(yè)管理消防安全管理職責(zé)與流程
- 內(nèi)蒙古硅膠助劑項(xiàng)目可行性研究報(bào)告模板范文
- 垃圾分類(lèi)的開(kāi)展實(shí)施方案
- 初中生自我激勵(lì)與成長(zhǎng)故事
- 體育賽事應(yīng)急救援工作小組職責(zé)
- 老年患者跌倒風(fēng)險(xiǎn)評(píng)估及應(yīng)急流程范文
- 伺服驅(qū)動(dòng)器項(xiàng)目可行性分析報(bào)告
- 2025年xx銀行分行國(guó)際業(yè)務(wù)拓展計(jì)劃
- 冀教版三至四年級(jí)《發(fā)展柔韌性練習(xí)》評(píng)課稿
- 漢語(yǔ)拼音聲母韻母拼讀全表打印版
- 運(yùn)動(dòng)系統(tǒng)病例分析01
- 天津市南開(kāi)區(qū)南開(kāi)中學(xué)2022-2023學(xué)年物理高二下期末復(fù)習(xí)檢測(cè)試題含解析
- 澠池鋁礦礦產(chǎn)資源開(kāi)采與生態(tài)修復(fù)方案
- 功與功率 課件高一下學(xué)期物理人教版(2019)必修第二冊(cè)
- 成品入庫(kù)、發(fā)貨流程圖
- 光柵安全檢查作業(yè)指導(dǎo)
- 不對(duì)稱(chēng)短路故障分析與計(jì)算(電力系統(tǒng)課程設(shè)計(jì))
- GB/T 28731-2012固體生物質(zhì)燃料工業(yè)分析方法
- 局下屬企業(yè)全面審計(jì)實(shí)施方案
評(píng)論
0/150
提交評(píng)論