实验三 C#和ASP.NET 4.5
一、实验名称:C#和ASP.NET 4.5
二、实验内容:
1.转换输入的成绩到相应的等级
(1)控件设置:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Grade.aspx.cs" Inherits="Ex3_Grade" %>
<!DOCTYPE html>
<html xmlns="/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="等级" />
<asp:Label ID="lblDisplay" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
(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 = asp查看源码配置ui"良好";
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("<br/>");
}
}
3.输入一组以空格间隔的共10个以内的整数,输出该组整数的降序排列
(1)控件设置
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ArrayDescending.aspx.cs" Inherits="Ex3_ArrayDescending" %>
<!DOCTYPE html>
<html xmlns="/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="降序" />
</div>
</form>
</body>
</html>
(2)单击事件
protected void btnSubmit_Click(object sender, EventArgs e)
{
string sInput = txtInput.Text.Trim() + " ";
int j = 0;
int[] aInput = new int[10];
string temp = "0";
for (int i = 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 (int i in aInput)
{
if (i != 0)
{
Response.Write(i+" ");
}
}
}
4.计算两个数的商
(1)控件设置
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Division.aspx.cs" Inherits="Ex3_Division" %>
<!DOCTYPE html>
<html xmlns="/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtDivsor" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="txtDividend" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="提交" />
</div>
</form>
</body>
</html>
(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.设计并实现一个用户信息类UserInfo
public class UserInfo
{
private string _Name;
private DateTime _Birthday;
public string Name
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论