




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1. 創(chuàng)建 C#控制臺(tái)應(yīng)用程序。設(shè)計(jì)一個(gè)簡(jiǎn)單的密碼驗(yàn)證程序,若密碼正確,則顯示“歡迎 進(jìn)入本系統(tǒng)! ” ,否則顯示“密碼輸入錯(cuò)誤,請(qǐng)重新輸入! ” 。若連續(xù)三次密碼輸入錯(cuò)誤,則顯 示“對(duì)不起,超過(guò)最多輸入次數(shù),取消服務(wù)! ” ,程序退出。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1class Programstatic void Main(string argsint i = 0;string mima = "
2、;123321"bool k = true;Console.WriteLine(" "Console.WriteLine(" 歡迎使用本系統(tǒng) nn"Console.WriteLine(" 請(qǐng)輸入您的服務(wù)秘密 "while (kstring get = Console.ReadLine(;if (get != mimai+;if (i = 3Console.WriteLine("對(duì)不起,您輸入的密碼錯(cuò)誤次數(shù)已經(jīng)超過(guò)三 次, nn已取消服務(wù),請(qǐng)按任意鍵結(jié)束! ! "Console.ReadLine(; bre
3、ak;elseConsole.WriteLine("對(duì)不起,您輸入的密碼有誤,請(qǐng)重新輸入 ! "elseConsole.WriteLine("歡迎進(jìn)入本系統(tǒng)! ! "Console.ReadLine(; break;2. 創(chuàng)建一個(gè)點(diǎn) Point 類,屬性包括橫坐標(biāo)、縱坐標(biāo)。要求能夠完成點(diǎn)的移動(dòng)操作、求兩點(diǎn) 距離操作, 并利用運(yùn)算符重載, 對(duì)兩個(gè)點(diǎn)進(jìn)行比較 (相等和不等 依據(jù)是兩坐標(biāo)點(diǎn)相等指它 們橫坐標(biāo)和縱坐標(biāo)分別相等。編寫一個(gè)測(cè)試程序?qū)Ξa(chǎn)生的類的功能進(jìn)行驗(yàn)證。using System;using System.Collections.Generic;us
4、ing System.Linq;using System.Text;namespace _1_2class pointpublic double x, y;public point(double a, double bx = a; y = b;public void move(double a, double bx = x + a;y = y + b;public static bool operator =(point a, point bif (a.x = b.x && (a.y = b.yreturn true;elsereturn false;public static
5、 bool operator !=(point a, point bif (a.x != b.x | (a.y != b.yreturn true;elsereturn false;public double distance(point a, point breturn Math.Sqrt(a.x - b.x * (a.x - b.x + (a.y - b.y * (a.y - b.y;class Programstatic void Main(point a=new point(1,1 ;point b = new point(2, 2;Console.WriteLine("a點(diǎn)
6、的坐標(biāo):(0, 1 ",a.x,a.y;Console.WriteLine("b點(diǎn)的坐標(biāo):(0, 1 ", b.x, b.y;Console.WriteLine("現(xiàn)在將對(duì) a 點(diǎn)的坐標(biāo)進(jìn)行移動(dòng) 2和 3,請(qǐng)按 enter 鍵開始移 動(dòng)! "/string get1 = Console.ReadLine(;/ Console.WriteLine("現(xiàn)在將對(duì) a 點(diǎn)的縱坐標(biāo)進(jìn)行移動(dòng),請(qǐng)輸入您要移動(dòng)的 Y 坐 標(biāo)數(shù) "/ string get2 = Console.ReadLine(;/a.move(doubleget1,(do
7、ubleget2;a.move(2, 3;Console.ReadLine(;Console.WriteLine("移動(dòng)后 a 點(diǎn)得坐標(biāo)是:(0,1", a.x, a.y;Console.WriteLine("a點(diǎn)坐標(biāo)移動(dòng)后與 b 點(diǎn)坐標(biāo)的距離是:0", a.distance(a,b; if (a = bConsole.WriteLine("a點(diǎn)和 b 點(diǎn)相等 n"elseConsole.WriteLine("a點(diǎn)和 b 點(diǎn)不相等 n"Console.WriteLine("現(xiàn)將對(duì) b 點(diǎn)坐標(biāo)分別移動(dòng) 3和
8、 4,按 enter 確認(rèn)! " b.move(1, 2;Console.ReadLine(;Console.WriteLine("移動(dòng)后 b 點(diǎn)得坐標(biāo)是:(0,1", b.x, b.y;/Console.WriteLine("b點(diǎn)坐標(biāo)移動(dòng)后與 a 點(diǎn)坐標(biāo)的距離是:0", b.distance(a,b; if (a = bConsole.WriteLine("a點(diǎn)和 b 點(diǎn)相等 "elseConsole.WriteLine("a點(diǎn)和 b 點(diǎn)不相等 "Console.ReadLine(;3. 定義一個(gè)順序表
9、 SqlList 類,要求能夠完成在順序表中插入元素和刪除元素,確定元素 在順序表中位置, 檢索元素, 清空表, 判斷表是否為空等操作。 編寫一個(gè)測(cè)試程序進(jìn)行驗(yàn)證。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace shiyan13class SqlListprivate int list;private int len;public SqlList(int a, int blist = a;len = b;public void print(/Console.
10、WriteLine("順序表序列是:"for (int i = 0; i < len; i+Console.Write("00", listi;public bool insert(int c, int dint temp = 0, i = d - 1;for (; i < len; i+temp = listi;listi = c;c = temp;if (d < len | d < 1Console.WriteLine("n對(duì)不起, 您的插入位置有誤, 請(qǐng)重新輸入插入位置 !" return false;r
11、eturn true;public bool delete(int eint j = e;for (; j < len; j+listj - 1 = listj;len-;if (e < len | e < 1Console.WriteLine("n對(duì)不起,沒(méi)有您要?jiǎng)h除的元素,請(qǐng)重新輸入您要?jiǎng)h 除的位置 !n"return false;return true;public int lookup(int aint i = 0;for (i = 0; i < len; i+if (listi = abreak;if (i = lenreturn -1;e
12、lsereturn (i + 1;public int reserch(int aint i = 0, j = 0;for (; i < len; i+if (listi = aj+;return j;public void clear(len = 0;public void show(if (len = 0Console .WriteLine("順序表已清空! n"elseConsole.WriteLine("順序表未清空! n"class Programstatic void Main(string argsint a=1,2,3,4,5,6,
13、7,8,9;int b = 9;SqlList list = new SqlList(a,b;Console.WriteLine("順序表初始化為:"list.print(;list.insert(4, 6;Console.WriteLine("nn在順序表的第 6個(gè)數(shù)據(jù)前插入數(shù)據(jù) 4后為:"list.print(;Console.WriteLine("nn在順序表檢索數(shù)據(jù) 3, 得到的個(gè)數(shù):0", list.reserch(3; Console.WriteLine("nn在順序表檢索數(shù)據(jù) 4, 得到的個(gè)數(shù):0",
14、 list.reserch(4; Console.WriteLine("nn在 順 序 表 找 到 第 一 個(gè) 數(shù) 據(jù) 3所 在 位 置 :0", list.lookup(3;Console.WriteLine("nn在 順 序 表 找 到 第 一 個(gè) 數(shù) 據(jù) 4所 在 位 置 :0", list.lookup(4;list.delete(3;Console.WriteLine("nn刪除順序表的第 3個(gè)數(shù)據(jù):"list.print(;Console.WriteLine("nn判斷順序表是否為空:"list.sho
15、w(;list.clear(;Console.WriteLine("n清空順序表后判斷:"list.show(;Console.Read(;4. 定義一個(gè) shape 抽象類,利用它作為基類派生出 Rectangle 、 Circle 等具體形狀類,已知 具體形狀類均具有兩個(gè)方法 GetArea 和 GetPerim , 分別用來(lái)求形狀的面積和周長(zhǎng)。 最后編寫 一個(gè)測(cè)試程序?qū)Ξa(chǎn)生的類的功能進(jìn)行驗(yàn)證。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespa
16、ce shiyan14public abstract class Shapepublic double GetArea(return 0;public double GetPerim(return 0;public class Circle:Shapeprivate double r;public Circle(double ar=a;public new double GetArea( return Math.PI*r*r;public new double GetPerim( return Math.PI*2*r;public class Rectangle : Shapeprivate
17、double a, b;public Rectangle(double c, double d a = c; b = d;public new double GetArea( return a*b;public new double GetPerim(return (2*(a+b;class Programstatic void Main(string argsCircle str = new Circle(3;Rectangle ch = new Rectangle(5, 10;Console.WriteLine("n0圓的半徑初始化為:R=3n"Console.Writ
18、eLine(" =>圓的面積為:0n", str.GetArea(;Console.WriteLine(" =>圓的周長(zhǎng)為:0n", str.GetPerim(;Console.WriteLine("n0初始化長(zhǎng)方形 長(zhǎng)為:10,寬為:5n"Console.WriteLine(" =>長(zhǎng)方形面積:0n", ch.GetArea(;Console.WriteLine(" =>長(zhǎng)方形周長(zhǎng):0n", ch.GetPerim(;Console.Read(;5. 編程實(shí)現(xiàn)一個(gè)模擬鬧
19、鈴的程序,具有鬧鈴、繼續(xù)鬧鈴、打會(huì)盹兒,停止鬧鈴的功能。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace shiyan15public class clockSystem.Media.SoundPlayer music;public void alarm(music = new System.Media.SoundPlayer("Track06.wav"music.Play(;public void goon(music = new Sys
20、tem.Media.SoundPlayer("Track06.wav"music.Play(;public void rest(music.Stop(;System.Threading.Thread.Sleep(15000;music = new System.Media.SoundPlayer("Track06.wav"music.Play(;class Programstatic void Main(string argsclock a=new clock(;Console.WriteLine("nn=主 菜 單 ="Consol
21、e.WriteLine("nn 1 : 鬧鈴 "Console.WriteLine("nn 2 :繼續(xù)鬧鈴 "Console.WriteLine("nn 3 :稍后鬧鈴 "Console.WriteLine("nn 4 :停止鬧鈴 "Console.WriteLine("n請(qǐng)輸入您要選擇的編號(hào) "int i = Console.Read(;Console.ReadLine(;if (i = 1Environment.Exit(0;a.alarm(;System.Console.Clear(;Console.WriteLine("nn=主 菜 單 ="Console.WriteLine("nn 2 :繼續(xù)鬧鈴 "Console.WriteLine("nn 3 :稍后鬧鈴 "Console.WriteLine("
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 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ì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度智慧城市建設(shè)勞務(wù)工解除合同及數(shù)據(jù)安全服務(wù)協(xié)議
- 2025年度酒吧租賃與環(huán)保設(shè)施維護(hù)合同
- 二零二五年度家庭贍養(yǎng)協(xié)議書:構(gòu)建和諧家庭關(guān)系的贍養(yǎng)協(xié)議范本
- 二零二五年度股東投資風(fēng)險(xiǎn)控制合同
- 小學(xué)體育教師年度教學(xué)工作計(jì)劃
- 2025年航空器材維護(hù)技術(shù)策劃合作協(xié)議書
- 2025年協(xié)作戰(zhàn)略協(xié)議
- 2025年公共建筑安全性評(píng)估與加固協(xié)議
- 2025年農(nóng)業(yè)設(shè)施租賃合同模板
- 2025年保健品經(jīng)銷合同文本
- 江蘇天嘉宜化工有限公司特大事故警示專題教育課件
- 2023年體育單招英語(yǔ)語(yǔ)法練習(xí)專題08 非謂語(yǔ)動(dòng)詞(含解析)
- 如何抓好學(xué)生的行為習(xí)慣課件
- 商場(chǎng)裝修管理規(guī)范課件
- 2023年青島恒星科技學(xué)院?jiǎn)握芯C合素質(zhì)考試筆試題庫(kù)及答案解析
- 民族宗教新疆歷史課件
- PVC注塑問(wèn)題的改善措施
- 頸動(dòng)脈斑塊講稿課件
- 部編語(yǔ)文八年級(jí)上冊(cè)1-3單元教材分析課件
- (完整版)SF-36評(píng)分標(biāo)準(zhǔn)
- 研究思路圖模板
評(píng)論
0/150
提交評(píng)論