




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、面向?qū)ο蟪绦蛟O(shè)計(jì)編程上機(jī)作業(yè)題目:(1調(diào)試構(gòu)造函數(shù)Pen(例題using System;using System.Text;namespace ConsoleApplication2class Penpublic string Color;private int Price;public Pen( Color="BLACK"Price=5;public void SetPrice(int newPrice Price=newPrice;public int GetPrice( return Price; public void SetColor(string newColo
2、r Color=newColor; public string GetColor( return Color; class Test public static void Main( Pen myPen=new Pen( ;Console.WriteLine("The price is 0",myPen.GetPrice(;Console.WriteLine("The Color is 0",myPen.Color;(2調(diào)試構(gòu)造函數(shù)重載Pen(例題using System;class Penpublic string Color;private int
3、Price;public Pen( Color = "BLACK" Price = 5;public Pen(string newColor, int newPrice Color = newColor;Price = newPrice;public void SetPrice(int newPrice Price = newPrice; public void SetPrice( Price = 5; public int GetPrice( return Price; public void SetColor(string newColor Color = newCol
4、or; public string GetColor( return Color; class Testpublic static void Main( Pen myPen = new Pen(;Pen hisPen = new Pen("GREEN", 8;Console.WriteLine("The price is 0", myPen.GetPrice(;Console.WriteLine("The Color is 0", myPen.Color;Console.WriteLine("The price is 0&q
5、uot;, hisPen.GetPrice(;Console.WriteLine("The Color is 0", hisPen.GetColor(; hisPen.SetPrice(;Console.WriteLine("The price is 0", hisPen.GetPrice(; (3使用重載方法求5和5.65的平方。using System;using System.Text;namespace ConsoleApplication8class Program public class apppublic int app1(int x r
6、eturn x * x; public double app1(double y return y * y; static void Main(string args app x = new app(;Console.WriteLine("5的平方是0", x.app1(5;Console.WriteLine("5.65的平方是0", x.app1(5.65;(4將運(yùn)算符+和- -進(jìn)行重載,使之可對(duì)字符型數(shù)據(jù)進(jìn)行運(yùn)算,即:對(duì)一個(gè)字符型變量a,當(dāng)a=L時(shí)a+(或+a的值為M, a- -(或- -a的值為Kusing System;using System.
7、Text;namespace ConsoleApplication6public class charTestprivate char ch;public charTest( this.ch = ' ' public charTest(char val this.ch = val; public char c get return this.ch; set this.ch = value; static public charTest operator +(charTest orig charTest Result = new charTest(;Result.ch = (ch
8、ar(orig.ch + 1;return Result;static public charTest operator -(charTest orig charTest Result = new charTest(;Result.ch = (char(orig.ch - 1;return Result;public class overloadApppublic static void Main( charTest a = new charTest('L'charTest b = new charTest('L'Console.WriteLine("
9、Original value is :0,1", a.c, b.c;a = +a;b = -b;Console.WriteLine("Current value is :0.1", a.c, b.c;a = +a;b = -b;Console.WriteLine("Final value is:0,1", a.c, b.c;(5編寫(xiě)一個(gè)控制臺(tái)程序,完成下列功能并輸出結(jié)果:創(chuàng)建一個(gè)類Test1,用無(wú)參數(shù)的構(gòu)造函數(shù)輸出該類的類名;增加一個(gè)重載的構(gòu)造函數(shù),帶有一個(gè)string類型的參數(shù),在此構(gòu)造函數(shù)中將傳遞的字符串打印出來(lái);在Main方法中創(chuàng)建屬于T
10、est1類的一個(gè)對(duì)象,不傳遞參數(shù);在Main方法中創(chuàng)建屬于Test1類的另一個(gè)對(duì)象,傳遞一個(gè)字符串“This is a string”; using System;using System.Text;namespace ConsoleApplication8class Programclass Test1public string test;public Test1( test = "Test1" public Test1(string s test = s; static void Main(string argsstring x = "This is a st
11、ring"Test1 app1 = new Test1(;Test1 app2 = new Test1(x;Console.WriteLine("0", app1.test;Console.WriteLine("0", app2.test;(6編寫(xiě)一個(gè)控制臺(tái)程序,完成下列功能并輸出結(jié)果:創(chuàng)建一個(gè)類A,在A中編寫(xiě)一個(gè)可以被重寫(xiě)的帶int類型參數(shù)的方法MyMethod,并在該方法中輸出傳遞的整型值加10后的結(jié)果;再創(chuàng)建一個(gè)類B,使其繼承自類A,然后重寫(xiě)A中的MyMethod方法,將A中接收的整型值加50,并輸出結(jié)果;在Main方法中分別創(chuàng)建類A和類
12、B的對(duì)象,并分別調(diào)用MyMethod方法;using System;class ClassA public static int MyMethod(int ii=i+10; return i;class ClassB:ClassApublic static int MyMethod(int ii=i+50;return i;class Testpublic static void Main(ClassA a=new ClassA(;ClassB b=new ClassB(;Console.WriteLine("請(qǐng)輸入一個(gè)數(shù):"string s=Console.ReadLin
13、e(;int x=Int32.Parse(s;Console.WriteLine("調(diào)用A類方法:0", ClassA.MyMethod(x;Console.WriteLine("調(diào)用B類方法:0", ClassB.MyMethod(x;(7利用委托實(shí)現(xiàn):當(dāng)用戶輸入一個(gè)字符1時(shí),調(diào)用兩個(gè)整數(shù)相加的方法,計(jì)算兩整數(shù)之和;當(dāng)用戶輸入一個(gè)字符2時(shí),調(diào)用兩個(gè)整數(shù)相減的方法,計(jì)算兩整數(shù)之差。using System;class Appdelegate int process(int a,int b;public static int add(int a,int breturn a+b;public static int sub(int a,int breturn a-b;static void Main(string s,s1,s2;process Pro;Console.WriteLine("請(qǐng)輸入一個(gè)數(shù):"s1=Console.ReadLine(;int a=Int32.Parse(s1;Console.WriteLine("請(qǐng)輸入另一個(gè)數(shù):"
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 商業(yè)智慧教育美妝品牌的市場(chǎng)策略與方向
- 醫(yī)療科技的創(chuàng)新之路基于設(shè)計(jì)思維的實(shí)踐與探索
- 全球教育趨勢(shì)與國(guó)際化發(fā)展戰(zhàn)略規(guī)劃
- 從學(xué)生心理角度看教育改革與發(fā)展趨勢(shì)
- 商業(yè)培訓(xùn)中的互動(dòng)游戲化教學(xué)策略研究
- 抖音商戶直播樣品簽收確認(rèn)制度
- 抖音商戶直播停留時(shí)長(zhǎng)優(yōu)化方案執(zhí)行制度
- 公交優(yōu)先戰(zhàn)略下2025年城市交通擁堵治理的智能交通設(shè)施布局分析報(bào)告
- CDK9-IN-38-生命科學(xué)試劑-MCE
- 浙江省溫州市各學(xué)校2025屆化學(xué)九年級(jí)第一學(xué)期期末檢測(cè)試題含解析
- 2025年云南省時(shí)事政治考試試卷帶解析附完整答案(考點(diǎn)梳理)
- 車子刮擦協(xié)議書(shū)
- 詩(shī)歌鑒賞|蘇軾《鶴嘆》注釋+賞析+試題
- JT-T 329-2025 公路橋梁預(yù)應(yīng)力鋼絞線用錨具、夾具和連接器
- 2024年質(zhì)量工程師備考常見(jiàn)問(wèn)答試題及答案
- 2025-2030全球及中國(guó)管道運(yùn)輸服務(wù)行業(yè)市場(chǎng)現(xiàn)狀供需分析及投資評(píng)估規(guī)劃分析研究報(bào)告
- 安慶市桐城經(jīng)開(kāi)區(qū)建設(shè)投資集團(tuán)有限公司招聘筆試題庫(kù)2025
- JJF 2244-2025公共機(jī)構(gòu)重點(diǎn)用能單位能源資源計(jì)量審查規(guī)范
- 警犬基地人員管理制度
- 2025年甘肅省建筑安全員B證(項(xiàng)目經(jīng)理)考試題庫(kù)
- ICU感控管理分析報(bào)告
評(píng)論
0/150
提交評(píng)論