C#編程環(huán)境實驗報告3解讀_第1頁
C#編程環(huán)境實驗報告3解讀_第2頁
C#編程環(huán)境實驗報告3解讀_第3頁
C#編程環(huán)境實驗報告3解讀_第4頁
C#編程環(huán)境實驗報告3解讀_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、江西理工大學(xué)軟件學(xué)院計算機類課程實驗報告課程名稱:C#程序設(shè)計教程班 級: 11級軟會(4)班姓 名:黃健學(xué) 號:11222122江西理工大學(xué)軟件學(xué)院實驗三稱 名 驗程 編 象 對 ,刖 面期 日 驗實驗?zāi)康?、要求及?nèi)容化 重 始 的 初 法 定 法 對員 方 烙 勺 吏 目 沁知 釧 題 3是學(xué) 念 別 年 完 加悔1解己 的 里 自 m老 玉 其 編 格 臥 及 隊翊 聲 七 對 聲 的 3 向 的 法 2 印 矣3 -丿二_ 丁1 二至 二至 - 圳 MM 3 : 理 掌等 掌。 : 的深冷象冷等容驗 目 加 熟對 熟載內(nèi)實 驗 驗 出 實 1 2 3 實 揀 、 、 一 二實驗環(huán)境4P

2、 仏 Z3WX塚 地 o C3實驗3-1操作:1)閱讀程序2)編輯、編譯和運行程序3) 自己完成:(1)分析靜態(tài)成員 total_rects和total_rect_area的值 及構(gòu)造函數(shù)的調(diào)用次序。(2)將注釋1和注釋2的花括號去掉,運行結(jié)果將 發(fā)生什么變化?為什么?實驗3-2操作:1)閱讀程序算法描述及實驗步驟2)編輯、編譯和運行程序3) 自己完成:將上述程序中class Test32中的三個方法:(1)void sortTitle(Card book , int index)(2)void sortAuthor(Card book , int index)(3)void sortTota

3、l(Card book , int index)改寫成一個方法 sort(Card book,int index)其中增加的參數(shù) method指示按什么字段排序。重新修改、編譯和運行程序,觀察運行結(jié)果。實驗3-3操作:1)閱讀程序2) 自己完成:(1)修改Card類,增加每日食用額度不超過5000 的限制功能。(2 )再次修改Card類,要求對銀行卡進行操作 前必須驗證用戶密碼,并且在輸入密碼時屏幕上用“* ”掩碼顯示。為簡單起見,初始密碼設(shè)為123456.4實驗3-1:kvEPwTNi 魯匚嚴門亡Rec t C In t r Lit.尸 in t ” Lnt &9ina I.i*u.c t

4、ny recle nuLinlwT*d C -n 1. n C t. An Id Aiva.B Aa 5CRc t, CCReie tftCnslr-ue t iny ieet Any le2rcnlr*!1 trvA* : UHRflCLfliiylH Z : Hn IghIL : 1 ,Width;C:Rbc (.OCofiiA fcaruct Ln塹 j-we tan le riljuiJb 了Tot* 1 rac t. Ansi 1 :.f Ju g小 交彷丈書憑按貯2 tt直口 Su t lior- dmim 尸工口 a 1 = G-lJ-士FZ.11Tint調(diào)試過程及實驗結(jié)果實驗3

5、-3一k曰川I.忘髭Lk聿:4. 上s.fMiv忙嚴芳芒尸.IIH書需熬希哼暮讓臺諒廠 熾駕戸V說骨U.舍3寶律1話警七冬妄僉妄吳穴更n雯4寫吏心 得 體 會通過這次實踐,我覺得我學(xué)到了很多東西,不光光 是在知識層面上的,整體都有了進一步的了解, 更是認識 到編程的不容易,一個看似簡單的程序,原來也有這么多 的代碼,但是那么一個復(fù)雜的代碼,如果深入研究后你會 發(fā)現(xiàn)其實各個代碼之間都是有聯(lián)系的, 一個看上去巨大的 程序?qū)嶋H上是由若干個函數(shù)、方法、類等組成的。以前對 于那些小的程序尚能敲一敲,看得懂。對于大的程序就很 容易感到束手無策。我覺得在問題面前我們應(yīng)該先要冷靜 地分析一下,將大問題分解成一

