C程序設計實驗報告413_第1頁
C程序設計實驗報告413_第2頁
C程序設計實驗報告413_第3頁
已閱讀5頁,還剩39頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、實驗報告書寫要求實驗報告原則上要求學生手寫,要求書寫工整。若因課程特點 需打印的,標題采用四號黑體,正文采用小四號宋體,單倍行距。 紙張一律采用A4的紙張。實驗報告書寫說明實驗報告中實驗追求和要求、實驗儀器和設備、實驗內(nèi)容與過 程、實驗結(jié)果與分析這四項內(nèi)容為必需項。教師可根據(jù)學科特點和 實驗具體要求增加項目。.填寫注意事項(1)細致觀察,及時、準確、如實記錄。(2)準確說明,層次清晰。(3)盡量采用專用術語來說明事物。(4)外文、符號、公式要準確,應使用統(tǒng)一要求的名詞和符 號。(5)應獨立完成實驗報告的書寫,嚴禁抄襲、復印,一經(jīng)發(fā) 現(xiàn),以零分論處。實驗報告批改說明實驗報告的批改要及時、認真、仔

2、細,一律用紅色筆批改。實 驗報告的批改成績采用五級記分制或百分制,按金陵科技學院課 堂教學實施細則中作業(yè)批閱成績評定要求執(zhí)行。實驗報告裝訂要求實驗批改完畢后,任課老師將每門課程的每個實驗項追求實驗 報告以自然班為單位、按學號升序排列,裝訂成冊,并附上一份該 門課程的實驗大綱。.實驗項目名稱:C#基礎編程實驗學時:6同組學生姓名:實驗地點:1318實驗日期:10月5日-10月19日實驗成績:批 改 教 師: 批 改 進實驗 1 C# 基礎編程一、實驗追求1、熟悉 Visual Studio .NET 開發(fā)環(huán)境。2、掌握C#應用程序的基本制作過程。3、掌握C#的數(shù)據(jù)類型,運算符以及表達式的使用。4

3、、掌握分支和循環(huán)語句的使用方法。5、掌握一維數(shù)組,二維數(shù)組及數(shù)組型數(shù)組的使用。二、實驗要求( 1)編寫程序要規(guī)范、正確,上機調(diào)試過程和結(jié)果要有記錄 (2)做完實驗后給出本實驗的實驗報告。三、實驗設備、環(huán)境安裝有 Visual Studio .NET 軟件。四、實驗步驟1、分析題意。2、根據(jù)題目要求,新建項目。3、編寫并輸入相關的程序代碼。5、運行與調(diào)試項目。6、保存項目。五、實驗內(nèi)容1、 編寫一個簡單的控制臺應用程序,打印一行文字(如你的姓名 )。using System;using System.Collections.Generic;using System.Linq;using Syst

