《上机实验1(10页).doc》由会员分享,可在线阅读,更多相关《上机实验1(10页).doc(10页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、-上机实验1-第 10 页攀枝花学院实验报告实验课程: Visual C#,NET程序设计 实验项目: 上机实验1 上机实验2 实验日期:2015 系:数学与计算机学院 班级: 2013级计算机科学与技术 姓名: 学号: 同组人: 指导教师:罗明刚 成绩:实验目的:1. ;理解c#的值类型,常量和变量的概念.2. 掌握c#常用运算符以及表达式的运算规则.3. 理解数据类型转换的方法.4. 掌握数组和字符串的使用方法.实验仪器设备,药品,器材:Microsoft visual studio 20101. 实验原理:熟悉visual 2010的基本操作方法.2. 认真阅读本章相关内容,尤其是案例.
2、3. 实验前进行程序设计,完成源程序的编写任务.4. 反复操作,直到不需要参考教材,能熟练操作为止.实验步骤:见下页一.实验目的5. ;理解c#的值类型,常量和变量的概念.6. 掌握c#常用运算符以及表达式的运算规则.7. 理解数据类型转换的方法.8. 掌握数组和字符串的使用方法.二. 实验要求5. 熟悉visual 2010的基本操作方法.6. 认真阅读本章相关内容,尤其是案例.7. 实验前进行程序设计,完成源程序的编写任务.8. 反复操作,直到不需要参考教材,能熟练操作为止.三. 实验内容1. 设计一个简单的windows应用程序,完成以下功能:从键盘输入摄氏温度值,输出对应的华氏温度值.
3、运行效果如图所示.摄氏温度到华氏温度的转换公式为: Fahrenheir=9/5celsius+32核心代码如下:double c = Convert.ToDouble(txtCelsius.Text);double f = 9 / 5 * c + 32;txtFahrenheir.Text = f.ToString();2. 设计一个简单的储蓄存款计算器,运行效果如图所示.核心代码如下:int money = Convert.ToInt32(txtmoney.Text);int year = Convert.ToInt32(txtyear.Text);double rate = Conver
4、t.ToDouble(txtrate.Text) / 100;double interest = money * year * rate;txtinterest.Text = interest.ToString();double total = money + interest;txttotal.Text = total.ToString();3. 设计一个简单的windows程序,输入5个数字,然后排序输出,运行果如图所示.核心代码如下:double a = new double5;int i = 0;private void button1_Click(object sender, Eve
5、ntArgs e)double element = double.Parse(txtelement.Text);ai = element;txtprior.Text += ai + ;i+;lblNo.Text = 第输入第 + (i + 1) + 个元素;private void button2_Click(object sender, EventArgs e)Array.Sort(a);txtsort.Text = a0 + + a1 + + a2 + + a3 + + a4;四. 源程序1.using System;using System.Collections.Generic;usi
6、ng System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace _2 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) if (txtc.Text != string.Empty) do
7、uble c = Convert.ToDouble(txtc.Text); double f = 9 / 5 * c + 32; txtf.Text = f.ToString(); else if (txtf.Text != string.Empty) double f = Convert.ToDouble(txtf.Text); double c = (f - 32) * 5 / 9; txtc.Text = c.ToString();程序运行结果:2.using System;using System.Collections.Generic;using System.ComponentMo
8、del;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace _3 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) int money = Convert.ToInt32(txtmoney.Text); int year =
9、 Convert.ToInt32(txtyear.Text); double rate = Convert.ToDouble(txtrate.Text) / 100; double interest = money * year * rate; txtinterest.Text = interest.ToString(); double total = money + interest; txttotal.Text = total.ToString();程序运行结果:3.using System;using System.Collections.Generic;using System.Com
10、ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace _4 public partial class Form1 : Form public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) private void linkLabel1_LinkClicked(object sender
11、,LinkLabelLinkClickedEventArgs e) private void labNo_Click(object sender, EventArgs e) private void label3_Click(object sender, EventArgs e) double a = new double5; int i = 0; private void button1_Click(object sender, EventArgs e) double element = double.Parse(txtelement.Text); ai = element; txtprio
12、r.Text += ai + ; i+; lblNo.Text = 第输入第 + (i + 1) + 个元素; private void button2_Click(object sender, EventArgs e) Array.Sort(a); txtsort.Text = a0 + + a1 + + a2 + + a3 + + a4;一. 实验目的1. 理解分支和循环的逻辑意义2. 掌握c#的if,switch分支语句的使用方法.3. 掌握c#的while,do/while,for,foreach等循环语句的使用方法.二.实验要求9. 熟悉visual 2010的基本操作方法.10.
13、认真阅读本章相关内容,尤其是案例.11. 实验前进行程序设计,完成源程序的编写任务.12. 反复操作,直到不需要参考教材,能熟练操作为止.三. 实验内容1. 有一个函数: x (x1) Y= 2*x-1 (1x10) 3*x-11 (x10)设计一个windows应用程序,输入x,输出y值.核心代码提示如下:double x = Convert.ToDouble(txtx.Text);double y;if (x = 1 & x 0)turnnum = turnnum * 10 + num % 10;num = num / 10;txtn.Text = turnnum.ToString();3
14、. 一个数如果恰好等于她的因子之和,这个数就称为完数.例如6的因子是1,2,3,而6=1+2+3,因此6是完数,编程找出1000之内的所有完数,当单击查找按钮时,按下面的格式输出所有完数和其因子:”6是一个完数:6=1+2+3”,如图所示:核心代码部分提示如下:StringBuilder sb = new StringBuilder();int i, j, sum;for (i = 2; i 1000; i+)sum = 0;for (j = i; j i / 2; j+)if (i % j = 0) sum += j;if (sum = i)sb.Append(i + 是一个完数: + i
15、+ =1);for (j = 2; j = i / 2; j+)if (i % j = 0)sb.Append(+ + j);sb.Append(n);lblshow.Text = sb.ToString();四. 源程序1.using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace _
16、5 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) double x = Convert.ToDouble(txtx.Text); double y; if (x = 1 & x 0) turnnum = turnnum * 10 + num % 10; num = num / 10; txtn.Text = turnnum.ToString();运行结果如下:3.using System;
17、using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace _8 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs
18、e) StringBuilder sb = new StringBuilder(); int i, j, sum; for (i = 2; i 1000; i+) sum = 0; for (j = i; j i / 2; j+) if (i % j = 0) sum += j; if (sum = i) sb.Append(i + 是一个完数: + i + =1); for (j = 2; j = i / 2; j+) if (i % j = 0) sb.Append(+ + j); sb.Append(n); lblshow.Text = sb.ToString();运行结果如下: 五. 实验总结