6、個個的小問題, 再各個擊 破。雖然成功地完成了程序,但是自己本身尚有許多不 足之處,需要進一步的學(xué)習(xí)和鞏固。 不管是做什么都要有 堅韌不拔的意志,在遇到困難的時候要懂得堅持,也要學(xué) 會分析問題、解決問題。同時,很多的東西,理解了,可是在實現(xiàn)的時候還 是有很多的錯誤發(fā)生,在以后的練習(xí)和實踐中, 應(yīng)該多動 手,遇到問題多思考,即使方案不是最優(yōu)的也要想辦法自 己解決,然后和好的方案進行比較, 從中找出自己的差距 在哪里。最后感謝老師在實驗中對我們的指導(dǎo)7實驗3-1:using System;using System.Collections.Generic;using System.Linq;usin

7、g System.Text;class CRectprivate int top, bottom, left, right;public static int total_rects = 0;public static long total_rect_area = 0;public CRect()left = top = right = bottom = 0;total_rects+;total_rect_area += getHeight() * getWidth();Console .WriteLine( CRect() Constructing recangle number0,tota

8、l_rects);Console .WriteLine( Total rectangle areas is:0, total_rect_area);public CRect( int x1, int y1, int x2, int y2)left = x1; top = y1;right = x2; bottom = y2;total_rects+;total_rect_area += getHeight() * getWidth();Console .WriteLine( CRect(int,int,int,int) Constructing rectanglenumber0 , total

9、_rects);Console .WriteLine( Total rectangle areas is:0, total_rect_area);public CRect( CRect r)left = r.l eft; right = r.right;top = r.top; bottom = r.bottom;total_rects+;total_rect_area += getHeight() * getWidth();Console .WriteLine(CRect(CRect&) Constructing rectangle number0total_rects);,total_re