4、em.Text;namespace one.firstclass Programstatic void Main(string args)System.Co nsole.WriteLi ne(我叫王蕾?。?2、編寫一個簡單的 Windows 應用程序,在窗體 Load 事件中書寫代碼,標簽中顯示你 的姓名。using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing; using System.Linq; using System.

5、Text;using System.Windows.Forms; namespace one.second public partial class Form1 : Form public Form1() InitializeComponent();private void Form1_Load(object sender, EventArgs e. ) this.Text = Windows 程序 ; Label lblShow = new Label(); lblShow.Location = new Point(20, 30); lblShow.AutoSize = true; lblS

6、how.Text = 王蕾! ; this.Controls.Add(lblShow); 3、編寫一個一個程序,用來判斷輸入的是大寫字母,小寫字母,數(shù)字還是其他的字 符。using System;using System.Collections.Generic;using System.Text; namespace one.thirdclass Programstatic void Main(string args)Con sole.WriteLi ne(” 請輸入一個字符:); char c = Convert.ToChar(Console.ReadLine(); if (c=a&c=A&

7、c=Z)Console.WriteLine(這是一個字母);if (char.IsDigit(c)Con sole .WriteL ine(這是一個數(shù)字);4、分別用 while , do-while ,for 循環(huán)求 1到 100 的和。using System;using System.Collections.Generic;class Programstatic void Main(string args)int i = 1, sum = 0;while (i = 100)sum = sum + i; i+;Console.WriteLine(1 到 100 的自然數(shù)之和為: using

8、 System;using System.Collections.Generic;class Programstatic void Main(string args)int i = 1, sum = 0;dosum = sum + i; i+;while (i = 100);Co nsole .WriteL in e(1到100的自然數(shù)的和為:using System;using System.Collections.Generic; + sum);+ sum );class Programstatic void Main(string args)int i , sum = 0;for (i

9、= 1; i = 100; i+)sum = sum + i;Console.WriteLine(1 到 100 的自然數(shù)的和為: + sum);5、定義一個一維數(shù)組,用隨機數(shù)為此賦值,用foreach 循環(huán)輸出其中的內(nèi)容。using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace first.fiveclass Programstatic void Main(string args)int a = 0,1,2,3,4;foreach (int i in a)Conso

10、le.WriteLine(ai); 6、實現(xiàn)二維數(shù)組的輸入和輸出。using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace first.sixclass Programstatic void Main(string args)int, a = new int2, 3 1, 2, 3 , 4, 5, 6 ; .for (int i = 0;i 2; i+)for (int j =0; j 3; j+) Con sole.WriteLi ne(ai, j); 7、實現(xiàn)數(shù)組

11、型數(shù)組的輸入和輸出。using System;using System.Collectio ns.Ge neric;using System丄inq;using System.Text;n amespace first.seve nclass Programstatic void Main( stri ng args)in t a = new in t new in t 1,2, 3 , new in t 4, 5, 6 ;for (int i = 0; i a.Le ngth; i+)for (i nt j = 0; j ai.Le ngth; j+)Con sole.WriteLi ne(

12、aij);六、實驗思想到(遇到問題及解決辦法,編程后的心得思想到)剛開始編程的時候覺得無從下手,盡管我們已經(jīng)學了好幾種高級編程語言,但每個都 有其獨特的地方,稍不留神就會混淆。.通過這次實驗,我思想到到課后復習鞏固的重要性。在編程的時候,很多內(nèi)容都不記得,需要去翻書。不得不說,實驗是鞏固課程的好方法!本次實驗,我熟悉Visual Studio .NET 開發(fā)環(huán)境。掌握了 C#應用程序的基本制作過程。掌握了C#的數(shù)據(jù)類型,運算符以及表達式的使用。掌握了分支和循環(huán)語句的使用方法以及一維數(shù)組,二維數(shù)組及數(shù)組 型數(shù)組的使用。.實驗項目名稱:類與對象實驗學時:6同組學生姓名:實驗地點:1318實驗日期:

13、10月26日-11月9日實驗成績:批改教師:批改進度: 實驗2類與對象一、實驗追求、要求(1)掌握類的定義和使用。(2)掌握類的數(shù)據(jù)成員,屬性的定義和使用。(3)掌握方法的定義,調(diào)用和重載以及方法參數(shù)的傳遞。(4)掌握構造函數(shù)的定義和使用。二、實驗要求(1)編寫程序要規(guī)范、正確,上機調(diào)試過程和結(jié)果要有記錄。(2)做完實驗后給出本實驗的實驗報告。三、實驗設備、環(huán)境安裝有 Visual Studio .NET 軟件。四、實驗步驟1、分析題意。2、根據(jù)題目要求,新建項目。3、編寫并輸入相關的程序代碼。5、運行與調(diào)試項目。6、保存項目。五、實驗內(nèi)容1、定義一個方法,實現(xiàn)兩個數(shù)的交換(分別把參數(shù)按值傳遞

14、和按引用傳遞)。using System;using System.Collectio ns.Ge neric;using System.Text;n amespace sec ond.oneclass Programstatic void Main( stri ng args)Swaper s = new Swaper();Console.WriteLine(輸入 x 的值:);int a = Convert.ToInt32(Console.ReadLine();Console.WriteLine(輸入 y 的值:);int b=Convert.ToInt32(Console.ReadLin

15、e();Console.WriteLine(s.Swap(a, b); Console.WriteLine(s.Swap(ref a,ref b);class Swaperpublic string Swap(int x, int y)int temp;temp = x;x = y;y = temp;return string.Format(按值傳參交換之后:x=0,y=1,x,y);public string Swap(ref int x, ref int y)int temp;temp = x;x = y;y = temp;return string.Format(按引用傳參交換之后:x=

16、0,y=1, x, y); 2、定義一個方法,實現(xiàn)數(shù)組的排序。using System;using System.Collections.Generic;using System.Text;namespace second.twoclass Programpublic class sortpublic void change(int a)Con sole.WriteLi ne(排序前,數(shù)組順序為:);show(a);int i, j, m; for (i = 0; i = 0 & m aj)/ 判斷 i 下標的數(shù)是否大于 j 下標的數(shù) aj + 1 = aj;如果i下標大于j把j往后移一個位j

17、-;aj+1 = m; /當不大于 j 的時候就把 M 的值放到 i 下標下面 j+1 是為了下標減到最前時考慮 -1 + 1 還是下標的最前面 .Con sole.WriteLi ne(排序后,數(shù)組順序為:); show(a);void show(int a)int i;for (i = 0; i 10; i+)Console.Write(0 , ai);Console.WriteLine();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

18、、定義一個學生類,把學生類當作對象來傳遞。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace second.threeclass Programpublic class studentpublic void st()int a = 999;public class stpublic void aa(student s)Console.WriteLine(s);static void Main(string args)student s=new student();

19、 st s1 = new st();s1.aa(s);4、定義一個方法,求兩個數(shù)的和和差,通過參數(shù)把這兩個值帶回。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace second.fourclass Programpublic class sumpublic 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

20、sum();int a = 10;int b = 3;int m, n;s.ab(out m, out n, a, b);Console.WriteLine(0+1=2;0-1=3,a,b,m,n); 5、用構造函數(shù)重載,實現(xiàn)矩形的面積,圓的面積,梯形的面積。 using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace secong.fiveclass Programpublic class square public double area; public squar

21、e() 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)area = (a + b) / 2 * h;static void Main(string args) double a, b, h,area;b=1 ,面積area=1, a,a = 2; b = 5; h = 3; square s = new square(a,b);Console.WriteLine( 求矩形面積,

22、長為 a=0 ,寬為 area=2,a,b,s.area);.square i = new square(a);Console.WriteLine( 求圓形面積,半徑 a=0 ,面積 i.area);.square j = new square(a, b, h);Console.WriteLine( 求梯形面積,上底為 a=0 ,下底為 b=1 ,高 為 h=2 面積 area=3, a, b,h, j.area);.6、設計一個 windows 應用程序,在該程序中定義一個學生類和班級類,以處理每個學 生的學號,姓名,語文,數(shù)學和英語成績,要求: .1)能查詢每個學生的總成績。2)能顯示全班

23、前三名的名單。3)能顯示單科成績最高分和不及格的學生名單。4)能統(tǒng)計全班學生的平均成績。5)能顯示各科成績不同分數(shù)段的學生人數(shù)的百分比。Stude nt 類:using System; using System.Collections.Generic;using System.Text; namespace Test2_6public class Studentpublic string stuNo;public string name;public double chinese;public double math;public double english;public double su

24、mScoreget return chinese + math + english; Stude ntList 類:using System; using System.Collections.Generic;using System.Text; namespace Test2_6public class StudentList:Studentint snums;public Student stu=new Student50;public StudentList() snums = 0;public void addstu(Student s) stusnums = s; snums+;pu

25、blic int searchstu(string name)int i;for (i = 0; i snums; i+)if ( = name) break;if (i = snums) return -1; else return i;/給所有成績排序,用后面實現(xiàn)前三名的排名 public void ProThree()for (int i = 0; i snums; i+)int k = i;for (int j = i + 1; j stuk.sumScore) k = j;if (k != i)Student temp; temp = stuk; stuk = st

26、ui; stui = temp;/顯示單科成績的最高分 public int HighScore(int k)int p = 0;if (k = 0)for (int i = 1; i stup.math) p = i;else if (k = 1)for (int i = 1; i stup.chinese) p = i; elsefor (int i = 1; i stup.chinese) p = i; return p;/顯示不及格名單public string BuhgName(int k)string name= if (k = 0)for (int i = 0; i snums;

27、 i+)if (stui.math 60) name +=+n;else if (k = 1)for (int i = 0; i snums; i+)if (stui.chinese 60) name += + n;.elsefor (int i = 0; i snums; i+)if (stui.english 60) name += + n;.return name;public string getHL()string Maxer = , Loser = ;Maxer += 單科數(shù)學最高: + stuHighScore(0).na

28、me + n; .Maxer += 單科語文最高: + stuHighScore(1).name + n;.Maxer += 單科英語最高: + stuHighScore(2).name + n;.Loser += 單科數(shù)學掛科名單: +BuhgName(0) + n;Loser += 單科語文掛科名單: + BuhgName(1) + n;Loser += 單科英語掛科名單: + BuhgName(2) + n; return Maxer + n + Loser;/全班的平均成績public string SumScore()double sum = 0;double avg=0;for (

29、int i = 0; i snums; i+)sum = sum + stui.sumScore;avg = sum / snums;return 班級總分平均分: +avg;/各科成績不同分數(shù)段的學生百分比/英語成績各分數(shù)段百分比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 90) & (stui.chinese = 100) .sumC1+;else if (80 =

30、 stui.chinese) & (stui.chinese 90).sumC2+;else if(70=stui.chinese)& (stui.chinese 80) .sumC3+;else if(60=stui.chinese)&(stui.chinese 70).sumC4+;elsesumC5+;per2 = sumC2 / snums;per3 = sumC3 / snums;per4 = sumC4 / snums;per5 = sumC5 / snums;8090:+per2+0, sumC5 = .0;return 語文成績百分比: +n+90100:+per1+8070:

