![四川理工C#網(wǎng)絡(luò)編程(1—5章)答案_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/26/d691af0f-5aa3-4c45-9123-2248ae1dc583/d691af0f-5aa3-4c45-9123-2248ae1dc5831.gif)
![四川理工C#網(wǎng)絡(luò)編程(1—5章)答案_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/26/d691af0f-5aa3-4c45-9123-2248ae1dc583/d691af0f-5aa3-4c45-9123-2248ae1dc5832.gif)
![四川理工C#網(wǎng)絡(luò)編程(1—5章)答案_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/26/d691af0f-5aa3-4c45-9123-2248ae1dc583/d691af0f-5aa3-4c45-9123-2248ae1dc5833.gif)
![四川理工C#網(wǎng)絡(luò)編程(1—5章)答案_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/26/d691af0f-5aa3-4c45-9123-2248ae1dc583/d691af0f-5aa3-4c45-9123-2248ae1dc5834.gif)
![四川理工C#網(wǎng)絡(luò)編程(1—5章)答案_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-11/26/d691af0f-5aa3-4c45-9123-2248ae1dc583/d691af0f-5aa3-4c45-9123-2248ae1dc5835.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、四川理工大學2012級計科四班 百年孤獨(匿名胖鳥) 提供第一章1如何確定最佳的斷行位置1. 表達式應完整清晰地體現(xiàn)其內(nèi)在的邏輯關(guān)系,因此一般選擇整個表達式中最高的關(guān)系層次進行斷行,比如“=“,”|”等,并將分隔符留在上一行;2. 當參數(shù)數(shù)量較多時,較長或含有表達式時,為了將邏輯體現(xiàn)得更為清晰,應將函數(shù)調(diào)用中的每個參數(shù)都分行書寫;3. 對于SQL語句或其他較長的復合語句,應將每個子句單獨寫成一行,便于理解。2九九乘法表using System;using System.Collections.Generici;using System.Linq;using System.Text;namesp
2、ace Homework class MulTable /乘法表類#region public void mulTablei() for (int ii = 1; i < 10; i+) for (int j = 1; j <= i; j+) String s = j + "x" + i + "=" + i * j; Console.Writiie(s.PadRighti(8); /使用PadRighti的作用是對齊 Console.WriteLine(); #endregion class Program /主類 static void M
3、ain(string args) MulTable m = new MulTable();/實例化一個對象m m.mulTable();/調(diào)用mulTable函數(shù)打印九九表 3關(guān)于類與對象的思考用我個人的話說,類就相當于一個模板,它不能直接使用,用模板造出來的東西就是對象,對象才可以被使用。第二章1注釋的用途1. 解釋代碼的意,用符合人類思維方式的描述性文字闡明代碼的功能和意圖;2. 對局部變量進行含義,取值范圍,單位等的說明;3. 充當代碼標題,便于掌握代碼總體結(jié)構(gòu),快速定位錯誤,闡明分支與循環(huán)控制結(jié)構(gòu);4. 指出例外情況,為達到特殊效果有意為之,并對其說明原由。2復數(shù)類Complexusi
4、ng System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Homework / <summary> / Complex 實現(xiàn)復數(shù)的加減功能 / </summary> class Complex/一個簡單的復數(shù)類 / <summary> / real 為實數(shù)的實部 / image 為實數(shù)的虛部 / </summary> private Int32 real; private Int32 image; / <summary&g
5、t; / 初始化Homework.Complex的新實例 / </summary> public Complex()/無參構(gòu)造函數(shù) this.real = 0; this.image = 0; / <summary> / 使用指定的參數(shù)列表初始化Homework.Complex的新實例 / </summary> / <param name="r">形參實部</param> / <param name="i">形參虛部</param> public Complex(int
6、r, int i)/帶參構(gòu)造函數(shù) this.real = r; this.image = i; / <summary> / Add實現(xiàn)兩個復數(shù)相加的功能 / </summary> / <param name="com">類型為Complex的形參</param> / <returns>返回一個a+bi形式的字符串</returns> public String Add(Complex com)/復數(shù)加法方法 Int32 addReal = this.real + com.real;/addReal為實部
7、相加結(jié)果 Int32 addImage = this.image + com.image;/addImage為虛部相加結(jié)果 if (0 != addReal && 0 > addImage)/實部不為0,虛部小于0,結(jié)果形如:2 - 5i return addReal.ToString() + addImage.ToString() + "i" else if (0 = addReal && 0 != addImage)/實部為0,虛部不為0,結(jié)果形如:5i return addImage.ToString() + "i&qu
8、ot; else if (0 != addReal && 0 = addImage)/實部不為0,虛部為0,結(jié)果形如:2 return addReal.ToString(); else if (0 = addReal && 0 = addImage)/實部虛部都為0,即結(jié)果為:0 return "0" else/實部不為0,虛部大于0,結(jié)果形如:2+5i return addReal.ToString()+ "+" + addImage.ToString() + "i" / <summary>
9、; / Sub實現(xiàn)復數(shù)相減的功能 / </summary> / <param name="com">類型為Complex的形參</param> / <returns>返回一個形如a+bi的字符串</returns> public String Sub(Complex com)/復數(shù)減法方法 Int32 subReal = this.real - com.real;/subReal為實部相減結(jié)果 Int32 subImage = this.image - com.image;/subImage為虛部相減結(jié)果 if (
10、0 != subReal && 0 > subImage)/實部不為0,虛部小于0,結(jié)果形如:2 - 5i return subReal.ToString() + subImage.ToString() + "i" else if (0 = subReal && 0 != subImage)/ 實部為0,虛部不為0,結(jié)果形如:5i return subImage.ToString() + "i" else if (0 != subReal && 0 = subImage)/ 實部不為0,虛部為0,結(jié)果
11、形如:2 return subReal.ToString(); else if (0 = subReal && 0 = subImage)/ 實部虛部都為0,即結(jié)果為:0 return "0" else/實部不為0,虛部大于0,結(jié)果形如:2+5i return subReal.ToString() + "+" + subImage.ToString() + "i" class Program/主函數(shù)類 static void Main(string args) /實例化兩個對象c1,c2 Complex c1 = ne
12、w Complex(1, 2); Complex c2 = new Complex(2, -2); /輸出兩個復數(shù)相互加減的結(jié)果 Console.WriteLine(c1.Add(c2); Console.WriteLine(c1.Sub(c2); Console.WriteLine(c2.Add(c1); Console.WriteLine(c2.Sub(c1); 3圓類Circleusing System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Homework / <
13、;summary> / 提供計算圓周長和面積的功能 / </summary> class Circle / <summary> / radius為圓的半徑 / </summary> private double radius; / <summary> / 初始化Homework.Circle的新實例 / </summary> public Circle() this.radius = 0; / <summary> / 用指定的參數(shù)列表初始化Homework.Circle的新實例 / </summary>
14、/ <param name="r">形參為圓的半徑,double類型</param> public Circle(double r) this.radius = r; / <summary> / 實現(xiàn)計算圓周長的功能 / </summary> / <returns>返回圓的周長,類型為double</returns> public double Girth() return Math.PI * this.radius * 2; / <summary> / 實現(xiàn)計算圓面積的功能 / </
15、summary> / <returns>返回圓的面積,類型為double</returns> public double Ariea() return Math.PI * this.radius * this.radius; class Program/主函數(shù)類 static void Main(string args) Circle c = new Circle(10);/實例化一個對象c Console.WriteLine(c.Girth();/輸出圓c的周長 Console.WriteLine(c.Area();/輸出圓c的面積 第三章1字符使用規(guī)則1. 所
16、有的標識符只能由字母,數(shù)字,下劃線組成,且第一個字符不能為數(shù)字,下劃線主要用于分隔汗多個單詞的常量;2. 標識符中不能包含空格,標點符號,運算符等其他符號;3. 標識符區(qū)分大小寫;4. 利用英語單詞的組合命名,做到一目了然;5. 標識符不能與C#的關(guān)鍵字相同;6. 標識符盡量不與C#中類庫名相同。2Pascal與Camel規(guī)則的區(qū)別,何時采用Camel1. Pascal: 標識符中每個單詞的首字母大寫,其余小寫;Camel: 標識符的第一個單詞的首字母小寫,其余每個單詞首字母大寫,剩余小寫2. 外部程序不可見的“私有及受保護的字段”,“局部變量”,“函數(shù)參數(shù)”使用Camel規(guī)則。3創(chuàng)建一個Wi
17、ndows工程,實現(xiàn)登錄界面。namespace HomeworkWinForm partial class FormLogin / <summary> / 必要的設(shè)計器變量 / </summary> private System.ComponentModel.IContainer components = null; / <summary> / 清理所有正在使用的資源 / </summary> / <param name="disposing">如果應釋放托管資源,為 true;否則為false</para
18、m> protected override void Dispose(bool disposing) if (disposing && (components != null) components.Dispose(); base.Dispose(disposing); #region Windows 窗體設(shè)計器生成的代碼 / <summary> / 設(shè)計器支持所需的方法 不要 / 使用代碼編輯器修改修此方法的內(nèi)容。 / </summary> private void InitializeComponent() this.labelUser = n
19、ew System.Windows.Forms.Label(); this.labelPassword = new System.Windows.Forms.Label(); this.textBoxUser = new System.Windows.Forms.TextBox(); this.textBoxPassword = new System.Windows.Forms.TextBox(); this.buttonSignIn = new System.Windows.Forms.Button(); this.buttonCancle = new System.Windows.Form
20、s.Button(); this.labelPassword2 = new System.Windows.Forms.Label(); this.textBoxPassword2 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); / / labelUser / this.labelUser.AutoSize = true; this.labelUser.Location = new System.Drawing.Point(30, 26); this.labelUser.Name = "labelUser"
21、; this.labelUser.Size = new System.Drawing.Size(67, 15); this.labelUser.TabIndex = 0; this.labelUser.Text = "用戶名:" / / textBoxUser / this.textBoxUser.Locationi = new System.Drawing.Point(107, 23); this.textBoxUser.MaxLength = 20; this.textBoxUser.Name = "textBoxUser" this.textBox
22、User.Size = new System.Drawing.Size(159, 25); this.textBoxUser.TabIndex = 2; / / labelPassword / this.labelPassword.AutoSize = true; this.labelPassword.Location = new System.Drawing.Point(30, 67); this.labelPassword.Name = "labelPassword" this.labelPassword.Size = new System.Drawing.Size(6
23、7, 15); this.labelPassword.TabIndex = 1; this.labelPassword.Text = "密碼:" / / textBoxPassword / this.textBoxPassword.Location = new System.Drawing.Point(107, 64); this.textBoxPassword.MaxLength = 18; this.textBoxPassword.Name = "textBoxPassword" this.textBoxPassword.PasswordChar =
24、 '#' this.textBoxPassword.Size = new System.Drawing.Size(159, 25); this.textBoxPassword.TabIndex = 3; / / labelPassword2 / this.labelPassword2.AutoSize = true; this.labelPassword2.Location = new System.Drawing.Point(30, 103); this.labelPassword2.Name = "labelPassword2" this.labelPa
25、ssword2.Size = new System.Drawing.Size(82, 15); this.labelPassword2.TabIndex = 6; this.labelPassword2.Text = "確認密碼:" / / textBoxPassword2 / this.textBoxPassword2.Location = new System.Drawing.Point(107, 100); this.textBoxPassword2.MaxLength = 18; this.textBoxPassword2.Name = "textBoxP
26、assword2" this.textBoxPassword2.PasswordChar = '#' this.textBoxPassword2.Size = new System.Drawing.Size(159, 25); this.textBoxPassword2.TabIndex = 7; / / buttonSignIn / this.buttonSignIn.Location = new System.Drawing.Point(52, 150); this.buttonSignIn.Name = "buttonSignIn" this
27、.buttonSignIn.Size = new System.Drawing.Size(75, 33); this.buttonSignIn.TabIndex = 4; this.buttonSignIn.Text = "注冊" this.buttonSignIn.UseVisualStyleBackColor = true; this.buttonSignIn.Click += new System.EventHandler(this.buttonLogin_Click); / / buttonCancle / this.buttonCancle.Location =
28、new System.Drawing.Point(179, 150); this.buttonCancle.Name = "buttonCancle" this.buttonCancle.Size = new System.Drawing.Size(75, 33); this.buttonCancle.TabIndex = 5; this.buttonCancle.Text = "取消" this.buttonCancle.UseVisualStyleBackColor = true; this.buttonCancle.Click += new Sys
29、tem.EventHandler(this.buttonCancle_Click); / / FormLogin / this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSizei = new System.Drawing.Size(316, 209); this.Controls.Add(this.textBoxPassword2); this.Controls.Add(thi
30、s.labelPassword2); this.Controls.Add(this.buttonCancle); this.Controls.Add(this.buttonSignIn); this.Controls.Add(this.textBoxPassword); this.Controls.Add(this.textBoxUser); this.Controls.Add(this.labelPassword); this.Controls.Add(this.labelUser); this.MaximizeBox = false; this.MinimizeBox = false; t
31、his.Name = "FormLogin" this.ShowIcon = false; this.ShowInTaskbar = false; this.Text = "注冊界面" this.Load += new System.EventHandler(this.FormLogin_Load); this.ResumeLayout(false); this.PerformLayout(); #endregion private System.Windows.Forms.Label labelUser; private System.Windows.
32、Forms.TextBox textBoxUser; private System.Windows.Forms.Label labelPassword; private System.Windows.Forms.Label labelPassword2; private System.Windows.Forms.TextBox textBoxPassword2; private System.Windows.Forms.TextBox textBoxPassword; private System.Windows.Forms.Button buttonSignIn; private Syste
33、m.Windows.Forms.Button buttonCancle; 第四章1. 判斷double型的d1是否等于3.14的表達式if (Math.Abs(d1 - 3.14) < 0.001) Console.WriteLine("d1等于3.14"); else Console.WriteLine("d1不等于3.14");2. 枚舉問題枚舉元素值原則上是可以相同的,但是應避免不同枚舉元素使用相同的枚舉值,以免程序運行產(chǎn)生歧義而出錯導致得不到理想運行結(jié)果。3. 表達式不宜復雜化的原因代碼開發(fā)講究的效率,而且基本都是團隊開發(fā),如果代碼太過復雜
34、就會導致團隊人員花大量時間來讀懂代碼的意思,從而阻礙到開發(fā)的進度;另外在維護代碼的時候也會耗費大量時間,浪費人力物力;因此好的代碼應清晰易懂。第五章1. 用if 和 switch 語句寫出分制轉(zhuǎn)換代碼void Score2Grade(float score)/if語句實現(xiàn)等級轉(zhuǎn)換 if (score >= 90 && score <= 100) Console.WriteLine("優(yōu)秀"); else if (score >= 80) Console.WriteLine("良好"); else if (score &g
35、t;= 70) Console.WriteLine("中等"); else if (score >= 60) Console.WriteLine("及格"); else Console.WriteLine("不及格"); void Score_Grade(float score)/switch實現(xiàn)等級轉(zhuǎn)換 int i = (int)score/10; switch(i) case 10: case 9: Console.WriteLine("優(yōu)秀"); break; case 8: Console.WriteLine("良好"); brea
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 三年級下口算題
- 2024-2025學年四年級語文上冊第一單元4秋天說課稿蘇教版
- 2024-2025學年五年級語文上冊第2單元奇觀3紅樹林作業(yè)設(shè)計北師大版
- 2025至2030年中國水噴汽霧式防火卷簾門數(shù)據(jù)監(jiān)測研究報告
- 期末測試卷(B卷·能力提升)2021-2022學年七年級地理下冊同步單元AB卷(原卷版)
- 2025年中國車載視頻監(jiān)控系統(tǒng)市場調(diào)查研究報告
- 2025年中國紫外線凈化器市場調(diào)查研究報告
- 2025年中國導爆管擊發(fā)器市場調(diào)查研究報告
- 2025年中國固定天輪市場調(diào)查研究報告
- 2025至2030年中國空氣綜合治理超濃縮液數(shù)據(jù)監(jiān)測研究報告
- 小學六年級數(shù)學上冊《簡便計算》練習題(310題-附答案)
- 2024年河南省《輔警招聘考試必刷500題》考試題庫及答案【全優(yōu)】
- 安全隱患報告和舉報獎勵制度
- 地理標志培訓課件
- 2023行政主管年終工作報告五篇
- 2024年中國養(yǎng)老產(chǎn)業(yè)商學研究報告-銀發(fā)經(jīng)濟專題
- 高教版2023年中職教科書《語文》(基礎(chǔ)模塊)下冊教案全冊
- 人教版英語七年級上冊閱讀理解專項訓練16篇(含答案)
- 幼小銜接學拼音
- 運動技能學習與控制課件第九章運動技能學習概述
- 在全縣生豬生產(chǎn)統(tǒng)計監(jiān)測工作會議的講話范文(通用3篇)
評論
0/150
提交評論