10、ct_area);Console .WriteLine( Total rectangle areas is:0 public int getHeight() return top bottom ? top-bottom : bottom-top; public int getWidth()return right left ? right-left : left-right; 6publicstaticint getTotalRects() return total_rects; publicstaticlong getTotalRectArea()public staticint getTo

11、talRects()return total_rects; public staticlong getTotalRectArea()return total_rect_area; public class Test31public static void Main()CRect rect1 = new CRect(1,3, 6, 4), rect2 =new CRect(rect1);Console .WriteLine( Rectangle 2:Height:0, rect2.getHeight();Console .WriteLine( ,Width:0, rect2.getWidth()

12、;CRect rect3 = new CRect();Console .Write( Rectangle 2:Height:0, rect2.getHeight();Console .WriteLine( ,Width:0, rect3.getWidth();Console .Write( total_rects=0 , CRect.total_rects);Console .WriteLine( total_rect_area=0 , CRect.toConsole .Read();附錄Console.WriteLine(Total rectangle areas is:0,total_re

13、ct_area);public int getHeight() return topbottom?top-bottom:bottom-top;public int getWidth() return rightleft?right-left:left-right;public static int getTotalRects() return total_rects;public static long getTotalRectArea() return total_rect_area;public class Test31public static void Main()CRect rect

14、1=new CRect(1,3,6,4),rect2=new CRect(rect1);Console.Write(Rectangle 2:Height:0,rect2.getHeight();Console.WriteLine(,Width:0,rect2.getWidth(); /注釋1CRect rect3=new CRect();Console.Write(Rectangle 3:Height:0,rect3.getHeight();Console.WriteLine(,Width:0,rect3.getWidth(); /注釋2Console.Write(total_rects=0,

15、CRect.total_rects);Console.WriteLine(,total_rest_area=0,CRect.total_rect_area);Console.Read();【3-2】using System;using System.Collections.Generic;using Syste m. Linq;using System.Text;namespace ConsoleApplicationlclass Cardprivate string title, author;private int total;附錄public Card()title = ; author

16、 =;total = 0;public Card(string title, string author, int total)this.title = title;this.author = author;this.total = total;public void store(ref Card card)title = card.title; author = card.author; total = card.total;public void show()Console .WriteLine (Title:0,author:1,total:2,title,author ,total )

17、;public string Titleget return title; set title = value; public string Authorget return author; set author = value; public int Totalget return total; set total = value; public class Test32public static void Main()Test32 T=new Test32 ();Card books;int index;附錄int i,k;Card card=new Card ();Console .Wr

18、ite (請輸入需要入庫圖書的總數(shù););string sline=Console .ReadLine ();int num=int .Parse (sline);books=new Card num;for (i=0;inum ;i+)books i=new Card ();index=new int num;for (i=0;inum;i+)Console .Write (請輸入書名:);card .Title =Console .ReadLine ();Console .Write (請輸入作者:);card .Author=Console .ReadLine ();Console .Wr

19、ite (請輸入入庫量:);sline=Console .ReadLine ();card .Total =int .Parse (sline);books i.store (ref card );indexi=i ;Console .Write (請選擇按什么關(guān)鍵字排序(1.按書名,2.按作者,3.按入庫量);sline =Console .ReadLine ();int choice=int .Parse (sline);switch(choice)case 1:T .sortTitle(books ,index);break ;case 2:T .sortAuthor(books,ind

20、ex);break ;case 3:T .sortTotal(books,index);break;for (i=0;inum ;i+)k=indexi;(booksk).show();Console .Read ();附錄void sortTitle(Card book,int index)int i,j,m,n,temp;for (m=0;mindex .Length -1;m+)for (n=0;n0)temp =index n;index n=index n+1;index n+1=temp ;void sortAuthor(Card book,int index)int i,j,m,

21、n,temp;for (m=0;mindex .Length -1;m+)for (n=0;n0)temp =index n;index n=index n+1;index n+1=temp ;void sortTotal(Card book,int index)int i,j,m,n,temp;for (m=0;mindex .Length -1;m+)for (n=0;nbook j.Total)temp =index n;index n=index n+1;index n+1=temp ;14【3-3】using System;using System.Collections.Gener

22、ic;using Syste m. Linq;using System.Text;namespace ConsoleApplication3class Cardlong cardNo;decimal balance;int currentNum;static int number;decimal currentMoney;public Card()currentMoney=new decimalnumber;public Card(long No,decimal Balance)cardNo=No;balance=Balance; currentMoney=new decimalnumber;

23、public void store(decimal Money,out int status)if (currentNum=number)status=0;return;if(balance+Money0)status=-1;return;currentMoneycurrentNum=Money;balance+=Money;currentNum+;status=1;15public void show()Console.WriteLine(” 卡號:0, 當(dāng)前余額:,當(dāng)日發(fā)生業(yè)務(wù)次數(shù):2,cardNo,balance,currentNum);for(int i=0;icurrentNum;i

24、+)Console.WriteLine(” 當(dāng)日存款 /取款的情況:0,currentMoneyi);static public int Numberset number=value;public long CardNogetreturn cardNo ;public class Test33附public static void Main()錄Test33 T=new Test33 ();Card person;int Num,status,k;long CardNo;decimal Balance,Money;Console .Write (請輸入允許當(dāng)日存款或取款的總次數(shù):);string sline=Console .ReadLine ();Card .Number =int .Parse (sline);Console .Write (請輸入某銀行發(fā)出的儲蓄卡總數(shù):);sline =Console .ReadLine ();Num =int.Parse (sline );person =new C

溫馨提示

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

評論

0/150

提交評論