31、+per3+ 7060:+per4+ 60 以下的:+per5;./數(shù)學成績各分數(shù)段百分比public string PerM()double per1, per2, per3, per4, per5;double sumC1 = 0, sumC2 = 0, sumC3 = 0, sumC4 =for (int i = 0; i 90) &(stui.math = 100)sumC1+;else if (80 = stui.math) & (stui.math 90) .sumC2+;else if (70 = stui.math) & (stui.math 80) .sumC3+;else

32、if (60 = stui.math) & (stui.math 70) .sumC4+;else sumC5+; per2 = sumC2 / snums;per3 = sumC3 / snums;per4 = sumC4 / snums;per5 = sumC5 / snums;return stri ng.Format( 數(shù)學成績百分比:” + n + 90100: + perl + 8090: + per2 + 8070: + per3 + 7060: + per4 + 60以下的: + per5);./英語成績各分數(shù)段百分比public string PerE()double per

33、1, per2, per3, per4, per5;double sumC1 = 0, sumC2 = 0, sumC3 = 0, sumC4 = 0, sumC5 = .0;for (int i = 0; i 90) & (stui.english = 100) .sumC1+;else if (80 = stui.english) & (stui.english 90) .sumC2+;else if (70 = stui.english) & (stui.english 80) .sumC3+;else if (60 = stui.english) & (stui.english 70)

