您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > 实验三C#和ASP4.5
实验三C#和ASP.NET4.5一、实验名称:C#和ASP.NET4.5二、实验内容:1.转换输入的成绩到相应的等级(1)控件设置:%@PageLanguage=C#AutoEventWireup=trueCodeFile=Grade.aspx.csInherits=Ex3_Grade%!DOCTYPEhtmlhtmlxmlns==servermetahttp-equiv=Content-Typecontent=text/html;charset=utf-8/title/title/headbodyformid=form1runat=serverdivasp:TextBoxID=txtInputrunat=server/asp:TextBoxasp:ButtonID=btnSubmitrunat=serverOnClick=btnSubmit_ClickText=等级/asp:LabelID=lblDisplayrunat=server/asp:Label/div/form/body/html(2)单击事件:protectedvoidbtnSubmit_Click(objectsender,EventArgse){floatfGrade=float.Parse(txtInput.Text);intiGrade=(int)(fGrade/10);switch(iGrade){case10:case9:lblDisplay.Text=优秀;break;case8:lblDisplay.Text=良好;break;case7:lblDisplay.Text=中等;break;case6:lblDisplay.Text=及格;break;default:lblDisplay.Text=不及格;break;}}2.在Web窗体中输出九九乘法表(1)登录事件protectedvoidPage_Load(objectsender,EventArgse){for(inti=1;i=9;i++){for(intj=1;j=i;j++){Response.Write(i.ToString()+x+j.ToString()+=+(i*j).ToString());Response.Write(  );}Response.Write(br/);}}3.输入一组以空格间隔的共10个以内的整数,输出该组整数的降序排列(1)控件设置%@PageLanguage=C#AutoEventWireup=trueCodeFile=ArrayDescending.aspx.csInherits=Ex3_ArrayDescending%!DOCTYPEhtmlhtmlxmlns==servermetahttp-equiv=Content-Typecontent=text/html;charset=utf-8/title/title/headbodyformid=form1runat=serverdivasp:TextBoxID=txtInputrunat=server/asp:TextBoxasp:ButtonID=btnSubmitrunat=serverOnClick=btnSubmit_ClickText=降序//div/form/body/html(2)单击事件protectedvoidbtnSubmit_Click(objectsender,EventArgse){stringsInput=txtInput.Text.Trim()+;intj=0;int[]aInput=newint[10];stringtemp=0;for(inti=0;i=sInput.Length-1;i++){if(sInput.Substring(i,1)!=){temp+=sInput.Substring(i,1);}else{aInput[j]=int.Parse(temp);j++;temp=0;}}Array.Sort(aInput);Array.Reverse(aInput);foreach(intiinaInput){if(i!=0){Response.Write(i+ );}}}4.计算两个数的商(1)控件设置%@PageLanguage=C#AutoEventWireup=trueCodeFile=Division.aspx.csInherits=Ex3_Division%!DOCTYPEhtmlhtmlxmlns==servermetahttp-equiv=Content-Typecontent=text/html;charset=utf-8/title/title/headbodyformid=form1runat=serverdivasp:TextBoxID=txtDivsorrunat=server/asp:TextBoxbr/asp:TextBoxID=txtDividendrunat=server/asp:TextBoxasp:ButtonID=btnSubmitrunat=serverOnClick=btnSubmit_ClickText=提交//div/form/body/html(2)单击事件protectedvoidbtnSubmit_Click(objectsender,EventArgse){try{floatdivsor=float.Parse(txtDivsor.Text);floatdividend=float.Parse(txtDividend.Text);Response.Write(商为:+divsor/dividend);}catch(Exceptionee){Response.Write(请输入正确的数字!);}}5.设计并实现一个用户信息类UserInfopublicclassUserInfo{privatestring_Name;privateDateTime_Birthday;publicstringName{get{return_Name;}set{_Name=value;}}publicDateTimeBirthday{get{return_Birthday;}set{_Birthday=value;}}publicUserInfo(stringname,DateTimebirthday){this._Name=name;this._Birthday=birthday;}publicstringDecideAge(){if(DateTime.Now.Year-_Birthday.Year18){returnthis._Name+,您还没长大呢?;}else{returnthis._Name+,您是成人了!;}}}6.在Web窗体中应用UserInfo类(1)控件设置%@PageLanguage=C#AutoEventWireup=trueCodeFile=UserInfoPage.aspx.csInherits=Ex3_UserInfoPage%!DOCTYPEhtmlhtmlxmlns==servermetahttp-equiv=Content-Typecontent=text/html;charset=utf-8/title/title/headbodyformid=form1runat=serverdivasp:LabelID=Label1runat=serverText=姓名:/asp:Labelasp:TextBoxID=txtNamerunat=server/asp:TextBoxbr/br/asp:LabelID=Label2runat=serverText=年龄:/asp:Labelasp:TextBoxID=txtBrithdayrunat=server/asp:TextBoxbr/br/asp:ButtonID=btnSubmitrunat=serverOnClick=btnSubmit_Clickstyle=margin-bottom:0pxText=提交//div/form/body/html(2)单击事件protectedvoidbtnSubmit_Click(objectsender,EventArgse){stringname=txtName.Text;stringbrithday=txtBrithday.Text;UserInfouserInfo=newUserInfo(name,DateTime.ParseExact(brithday,yyyyMMdd,null));Response.Write(userInfo.DecideAge());}7.调试九九乘法表三、习题:1.扩充成及转换程序。要求增加对输入成绩的合法性判断。protectedvoidbtnSubmit_Click(objectsender,EventArgse){try{floatfGrade=float.Parse(txtInput.Text);if(fGrade=0&&fGrade=100){intiGrade=(int)(fGrade/10);switch(iGrade){case10:case9:lblDisplay.Text=优秀;break;case8:lblDisplay.Text=良好;break;case7:lblDisplay.Text=中等;break;case6:lblDisplay.Text=及格;break;default:lblDisplay.Text=不及格;break;}}elselblDisplay.Text=请输入正确的成绩!;}catch(Exceptionee){lblDisplay.Text=不合法!;}}2.将九九乘法表改成如图3-13所时的浏览效果。protectedvoidPage_Load(objectsender,EventArgse){for(inti=1;i=9;i++){for(intj=i;j=9;j++){Response.Write(i.ToString()+x+j.ToString()+=+(i*j).ToString());Response.Write(  );}Response.Write(br/);}}3.完善实验内容3的程序,要求能完成包含0和负数的排序protectedvoidbtnSubmit_Click(objectsender,EventArgse){stringsInput=txtInput.Text.Trim()+;intj=0;inta=0;for(intx=0;x=sInput.Length-1;x++){if(sInput.Substring(x,1)==){a++;}}int[]aInput=newint[a];stringtemp=;for(inti=0;i=sInput.Length-1;i++){if(sInput.Substring(i,1)==-){while(sInput.Substring(i,1)!=){temp+=sInput.Substring(i,1);i++;}aIn
本文标题:实验三C#和ASP4.5
链接地址:https://www.777doc.com/doc-4925687 .html