C#实验报告.docx
- 文档编号:243932
- 上传时间:2022-10-07
- 格式:DOCX
- 页数:43
- 大小:44.89KB
C#实验报告.docx
《C#实验报告.docx》由会员分享,可在线阅读,更多相关《C#实验报告.docx(43页珍藏版)》请在冰豆网上搜索。
C
C#.
姓
班
学
指
NET
姓名
班级
学号
指导老师
T实
郭
计
1
师邰
实验
郭佳
计142
49074
邰伟鹏
报告
043
告
实验一
创建简单的.NET应用程序
【实验目的】
熟悉VS2005开发环境,掌握如何在此开发环境下开发简单的.NET应用程
序,以及调试程序的基本操作技巧。
【实验内容】
分别创建不同类型的.NET应用程序项目,体会基本的设计与编程方法。
【实验要求】
(1)通过实验掌握【工具箱】、【属性】窗口、【解决方案资源管理器】等
的用法和基本操作技巧。
(2)通过实验观察各种应用程序结构及特点;
(3)通过实验观察生成的可执行文件的存放位置,掌握项目备份与恢复的
方法;
(4)通过实验掌握利用断点进行程序调试的方法。
【源代码】
步骤1
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceSimpleWindowsApplication
{
publicpartialclassFormMain:
Form
{
publicFormMain()
{
InitializeComponent();
}
privatevoidbuttonExit_Click(objectsender,EventArgse)
{
this.Close();
}
}
}
步骤2
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceSimpleConsoleApplication
{
classProgram
{
staticvoidMain(string[]args)
{
Console.Write("请输入一个字符串:
");
stringwelcomeString=Console.ReadLine();
Console.WriteLine("Welcome:
{0}",welcomeString);
Console.ReadLine();
}
}
}
步骤3
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
publicpartialclass_Default:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
}
【运
步骤
步骤
步骤
prot
{
}
运行结果
骤1
骤2
骤3
ectedvoi
Response.
果】
dButtonO
Write("
OK_Click(o
script>ale
objectsen
ert('哈哈哈
nder,Even
哈');
ntArgse)
ript>");
实验二C#基本编程方式
【实验目的】
(1)练习C#中变量声明和赋值的方法。
(2)练习类型转换的方法。
(3)练习分支语的基本用法。
(4)练习循环语句的用法。
【实验内容】
为银行个人存款客户提供一个“超级存款计算器”,以简单直观的操作界
面为客户提供一个银行存款本息到期金额结算查询程序,以便客
户决定选择那种存款方式。
用户输入存款金额及相应信息后,单击【计算】按钮,程序能自动在【到期结
算总额】中显示到期应得的本金和利息合计总金额。
【实验要求】
(1)要求用startAmount表示初始存款金额。
(2)要求用yearRate表示年数。
(3)要求用years表示年数。
(4)要求用calculateFrequency保存用户选择的计算方式,即“按月算息”、
“按季度算息”和“按年算息”,当用户在【计算方式】中选择某个计算
方式后,程序会根据选择结果对calculateFrequency赋以相应的字符串
值,如赋值为“按月算息”。
(5)要求用rate表示按选择的计算方式使用的利率。
(6)要求将计算出的结算总金额赋给total变量,并在只读的textBoxTotal
中显示结果。
【实验代码】
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceSuperCalculator
{
publicpartialclassFormMain:
Form
{
publicFormMain()
{
InitializeComponent();
this.StartPosition=FormStartPosition.CenterScreen;
}
///
///将字符串转换为32位整数或64位浮点数
///
///
///
///
///
privateboolConvertStringToNumber(stringstr,bool
mustGreatThanZero,outintresult)
{
boolisValid=false;
if(int.TryParse(str,outresult)==false)
{
MessageBox.Show(string.Format("无法将{0}转换为整数",
str));
}
else
{
if(result<=0)
{
MessageBox.Show(string.Format("{0}不是正数",
str));
}
else
{
isValid=true;
}
}
returnisValid;
}
///
///将字符串转换为32位整数或64位浮点数
///
///
///
///
///
privateboolConvertStringToNumber(stringstr,bool
mustGreatThanZero,outdoubleresult)
{
boolisValid=false;
if(double.TryParse(str,outresult)==false)
{
MessageBox.Show(string.Format("无法将{0}转换为实数",
str));
}
else
{
if(result<=0)
{
MessageBox.Show(string.Format("{0}不是正数",
str));
}
else
{
isValid=true;
}
}
returnisValid;
}
privatevoidbuttonOk_Click(objectsender,EventArgse)
{
intstartAmount;//存款金额
doubleyearRate;//年利率
intyears;
//存期
if(ConvertStringToNumber(textBoxStartAmount.Text,true,
outstartAmount)==false)return;
if(startAmount<100)
{
MessageBox.Show("金额不能小于100元");
return;
}
if(ConvertStringToNumber(textBoxYearRate.Text,true,out
yearRate)==false)return;
yearRate/=100;
if(ConvertStringToNumber(textBoxYears.Text,true,out
years)==false)return;
if(comboBoxCalculateFrequency.SelectedIndex==-1)
{
MessageBox.Show("请选择提供的利息计算方式");
return;
}
stringcalculateFrequency=
comboBoxCalculateFrequency.SelectedItem.ToString();
switch(calculateFrequency)
{
case"按月计息":
textBoxTotal.Text=string.Format("{0:
F2}元",
Caculate(startAmount,yearRate/12,years*12));
break;
case"按季度计息":
textBoxTotal.Text=string.Format("{0:
F2}元",
Caculate(startAmount,yearRate/4,years*4));
break;
case"按年计息":
textBoxTotal.Text=string.Format("{0:
F2}元",
Caculate(startAmount,yearRate,years));
break;
}
}
///
///计算到期结算金额
///
///
///
///
///
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 实验 报告