




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验三 C#和ASP.NET 4.5 一、实验名称:C#和ASP.NET 4.5二、实验内容:1.转换输入的成绩到相应的等级(1)控件设置: (2)单击事件: protected void btnSubmit_Click(object sender, EventArgs e) float fGrade = float.Parse(txtInput.Text); int iGrade = (int)(fGrade / 10); switch (iGrade) case 10: case 9: lblDisplay.Text = 优秀; break; case 8: lblDisplay.Text = 良好; break; case 7: lblDisplay.Text = 中等; break; case 6: lblDisplay.Text = 及格; break; default: lblDisplay.Text = 不及格; break; 2.在Web窗体中输出九九乘法表(1)登录事件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.ToString() + x + j.ToString() + = + (i * j).ToString(); Response.Write(  ); Response.Write(); 3.输入一组以空格间隔的共10个以内的整数,输出该组整数的降序排列(1)控件设置 (2)单击事件protected void btnSubmit_Click(object sender, EventArgs e) string sInput = txtInput.Text.Trim() + ; int j = 0; int aInput = new int10; string temp = 0; for (int i = 0; i = sInput.Length - 1; i+) if (sInput.Substring(i, 1) != ) temp += sInput.Substring(i, 1); else aInputj = int.Parse(temp); j+; temp = 0; Array.Sort(aInput); Array.Reverse(aInput); foreach (int i in aInput) if (i != 0) Response.Write(i+ ); 4.计算两个数的商(1)控件设置 (2)单击事件 protected void btnSubmit_Click(object sender, EventArgs e) try float divsor = float.Parse(txtDivsor.Text); float dividend = float.Parse(txtDividend.Text); Response.Write(商为: + divsor / dividend); catch (Exception ee) Response.Write(请输入正确的数字!); 5.设计并实现一个用户信息类UserInfopublic class UserInfo private string _Name; private DateTime _Birthday; public string Name get return _Name; set _Name = value; public DateTime Birthday get return _Birthday; set _Birthday = value; public UserInfo(string name,DateTime birthday) this._Name = name; this._Birthday = birthday; public string DecideAge() if (DateTime.Now.Year - _Birthday.Year 18) return this._Name + ,您还没长大呢?; else return this._Name + ,您是成人了!; 6.在Web窗体中应用UserInfo类(1)控件设置 (2)单击事件protected void btnSubmit_Click(object sender, EventArgs e) string name = txtName.Text; string brithday = txtBrithday.Text; UserInfo userInfo = new UserInfo(name ,DateTime.ParseExact(brithday,yyyyMMdd,null); Response.Write(userInfo.DecideAge(); 7.调试九九乘法表三、习题:1.扩充成及转换程序。要求增加对输入成绩的合法性判断。protected void btnSubmit_Click(object sender, EventArgs e) try float fGrade = float.Parse(txtInput.Text); if (fGrade = 0 & fGrade = 100) int iGrade = (int)(fGrade / 10); switch (iGrade) case 10: case 9: lblDisplay.Text = 优秀; break; case 8: lblDisplay.Text = 良好; break; case 7: lblDisplay.Text = 中等; break; case 6: lblDisplay.Text = 及格; break; default: lblDisplay.Text = 不及格; break; else lblDisplay.Text = 请输入正确的成绩!; catch (Exception ee) lblDisplay.Text = 不合法!; 2.将九九乘法表改成如图3-13所时的浏览效果。 protected void Page_Load(object sender, EventArgs e) for (int i = 1; i = 9; i+) for (int j = i; j = 9; j+) Response.Write(i.ToString() + x + j.ToString() + = + (i * j).ToString(); Response.Write(  ); Response.Write(); 3.完善实验内容3的程序,要求能完成包含0和负数的排序protected void btnSubmit_Click(object sender, EventArgs e) string sInput = txtInput.Text.Trim() + ; int j = 0;int a=0; for (int x = 0; x = sInput.Length - 1; x+) if ( sInput.Substring(x, 1) = ) a+; int aInput = new inta; string temp = ; for (int i = 0; i = sInput.Length - 1; i+) if (sInput.Substring(i, 1) = -) while (sInput.Substring(i, 1) != ) temp += sInput.Substring(i, 1); i+; aInputj =int.Parse(temp); j+; temp = ; else if (sInput.Substring(i, 1) != ) temp += sInput.Substring(i, 1); else aInputj = int.Parse(temp); j+; temp = ; Array.Sort(aInput); Array.Reverse(aInput); foreach (int i in aInput) if (i != 0) Response.Write(i + ); else if (i = 0) Response.Write(0 + ); 4.使用ArrayList类实现降序排列一组整数的功能ArrayList类:public class ArrayList public ArrayList(string sInput)/ TODO: 在此处添加构造函数逻辑/ this._sInput = sInput; private string _sInput; private DateTime _Birthday; public string sInput get return _sInput; set _sInput = value; public string Jx() int j = 0; int a = 0; for (int x = 0; x = _sInput.Length - 1; x+) if (sInput.Substring(x, 1) = ) a+; int aInput = new inta; string temp = ; for (int i = 0; i = sInput.Length - 1; i+) if (sInput.Substring(i, 1) = -) while (sInput.Substring(i, 1) != ) temp += sInput.Substring(i, 1); i+; aInputj = int.Parse(temp); j+; temp = ; else if (sInput.Substring(i, 1) != ) temp += sInput.Substring(i, 1); else aInputj = int.Parse(temp); j+; temp = ; Array.Sort(aInput); Array.Reverse(aInput); string s = ; foreach (int i in aInput) if (i != 0) s+=i + else if (i = 0) s+=0 + return s; 设计页面using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Ex3_ArrayDescending : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) protected void btnSubmit_Click(object sender, EventArgs e) string sInput = txtInput.Text.Trim() + ; ArrayList arraylist = new ArrayList(sInput); Response.Write(arraylist.Jx(); 6改写UserInfo类,要求如下 (1)增加一个事件ValidateBrithday。(2)改写DecideAge()方法,当输入的生日值大于当前日期或小于1900-1-1时触发事件ValidateBrithday(3)设计页面并应用修改后的UserInfo类。改写的UserInfo类:public class UserInfo private string _Name; private DateTime _Birthday; public string Name get return _Name; set _Name = value; public DateTime Birthday get return _Birthday; set _Birthday = value; public UserInfo(string name,DateTime birthday) this._Name = name; this._Birthday = birthday; public delegate void EventHandler(object sender, EventArgs e);/声明事件所需的代理 public event EventHandler ValidateBrithday; public void OnValidateBrithday(object sender, EventArgs e) if (ValidateBrithday != null) ValidateBrithday(this, e); public string DecideAge() if (DateTime.Now.Year- _Birthday.Year0| _Birthday.Year1900) OnValidateBrithday(this, EventArgs.Empty); return ; else if (DateTime.Now.Year - _Birthday.Year 18) return this._Name + ,您还没长大呢?; else return this._Name + ,您是成人了!; 设计页面using System;using System.Collections.Generic;usin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 午餐科学搭配课件
- 硬笔点画教学课件
- 课件桥梁教学课件
- 应急处置培训课件
- 课件标准尺寸
- 课件末班教学课件
- 儿童创意口罩设计入门
- 表演基础全套课件
- 课件显示快捷方式
- 锂电行业考试题及答案
- 公务员面试人际关系题人际关系面试题及答案
- 2025年乡镇畜牧站动物检疫员招聘考试重点知识点梳理与解析
- 2025年中国电信招聘考试题库与答案解析
- 土地合作协议书合同模板
- 2025-2030中国废弃光伏组件回收处理技术路线与经济性分析报告
- 2025水利安全员C证考试题库(含答案)
- Unit 1 This is me!第5课时 Integration 说课稿- 2024-2025学年译林版(2024)七年级上册英语
- 一级建造师-机电工程管理与实务-案例专题突破教学课件
- 《中华人民共和国学前教育法》试题库及答案
- 新沪教牛津版九年级上册英语全册教案
- 全校教学质量提升会上校长讲话:把每一节课教好是我们最实在的荣耀
评论
0/150
提交评论