C#实验报告(20200623060540)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

攀枝花学院实验报告

实验课程:Visual C#,NET程序设计实验项目:上机实验实验日期:2015

系:数学与计算机学院班级:2013级计算机科学与技术学

号:201310801009 同组人:指导教师:罗明刚

实验目的:

1. ;理解c#的值类型,常量和变量的概念.

2. 掌握c#常用运算符以及表达式的运算规则.

3. 理解数据类型转换的方法.

4■掌握数组和字符串的使用方法.

实验仪器设备,药品,器材:Microsoft visual studio 2010

1. 实验原理:熟悉visual 2010的基本操作方法.

2. 认真阅读本章相关内容,尤其是案例.

3. 实验前进行程序设计,完成源程序的编写任务.

4. 反复操作,直到不需要参考教材,能熟练操作为止.

实验步骤:见下页1上机实验2

姓名:何静成绩:

一•实验目的 5.;理解c#的值类型,常量和变量的概念.

6•掌握c#常用运算符以及表达式的运算规则7•理解数据类型转换的方法.

8•掌握数组和字符串的使用方法.

二•实验要求

5.熟悉visual 2010的基本操作方法.

6•认真阅读本章相关内容,尤其是案例.

7•实验前进行程序设计,完成源程序的编写任务.

8. 反复操作,直到不需要参考教材,能熟练操作为止. 三•实验内容

1. 设计一个简单的windows应用程序,完成以下功能:从键盘输入摄氏

温度值,输出对应的华氏温度值•运行效果如图所示

摄氏温度到华氏温度的转换公式为

Fahre nheir=9/5celsius+32

核心代码如下:

double c = Conv ert.ToDouble(txtCelsius.Text);

double f = 9 / 5 * c + 32;

txtFahre nheir.Text = f.ToStri ng();

int money = Conv ert.To In t32(txtm on ey.Text); int year = Conv ert.To In t32(txtyear.Text);

double rate = Co nvert.ToDouble(txtrate.Text) /

100;

double in terest = money * year * rate;

txti nterest.Text = in terest.ToStri ng();

double total = money + in terest;

txttotal.Text = total.ToStri ng();

2•设计一个简单的储蓄存款计算器,运行效果如图所示

核心代码如

下:

如图所示. 3.设计一个简单的windows 程序,输入5个数字,然后排序输出,

运行

核心代码如下:

double[] a = new double[5];

int i = 0;

private void butt on 1_Click(object sen der, Eve ntArgs e) {

double eleme nt = double.Parse(txteleme nt.Text);

a[i] = eleme nt;

txtprior.Text += a[i] + "";

i++;

lblNo.Text =" 第输入第” + (i + 1) + " 个元素";

}

private void butt on 2_Click(object sen der, Eve ntArgs e) {

Array.Sort(a);

txtsort.Text = a[0] + "" + a[1] + "" + a[2] + "" + a[3] + ""

+ a[4];

}

四.源程序

1. using System;

using System.Collections.Generic using ponentModel using System.Data;

using System.Drawing;

using System丄inq ;

using System.Text;

using System.Windows.Forms;

n amespace _2

{

public partial class Forml: Form

{

public Form1()

{

In itializeComp onent ();

}

private void butt on 1_Click (object sen der, Eve ntArgs e) { _

if ( txtc.Text != string.Empty )

{

double c = Convert.ToDouble (txtc.Text );

double f=9/5*c + 32;

txtf.Text = f.ToStri ng ();

}

else if ( txtf.Text != string.Empty )

{

double f = Convert.ToDouble (txtf.Text );

double c = ( f - 32) * 5 / 9;

txtc.Text = c.ToString ();

}

}

}

}

程序运行结果:

相关文档
最新文档