




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上學(xué) 生 實(shí) 驗(yàn) 報(bào) 告 冊(理工類)課程名稱: C#程序設(shè)計(jì)實(shí)驗(yàn) 專業(yè)班級:14計(jì)算機(jī)科學(xué)與技術(shù)(單)(1) 學(xué)生學(xué)號: 學(xué)生姓名: 邵佳楠 所屬院部: 計(jì)算機(jī)工程學(xué)院 指導(dǎo)教師: 馬xx 2016 2017學(xué)年 第 1 學(xué)期 金陵科技學(xué)院教務(wù)處制專心-專注-專業(yè)實(shí)驗(yàn)項(xiàng)目名稱: C#基礎(chǔ)編程 實(shí)驗(yàn)學(xué)時: 6 同組學(xué)生姓名: 無 實(shí)驗(yàn)地點(diǎn): A104 實(shí)驗(yàn)日期: 實(shí)驗(yàn)成績: 批改教師: 馬青霞 批改時間: 實(shí)驗(yàn)1 C#基礎(chǔ)編程一、實(shí)驗(yàn)?zāi)康?、熟悉Visual Studio .NET開發(fā)環(huán)境;2、掌握C#應(yīng)用程序的基本操作過程;3、掌握C#的數(shù)據(jù)類型,運(yùn)算符以及表達(dá)式的使
2、用;4、掌握分支和循環(huán)語句的使用方法;5、掌握一維數(shù)組,二維數(shù)組及數(shù)組型數(shù)組的使用。二、實(shí)驗(yàn)要求1、編寫程序要規(guī)范、正確,上機(jī)調(diào)試過程和結(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編寫一個簡單的控制臺應(yīng)用程序(1)打開VS開發(fā)工具。(2)在新建項(xiàng)目對話框中選擇Visual C#,模板選擇控制臺應(yīng)用程序,給項(xiàng)目命名為HelloConsole,然后點(diǎn)“瀏覽”按鈕,選擇項(xiàng)目的存儲目錄。(3)在Program.cs文件中,鍵入代碼如下:using System;Namespace Hell
3、oConsole class Program static void Main(string args) String name; Console.Write("請輸入姓名:"); name = Console.ReadLine(); Console.WriteLine("歡迎0光臨", name); Console.ReadLine(); (4)按F5或者點(diǎn)啟動調(diào)試按鈕運(yùn)行程序,在控制臺中輸入“你的姓名”,回車。2、采用VS編寫一個簡單的windows窗體應(yīng)用程序(1)打開開發(fā)工具。(2)在新建項(xiàng)目對話框中選擇Visual C#,模板選擇windows
4、窗體應(yīng)用程序,給項(xiàng)目命名為HelloForm,然后點(diǎn)“瀏覽”按鈕,選擇項(xiàng)目的存儲目錄。(3)在Form1窗體中拖放一個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)啟動調(diào)試按鈕運(yùn)行程序,在文本框中輸入“你的姓名”,單擊“確定”按鈕。運(yùn)行結(jié)果(請截圖):1、 采用VS編寫一個簡單的控制臺應(yīng)用程序2、采用VS編寫一個簡單的windows窗體應(yīng)用程序五、實(shí)驗(yàn)內(nèi)容1、編寫一個控制臺應(yīng)用程序,輸入自己的班級、學(xué)號、姓名并顯示。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("請輸入班級:"); grade = Console.ReadLine(); Console.WriteLine("請輸入姓名:"); name = Console.ReadLine(); Console.WriteLine("請輸入學(xué)號:"); number = Co
7、nsole.ReadLine(); Console .WriteLine ("班級:0,姓名:1,學(xué)號:2",grade,name ,number ); Console .ReadLine (); 2、編寫一個Windows窗體應(yīng)用程序,輸入自己的班級、學(xué)號、姓名并顯示。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 ("班級:"+textBox1.Text+"n姓名:"+textBox2.Text +"n
9、學(xué)號:"+textBox3 .Text ); 3、編寫一個程序,用來判斷輸入的是大寫字母,小寫字母,數(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("請輸入一個字符:"); char
10、c = Convert.ToChar(Console.ReadLine(); if (c >= 'a' && c <= 'z') Console.WriteLine("該字母是小寫字母"); else if (c >= 'A' && c <= 'Z') Console.WriteLine("該字母是大寫字母"); else if (char.IsDigit(c) Console.WriteLine("該字母是數(shù)字")
11、; else Console.WriteLine("其它字符"); Console.ReadLine(); 4、編寫一個程序,實(shí)現(xià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、定義一個一維數(shù)組,通過鍵盤輸入10個兩位整數(shù),用foreach
14、循環(huán)輸出其中的內(nèi)容。并求出其中的最大值和平均值,把結(jié)果顯示出來。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("請輸入第0個數(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、定義一個5行5列二維數(shù)組,用隨機(jī)數(shù)給二維數(shù)組賦值,按照5行5列的格式顯示出二維數(shù)組的內(nè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)目名稱: 面向?qū)ο缶幊?實(shí)驗(yàn)學(xué)時: 6 同組學(xué)生姓名: 無 實(shí)驗(yàn)地點(diǎn): A104 實(shí)驗(yàn)日期: 實(shí)驗(yàn)成績: 批改教師: 馬青霞 批改時間: 實(shí)驗(yàn)2 面向?qū)ο缶幊桃弧?shí)驗(yàn)?zāi)康摹⒁?、理解面向?qū)ο蟪绦蛟O(shè)計(jì)的思想和基本概念;2、掌握類的定義和使用;3、掌握類的數(shù)據(jù)成員,屬性的定義和使用;4、掌握方法的定義,調(diào)用和重載以及方法參數(shù)的傳遞;5、掌握構(gòu)造函數(shù)和析構(gòu)函數(shù)的定義和使用。7、掌握虛方法的定義以及如何用虛方法實(shí)現(xiàn)多態(tài);8、
19、掌握抽象類的定義以及如何用用抽象方法實(shí)現(xiàn)多態(tài);9、掌握集合的創(chuàng)建和操作方法;10、掌握接口的定義及使用方法。二、實(shí)驗(yàn)要求1、編寫程序要規(guī)范、正確,上機(jī)調(diào)試過程和結(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、利用方法的重載兩個整數(shù)和兩個雙精度類型數(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、定義一個Area類,用構(gòu)造函數(shù)重載,實(shí)現(xiàn)矩形的面積,圓的面積,梯形的面積,定義一個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、定義一個Students類,包括學(xué)號、姓名、性別、年齡4個屬性,要求在性別屬性中增加對性別的判斷(只能輸入男和女),在年齡屬性中提供對不合法(年齡在10至50之間)輸入的判斷,并提供方法顯示學(xué)生信息。構(gòu)建該類,并測試。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é)號:0rn姓名:1rn性別:2rn年齡:3", mz._id, mz._name, mz._sex, mz._age); Console.ReadKey(); 4、設(shè)計(jì)一個Windows應(yīng)用程序,在該程序中首先構(gòu)造一個學(xué)生基本類,再分別構(gòu)造小學(xué)生、中學(xué)生、大學(xué)生派生類,當(dāng)輸入相關(guān)數(shù)據(jù),單擊不用的按鈕時,將分別創(chuàng)建不同的學(xué)生類對象,并輸出當(dāng)前學(xué)生的總?cè)藬?shù),該學(xué)生的姓名,學(xué)生類型,平均成績。程序要求:(1)每個學(xué)生都有的字段為姓名、年齡。(2)小學(xué)生的字段還有語
29、文,數(shù)學(xué),用來表示這兩科的成績。(3)中學(xué)生在此基礎(chǔ)上增加英語成績。(4)大學(xué)生分為必修課和選修課兩項(xiàng)成績。(5)學(xué)生類提供方法來統(tǒng)計(jì)自己的總成績并輸出。(6)通過靜態(tài)成員自動記錄學(xué)生總?cè)藬?shù)。(7)成員初始化通過構(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(",平均成績?yōu)?:N2:n", total() / 2); else if (type = "中學(xué)生") result += string.Format(",平均成績?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ì)一個Windows應(yīng)用程序,在該程序中定義平面圖形抽象類Figure和派生類圓(Circle)、矩形(Rectangle)和三角形(Triangle)。該程序?qū)崿F(xiàn)的功能包括:輸入相應(yīng)圖形的參數(shù),如矩形的長和寬,單擊相應(yīng)的按鈕,根據(jù)輸入?yún)?shù)創(chuàng)建圖形類并輸出該對象的面積。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. 本站所有資源如無特殊說明,都需要本地電腦安裝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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《2025智能設(shè)備采購委托項(xiàng)目管理合同》
- 2025合同范本食品供應(yīng)合同
- 2025年委托借款合同模板
- 2025便利店店面轉(zhuǎn)讓合同范本
- 2025標(biāo)準(zhǔn)化的苗木購銷合同
- 2025版商品房購買合同范本
- 2025年上海市農(nóng)產(chǎn)品買賣合同示范文本
- 《年級魅力》課件
- 2025授權(quán)合同范本(標(biāo)準(zhǔn))
- 《金融市場概述》課件
- 智能物流無人機(jī)配送行業(yè)發(fā)展建議
- DB11-T854-2023占道作業(yè)交通安全設(shè)施設(shè)置技術(shù)要求
- 2024年國家義務(wù)教育質(zhì)量監(jiān)測-八年級心理健康考核試題
- 第12課《終身學(xué)習(xí) 持續(xù)發(fā)展》第2框《信息素養(yǎng)助力發(fā)展》-【中職專用】《心理健康與職業(yè)生涯》同步課堂課件
- 2024年濟(jì)南城市發(fā)展集團(tuán)投資開發(fā)有限公司招聘筆試參考題庫含答案解析
- 糧食熏蒸操作要點(diǎn)培訓(xùn)課件
- 同等學(xué)力申碩-同等學(xué)力(政治學(xué))筆試(2018-2023年)真題摘選含答案
- 園林植物的識別與應(yīng)用-灌木園林植物的識別與應(yīng)用
- 親子鑒定報(bào)告樣本
- 飼料市場分析報(bào)告
- pvc的生產(chǎn)工藝流程圖
評論
0/150
提交評論