古詩詞大全網 - 成語經典 - web程序設計 第三版 課後題答案 主編 吉根林 顧雲華 u8877@qq.com

web程序設計 第三版 課後題答案 主編 吉根林 顧雲華 u8877@qq.com

Web程序設計第3章課後題

註:課後題***7題(除第壹題和第九題),其中5和8由於還有些問題沒有解決,就沒有將答案附上。這裏的答案僅供參考,希望在上機之前能自己練習壹下。程序有很多地方可以改,不要照搬。

(2)設計壹個網頁,其中包含TextBox和Button控件各壹個。當在TextBox中輸入壹個成績,再單擊Button控件時在網頁上輸出相應的等級信息。

.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="question2.aspx.cs" Inherits="homework_chap3.question2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server">請輸入壹個成績</asp:TextBox>

<asp:Label ID="Label1" runat="server" Text="Label">待顯示</asp:Label>

<br />

<asp:Button ID="Button1" runat="server" OnClick = "btmSubmit_Click" Text="檢測" />

</div>

</form>

</body>

</html>

.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace homework_chap3

{

public partial class question2 : System.Web.UI.Page

{

protected void btmSubmit_Click(object sender, EventArgs e)

{

int iInput = int.Parse(TextBox1.Text);

if (iInput > 100)

Label1.Text = "請輸入正確的分數";

else if(iInput >= 90)

Label1.Text = "優秀";

else if (iInput >= 80)

Label1.Text = "良好";

else if (iInput >= 60)

Label1.Text = "及格";

else if (iInput >= 0)

Label1.Text = "不及格";

else

Label1.Text = "請輸入正確的分數";

}

}

}

效果

(3)在網頁上輸出九九乘法表

.aspx.cs(.aspx源文件可以不作處理)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace homework_chap3

{

public partial class question3 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

for (int i=1; i<= 9; i++)

{

for (int j = 1; j <= i; j++)

{

Response.Write(i + "*" + j + "=" + (i * j) + "");

}

Response.Write("</br>");

}

}

}

}

效果

(4)在網頁上輸出如下形狀:

A

BBB

CCCCC

DDD

E

.aspx.cs(.aspx源文件可以不作處理)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace homework_chap3.questions

{

public partial class question4 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

String[] s = { "A", "B", "C", "D", "E" };

for (int i = 1; i <= 3; i++)

{

for (int j = 1; j <= 3 - i; j++)

{

Response.Write("?");

}

for(int k = 1; k <= 2*i-1; k++)

{

Response.Write(s[i-1]);

}

Response.Write("</br>");

}

for (int i = 1; i < 3; i++)

{

for (int j = 1; j <= i; j++)

{

Response.Write("?");

}

for (int k = 1; k <= 5 - 2*i; k++)

{

Response.Write(s[i + 2]);

}

Response.Write("</br>");

}

}

}

}

效果

(6)設計壹個網頁,其中包含兩個TextBox和壹個Button控件。當在TextBox中各輸入壹個數值,再單擊Button控件時在網頁上輸出兩者相除的數值。(要求包含異常處理)

.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="question6.aspx.cs" Inherits="homework_chap3.questions.question6" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" Text="Label">輸入壹個除數:</asp:Label>?

<asp:TextBox ID="TextBox1" runat="server" Width="104px"></asp:TextBox>

<br />

<asp:Label ID="Label2" runat="server" Text="Label">輸入壹個被除數:</asp:Label>?

<asp:TextBox ID="TextBox2" runat="server" Width="104px"></asp:TextBox>

<br />

<asp:Button ID="Button1" runat="server" OnClick="btm_click" Text="計算" />?

<asp:Label ID="Label3" runat="server" Text="Label">答案</asp:Label>

</div>

</form>

</body>

</html>

.aspx.ce

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace homework_chap3.questions

{

public partial class question6 : System.Web.UI.Page

{

protected void btm_click(object sender, EventArgs e)

{

int[] str = new int[1];

int iInput1 = int.Parse(TextBox1.Text);

int iInput2 = int.Parse(TextBox2.Text);

if (iInput2 == 0)

throw new Exception("除數不能為0");

else

Label3.Text = (iInput1 / iInput2).ToString();

}

}

}

效果

(7)設計壹個用於用戶註冊頁面的用戶信息類UserInfo,它包括兩個屬性:姓名(Name)、生日(Birthday);壹個方法DecideAge:用於判斷用戶是否達到規定年齡,對大於等於18歲的在頁面上輸出“您是成人了!”,而小於18歲的在頁面上輸出“您還沒長大呢!”

.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="question7.aspx.cs" Inherits="homework_chap3.questions.question71" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Label3" runat="server" Text="Label">?註冊</asp:Label>

<br /><br />

<asp:Label ID="Label1" runat="server" Text="Label">姓名</asp:Label>?

<asp:TextBox ID="TextBox1" runat="server">如“朱曉棟”</asp:TextBox>

<br />

<asp:Label ID="Label2" runat="server" Text="Label">生日</asp:Label>?

<asp:TextBox ID="TextBox2" runat="server">如“19890411”</asp:TextBox>

<br />

<asp:Button ID="Button1" runat="server" OnClick="btm_click" Text="註冊" />

</div>

</form>

</body>

</html>

.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace homework_chap3.questions

{

public partial class question71 : System.Web.UI.Page

{

protected void btm_click(object sender, EventArgs e)

{

int iInput2 = int.Parse (TextBox2.Text);

question7 que = new question7("zhu",19890411);

que.DecideAge(iInput2);

}

}

}

.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace homework_chap3.questions

{

public class question7

{

private string _Name;

private int _Brithday;

public string Name

{

get

{

return this._Name;

}

set

{

this._Name = value;

}

}

public int Brithday

{

get

{

return this._Brithday;

}

set

{

this._Brithday = value;

}

}

public question7(String name, int brithday)

{

this._Name = name;

this._Brithday = brithday;

}

public void DecideAge(int brithday)

{

if (20101001 - brithday < 180000)

throw new Exception("您還沒長大呢!");

else

throw new Exception("您是成人了!");

}

}

}

效果

是這個麽