您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > Web程序设计第3章课后题
Web程序设计第3章课后题注:课后题共7题(除第一题和第九题),其中5和8由于还有些问题没有解决,就没有将答案附上。这里的答案仅供参考,希望在上机之前能自己练习一下。程序有很多地方可以改,不要照搬。(2)设计一个网页,其中包含TextBox和Button控件各一个。当在TextBox中输入一个成绩,再单击Button控件时在网页上输出相应的等级信息。【.aspx】%@PageLanguage=C#AutoEventWireup=trueCodeBehind=question2.aspx.csInherits=homework_chap3.question2%!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN==servertitle/title/headbodyformid=form1runat=serverdivasp:TextBoxID=TextBox1runat=server请输入一个成绩/asp:TextBoxasp:LabelID=Label1runat=serverText=Label待显示/asp:Labelbr/asp:ButtonID=Button1runat=serverOnClick=btmSubmit_ClickText=检测//div/form/body/html【.aspx.cs】usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespacehomework_chap3{publicpartialclassquestion2:System.Web.UI.Page{protectedvoidbtmSubmit_Click(objectsender,EventArgse){intiInput=int.Parse(TextBox1.Text);if(iInput100)Label1.Text=请输入正确的分数;elseif(iInput=90)Label1.Text=优秀;elseif(iInput=80)Label1.Text=良好;elseif(iInput=60)Label1.Text=及格;elseif(iInput=0)Label1.Text=不及格;elseLabel1.Text=请输入正确的分数;}}}【效果】(3)在网页上输出九九乘法表【.aspx.cs】(.aspx源文件可以不作处理)usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespacehomework_chap3{publicpartialclassquestion3:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){for(inti=1;i=9;i++){for(intj=1;j=i;j++){Response.Write(i+*+j+=+(i*j)+ );}Response.Write(/br);}}}}【效果】(4)在网页上输出如下形状:ABBBCCCCCDDDE【.aspx.cs】(.aspx源文件可以不作处理)usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespacehomework_chap3.questions{publicpartialclassquestion4:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){String[]s={A,B,C,D,E};for(inti=1;i=3;i++){for(intj=1;j=3-i;j++){Response.Write( );}for(intk=1;k=2*i-1;k++){Response.Write(s[i-1]);}Response.Write(/br);}for(inti=1;i3;i++){for(intj=1;j=i;j++){Response.Write( );}for(intk=1;k=5-2*i;k++){Response.Write(s[i+2]);}Response.Write(/br);}}}}【效果】(6)设计一个网页,其中包含两个TextBox和一个Button控件。当在TextBox中各输入一个数值,再单击Button控件时在网页上输出两者相除的数值。(要求包含异常处理)【.aspx】%@PageLanguage=C#AutoEventWireup=trueCodeBehind=question6.aspx.csInherits=homework_chap3.questions.question6%!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN==servertitle/title/headbodyformid=form1runat=serverdivasp:LabelID=Label1runat=serverText=Label输入一个除数:/asp:Label asp:TextBoxID=TextBox1runat=serverWidth=104px/asp:TextBoxbr/asp:LabelID=Label2runat=serverText=Label输入一个被除数:/asp:Label asp:TextBoxID=TextBox2runat=serverWidth=104px/asp:TextBoxbr/asp:ButtonID=Button1runat=serverOnClick=btm_clickText=计算/ asp:LabelID=Label3runat=serverText=Label答案/asp:Label/div/form/body/html【.aspx.ce】usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespacehomework_chap3.questions{publicpartialclassquestion6:System.Web.UI.Page{protectedvoidbtm_click(objectsender,EventArgse){int[]str=newint[1];intiInput1=int.Parse(TextBox1.Text);intiInput2=int.Parse(TextBox2.Text);if(iInput2==0)thrownewException(除数不能为0);elseLabel3.Text=(iInput1/iInput2).ToString();}}}【效果】(7)设计一个用于用户注册页面的用户信息类UserInfo,它包括两个属性:姓名(Name)、生日(Birthday);一个方法DecideAge:用于判断用户是否达到规定年龄,对大于等于18岁的在页面上输出“您是成人了!”,而小于18岁的在页面上输出“您还没长大呢!”【.aspx】%@PageLanguage=C#AutoEventWireup=trueCodeBehind=question7.aspx.csInherits=homework_chap3.questions.question71%!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN==servertitle/title/headbodyformid=form1runat=serverdivasp:LabelID=Label3runat=serverText=Label 注册/asp:Labelbr/br/asp:LabelID=Label1runat=serverText=Label姓名/asp:Label asp:TextBoxID=TextBox1runat=server如“朱晓栋”/asp:TextBoxbr/asp:LabelID=Label2runat=serverText=Label生日/asp:Label asp:TextBoxID=TextBox2runat=server如“19890411”/asp:TextBoxbr/asp:ButtonID=Button1runat=serverOnClick=btm_clickText=注册//div/form/body/html【.aspx.cs】usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespacehomework_chap3.questions{publicpartialclassquestion71:System.Web.UI.Page{protectedvoidbtm_click(objectsender,EventArgse){intiInput2=int.Parse(TextBox2.Text);question7que=newquestion7(zhu,19890411);que.DecideAge(iInput2);}}}【.cs】usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;namespacehomework_chap3.questions{publicclassquestion7{privatestring_Name;priv
本文标题:Web程序设计第3章课后题
链接地址:https://www.777doc.com/doc-2855696 .html