34、 .sumC4+;else sumC5+; per2 = sumC2 / snums;per3 = sumC3 / snums;per4 = sumC4 / snums;per5 = sumC5 / snums;return stri ng.Format( 數(shù)學成績百分比:” + n + 90100: + perl + 8090: + per2 + 8070: + per3 + 7060: + per4 + 60以下的: + per5);.From 窗體代碼:using System;using System.Collections.Generic;using System.Component

35、Model;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Test2_6public partial class Form1 : Formpublic Form1()InitializeComponent();public StudentList sl = new StudentList();private void btnAdd_Click(object sender, EventArgs e.)Student s = new Student();s.

36、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(添加成功);private void btnSearch_Click(object sender, EventArgs e)int pos = sl.searchstu(this.textBox1.Te

37、xt);if (pos != -1)label7.Text = this.textBox1.Text +的總成績:sl.stupos.sumScore;else MessageBox.Show(不 存在這我! ); private void btnFinish_Click(object sender, EventArgs e)label7.Text =前 3 名:+n;for (int i = 0; i 3; i+)sl.ProThree();label7.Text+= sl.stui. name+n;label7.Text += sl.getHL()+n;label7.Text += Co

38、nvert.ToStri ng(sl.SumScore()+n;label7.Text += sl.PerC()+n;label7.Text += sl.PerM()+n;label7.Text += sl.PerE()+n;六、實驗思想到(遇到問題及解決辦法,編程后的心得思想到)通過本次實驗,我掌握了類的定義與使用。掌握了類的數(shù)據(jù)成員,屬性的 定義和使用。掌握了方法的定義,調(diào)用和重載以及方法參數(shù)的傳遞以及構造函 數(shù)的定義和使用。值得注意的是:本次實驗中 return的使用以及所在的位置, 類型轉(zhuǎn)換時也經(jīng)常用到.實驗項目名稱:繼承與多態(tài)實驗學時:6同組學生姓名:實驗地點:1318實驗日期:11

39、月16日-11月30日實驗成績:批改教師:批改進度:實驗3繼承與多態(tài)一、實驗追求、要求(1)掌握類的繼承性與多態(tài)性。(2)掌握虛方法的定義以及如何使用虛方法實現(xiàn)多態(tài)。(3)掌握抽象類的定義以及如何使用抽象方法實現(xiàn)多態(tài)。二、實驗要求(1)編寫程序要規(guī)范、正確,上機調(diào)試過程和結(jié)果要有記錄。(2)做完實驗后給出本實驗的實驗報告。三、實驗設備、環(huán)境安裝有 Visual Studio .NET 軟件。四、實驗步驟1、分析題意。2、根據(jù)題目要求,新建項目。3、編寫并輸入相關的程序代碼。5、運行與調(diào)試項目。6、保存項目。五、實驗內(nèi)容1、設計一個 Windows應用程序,在該程序中第一步構造一個學生基本類,再

40、分別構造 小學生、中學生、大學生派生類,當輸入相關數(shù)據(jù),單擊不用的按鈕時,將分別創(chuàng)建不同 的學生類對象,并輸出當前學生的總?cè)藬?shù),該學生的姓名,學生類型,平均成績。.Stude nt 類:using System;using System.Collectio ns.Ge neric;using System.Text;n amespace Test3_1public abstract class Stude ntprotected stri ng n ame;protected int age;public static int number;public Student(string name

41、, int age) = name; this.age = age; number+;public string Nameget return name; public abstract double Average();public class Pupil : Studentprotected double chinese;protected double math;public Pupil(string name, int age, double chinese, double math. ): base(name, age) this.chinese = chines

