




下載本文檔
版權(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.collections.generic;using system.text;namespace consoleapplication2 class pen public string color; private int price; public pen() color=black; price=5; public void setprice(int newprice) price=newprice; public int getprice() return price;
2、public void setcolor(string newcolor) 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 pen public stri
3、ng color; private int 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 new
4、color) color = newcolor; public string getcolor() return color; class test public 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, hispen.get
5、price(); 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.collections.generic;using system.text;namespace consoleapplication8 class program public class app public int app1(int x
6、) return 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.collection
7、s.generic;using system.text;namespace consoleapplication6 public class chartest private 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 charte
8、st(); result.ch = (char)(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 overloadapp public static void main() chartest a = new chartest(l); chartest b = new chartest(l); cons
9、ole.writeline(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)編寫一個(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)建屬于test1類
10、的一個(gè)對(duì)象,不傳遞參數(shù);在main方法中創(chuàng)建屬于test1類的另一個(gè)對(duì)象,傳遞一個(gè)字符串“this is a string”;using system;using system.collections.generic;using system.text;namespace consoleapplication8 class program class test1 public string test; public test1() test = test1; public test1(string s) test = s; static void main(string args) strin
11、g x = this is a string; test1 app1 = new test1(); test1 app2 = new test1(x); console.writeline(0, app1.test); console.writeline(0, app2.test); (6)編寫一個(gè)控制臺(tái)程序,完成下列功能并輸出結(jié)果:創(chuàng)建一個(gè)類a,在a中編寫一個(gè)可以被重寫的帶int類型參數(shù)的方法mymethod,并在該方法中輸出傳遞的整型值加10后的結(jié)果;再創(chuàng)建一個(gè)類b,使其繼承自類a,然后重寫a中的mymethod方法,將a中接收的整型值加50,并輸出結(jié)果; 在main方法中分別創(chuàng)建類a和類
12、b的對(duì)象,并分別調(diào)用mymethod方法;using system;class classa public static int mymethod(int i) i=i+10; return i;class classb:classapublic static int mymethod(int i)i=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 b) return a+b; public static int sub(int a,int b) return 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.wr
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 人才公寓裝修合同范例
- 公司公章制作合同范例范例
- 農(nóng)村賣方合同范例
- 倉(cāng)庫(kù)建材配送合同范例
- 分紅簡(jiǎn)約合同范例
- 代理派遣服務(wù)合同范例
- 與餐飲合作合同范例
- 中心設(shè)計(jì)合同范例
- 書買賣協(xié)議合同范例
- 出售種植大棚合同范例
- GB/T 17639-2023土工合成材料長(zhǎng)絲紡粘針刺非織造土工布
- 2023年廣東省深圳市龍華區(qū)中考道德與法治二模試卷及答案解析
- 舟山國(guó)儲(chǔ)基地?cái)U(kuò)建項(xiàng)目開(kāi)山回填與隧道工程爆破項(xiàng)目設(shè)計(jì)方案
- 中國(guó)書畫藝術(shù)品投資(山東聯(lián)盟)知到章節(jié)答案智慧樹(shù)2023年山東財(cái)經(jīng)大學(xué)
- 信用修復(fù)申請(qǐng)文書(當(dāng)事人適用)
- 高中學(xué)生社會(huì)實(shí)踐活動(dòng)100例
- 2023年新改版教科版六年級(jí)下冊(cè)科學(xué)全冊(cè)教案(新課標(biāo))
- 天津漁港防波堤施工組織設(shè)計(jì)
- 03SG520-2 實(shí)腹式鋼吊車梁(中輕級(jí)工作制 A1~A5 Q345鋼 跨度6m,7.5m,9m)
- Access數(shù)據(jù)庫(kù)程序設(shè)計(jì)上機(jī)操作練習(xí)題2
- 《最優(yōu)化方法》復(fù)習(xí)題(含答案)
評(píng)論
0/150
提交評(píng)論