42、e; this.math = math;public override double Average()return (chinese + math) / 2;public class Middle : Studentprotected 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 = chine

43、se; this.math = math; this.english = english;public override double Average() return (chinese + math + english) / 3;public class College : Studentprotected double required; protected double elective;public College(string name, int age, double required, double elective. ) : base(name, age) this.requi

44、red = required; this.elective = elective;public override double Average()return (required + elective) / 2;Form 窗體內(nèi)的代碼:using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Test3_1public partial class

45、 Form1 : Formpublic Form1()InitializeComponent();private void btnSmall_Click(object sender, EventArgs e.)Pupil p = new Pupil(txtName.Text,Convert.ToInt32(txtAge.Text),Convert.ToDouble(txtChinese.Text ),Convert.ToDouble(txtMath.Text);.lblShow.Text += 總?cè)藬?shù) : +Convert.ToString( Student.number) + , + 姓名:

46、 + p.Name + , + 小學生 + , + 平均成績?yōu)椋?+ p.Average() +n; .private void btnMiddle_Click(object sender, EventArgs e).Middle m = new Middle(txtName.Text, Convert.ToInt32(txtAge.Text),Convert.ToDouble(txtChinese.Text),Convert.ToDouble(txtMath.Text),Convert.ToDouble(TxtEnglish.Text);.lblShow.Text += 總?cè)藬?shù) : + Co

47、nvert.ToString(Student.number) + , + 姓名: + m.Name + , + 中學生 + , + 平均成績?yōu)椋?+ m.Average() + n; .private void btnBig_Click(object sender, EventArgs e).College c = new College(txtName.Text, Convert.ToInt32(txtAge.Text),Convert.ToDouble(txtChinese.Text), Convert.ToDouble(txtMath.Text);.lblShow.Text += 總?cè)藬?shù)

48、 : + Convert.ToString(Student.number) + , + 姓名: + c.Name + , + 大學生 + , + 平均成績?yōu)椋?+ c.Average() + n; .2、設計一個 Windows 應用程序,在該程序中定義平面圖形抽象類和派生類圓,矩形和 三角形。Figure 類代碼:using System;using System.Collections.Generic;using System.Text;namespace Test3_2public abstract class Figurepublic abstract double Area();pu

49、blic class Circle:Figuredouble radius;public Circle(double r)radius = r;public override double Area()return radius * radius * 3.14;public class JUxing:Figuredouble chang;double kuan;public JUxing(double c, double k)this.chang = c;this.kuan = k;public override double Area()return chang * kuan;public

50、class San:Figuredouble bian;double heigth;public San(double b, double h)this.bian = b; this.heigth = h;public override double Area()return bian * heigth / 2;Form 窗體代碼:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Test3_2public parti

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論