




已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验报告二姓 名专业软件工程课程名称C#程序设计一、 实验名称:实验2二、 实验目的:掌握使用命令行开发简单的C#应用程序掌握使用Visual Studio编写控制台应用程序掌握Visual Studio环境下程序的跟踪调试了解Visual Studio在线帮助的使用掌握应用程序命令行参数的使用三、实验内容及要求利用ADO.NET完成数据的增、删、改、查1.1 鼠标、窗口、菜单的操作1.2 用户账户的管理1.3 桌面图标的排列、设置桌面背景和屏幕保护程序1.4 设置任务栏、语言栏1.5 选择输入法、在“记事本”文件中输入各种符号2.1了解“资源管理器的使用”2.2 设置文件夹选项、查找文件或文件夹2.3 文件/文件夹操作2.4 使用回收站具体要求请见大学计算机应用基础学习指导P37P48四、实验材料、工具、或软件Windows XP Professional SP3Visual Studio 2005五、实验步骤、结果(或记录)实验二:程序流程控制2-1输入半径,求对应的圆的周长、面积、对应球体的体积。运行结果:实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_1 class Program static void Main(string args) const double PI = 3.14159; double r, perimeter, area, volume; Console.Write (请输入半径:); String s = Console.ReadLine(); r = double.Parse(s); Console.WriteLine(圆的半径为=0,r); perimeter = 2 * PI * r; area = PI * r * r; volume = 4 / 3 * PI * Math.Pow(r, 3); Console.WriteLine(圆的周长为=0,面积为=1,perimeter ,area ); Console.WriteLine(球体的体积=0,volume ); Console.ReadLine(); 2-2求三角形的周长和面积运行结果:实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_2 class Program static void Main(string args) double a, b, c, p, h, area; Console.Write(请输入三角形的边a:); string s = Console.ReadLine(); a = double.Parse(s); Console .Write (请输入三角形的边b:); s = Console.ReadLine(); b = double.Parse(s); Console.Write(请输入三角形的边c:); s = Console.ReadLine(); c = double.Parse(s); if (a 0 & b 0 & c 0 & a + b c & a + c b & b + c a) Console.WriteLine(三角形三边分别为:a=0,b=1,c=2,a,b,c); p = a + b + c; h = p / 2; area = Math.Sqrt(h * (h - a) * (h - b) * (h - c); Console.WriteLine(三角形的周长=0,面积为=1,p,area); else Console.WriteLine(无法构成三角形!); Console.ReadKey(); 2-3分段函数的实现运行结果实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_3_2 class Program static void Main(string args) double x, y; Console .Write (请输入x:); string s = Console.ReadLine(); x = double.Parse(s); y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x); if(x=0) y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x); if(x=0) y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x); else y=Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math .E,4)-Math .Pow (x+1,3); Console .WriteLine (方法三:x=0,y=1,x,y); y=(x=0)?(x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x):Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math .E,4)-Math .Pow (x+1,3); Console .WriteLine (方法四:x=0,y=1,x,y); Console .ReadKey (); 2-4三个数比较大小运行结果:实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_4 class Program static void Main(string args) int a, b, c, a1, b1, c1, t, Nmax, Nmin, Nmid; Random rMun = new Random(); a = rMun.Next(101); b = rMun.Next(101); c= rMun.Next(101); Console.WriteLine(原始值:a=0,b=1,c=2,a,b,c); a1 = a; b1 = b; c1 = c; if (a b) t = a; a = b; b = t; if (a c) t = a; a = c; c = t; if (b c) t = b; b = c; c = t; Console.WriteLine(方法一)升序值:a=0,b=1,c=2),a,b,c); a = a1; b = b1; c = c1; Nmax =Math .Max (Math .Max (a,b),c); Nmin = Math.Min(Math.Min(a, b), c); Nmid = a + b + c - Nmax - Nmin; a = Nmin; b = Nmid; c = Nmax; Console.WriteLine(方法二)升序值:a=0,b=1,c=2,a,b,c); Console.ReadKey(); 2-5求解一元二次方程运行结果:实验代码:using System;using System.Collections.Generic;using System.Text;namespace Console2_5 class Program static void Main(string args) double a, b, c, delta, x1, x2, realPart, imagePart; Console.Write(请输入系数a:); String s = Console.ReadLine(); a = double.Parse(s); Console.Write(请输入系数b:); s = Console.ReadLine(); b = double.Parse(s); Console.Write(请输入系数c:); s = Console.ReadLine(); c = double.Parse(s); if(a=0) if(b=0) Console.WriteLine(此方程无解!); else Console.WriteLine(此方程的解为:0,-c/b); else delta=b*b-4*a*c; if(delta0) x1=(-b+Math.Sqrt(delta)/(2*a); x2=(-b-Math.Sqrt(delta)/(2*a); Console.WriteLine(此方程有两个不等实根:0,1,x1,x2); else if(delta =0)Console.WriteLine(此方程有两个相等实根:0,-b/(2*a); else realPart=-b/(2*a); imagePart=Math.Sqrt(-delta)/(2*a); Console.WriteLine(此方程有两个不等实根:0+1i和0-1i,realPart,imagePart); Console.ReadKey(); 2-6switch语句实现多重分支运行结果:实验代码:using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1 class Program static void Main(string args) int i; Console.Write(输入一个数字(17):); String s = Console.ReadLine(); i = int.Parse(s); switch(i) case 1: Console.WriteLine(对应的星期为:星期一); break; case 2: Console.WriteLine(对应的星期为:星期二); break; case 3: Console.WriteLine(对应的星期为:星期三); break; case 4: Console.WriteLine(对应的星期为:星期四); break; case 5: Console.WriteLine(对应的星期为:星期五); break; case 6: Console.WriteLine(对应的星期为:星期六); break; case 7: Console.WriteLine(对应的星期为:星期日); break; default: Console.WriteLine(输入错误!); break ; Console.ReadKey(); 2-7分别使用if语句和switch语句实现多分支结构方法一:运行结果(if语句)using System;using System.Collections.Generic;using System.Text;namespace Console2_7 class Program static void Main(string args) int c; double f = 0; Console.Write(请输入有固定工资收入的党员的月工资:); int salary = int.Parse(Console.ReadLine(); if (salary 1500) c = 15; else c = (salary - 1) / 100; switch (c) case 0: case 1: case 2: case 3: f = 0.5 / 100 * salary; break; case 6: case 7: f = 1.5 / 100 * salary; break; case 8: case 9: case 10: case 11: case 12: case 13: case 14: f = 2.0 / 100 * salary; break; case 15: f = 3.0 / 100 * salary; break; Console.WriteLine(月工资=0,交纳党费=1, salary, f); Console.ReadKey(); 法二运行结果:代码:(if语句)using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2_7_2 class Program static void Main(string args) int c; double f = 0; Console.Write(请输入有固定收入的党员的月工资:); int salary = int.Parse(Console.ReadLine(); if (salary 0 & salary 400 & salary 600 & salary 800 & salary 1500) f = 3.0 / 100 * salary; else Console.WriteLine(月工资输入有误!); Console.WriteLine(月工资=0,交纳党费=1, salary, f); Console.ReadKey(); 实验三:3-1运行结果:实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_1 class Program static void Main(string args) int i, n, fac = 1; string s; n = -1; while (n 0) Console.Write(请输入非负整数n:); s = Console.ReadLine(); n = int.Parse(s); /方法一:for循环 for (i = 1; i = n; i+) fac *= i; Console.WriteLine( For循环:0!=1, n, fac); /方法二:while语句循环 i = 1; fac = 1; while (i = n) fac *= i+; Console.WriteLine( while循环:0!=1, n, fac); /方法三:do.while语句循环 i = 1; fac = 1; do fac *= i; i+; while (i = n); Console.WriteLine( do.while循环:0!=1, n, fac); Console.ReadKey(); 3-2运行结果:实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_2 class Program static void Main(string args) int f1 = 1, f2 = 1, f3, num = 2; Console.Write(0,5t0,5t, f1, f2); f3 = f1 + f2; while (f3 = 10000) Console.Write(0,5t, f3); num+; if (num % 5 = 0) Console.WriteLine(); f1 = f2; f2 = f3; f3 = f1 + f2; Console.ReadKey(); 3-3、鸡兔同笼问题运行结果:代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_3 class Program static void Main(string args) int c, r; Console.Write(请输入总头数:); string s = Console.ReadLine(); int h = int.Parse(s); int f = 1; while (f % 2 != 0) Console.Write(请输入总脚数(必须是偶数):); s = Console.ReadLine(); f = int.Parse(s); /方法一:利用循环 bool solution = false; for (c = 0; c =0&c=0) Console .WriteLine (方法二:鸡:0只,兔:1只,c ,r); solution =true ; if (!solution) Console.WriteLine(方法二:无解,请重新运行测试!); Console .ReadKey (); 3-4利用级数和求PI运行结果:实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Consolejishuhe3_4 class Program static void Main(string args) float n, t,pi; int s; pi = 0; t = 1; n = 1; s = 1; while (Math.Abs(t) = Math.Pow(10, -6) pi += t; n += 2; s = -s; t = s / n; pi *= 4; Console.WriteLine(pi=0, pi); Console.ReadKey(); 3-5运行结果:实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleG_3_6 class Program static void Main(string args) int m,n, r, m1, n1; Random rNum = new Random(); m1 = rNum.Next(101); n1 = rNum.Next(101); Console.WriteLine(整数1=0,整数2=1, m1, n1); if (m1 n1) m = m1; n = n1; else m = n1; n = m1; do r =m %n; m =n ; n =r ; while (r !=0); Console .WriteLine (最大公约数=0,最小公约数=1,m ,m1 *n1 /m ); Console .ReadKey (); 3-6打印九九乘法表运行结果:代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_5 class Program static void Main(string args) string s; / Console.WriteLine( 九九乘法表); for (int i = 1; i = 9; i+) s = ; for (int j = 1; j = i; j+) s += (string.Format(0*1=2, i, j, i * j).PadRight(8); Console.WriteLine(s); / Console.WriteLine(); Console.WriteLine( 九九乘法表); for (int i = 1; i = 9; i+) s = ; s += s.PadRight(8 * (i - 1) + 1); for (int j = i ; j = 9; j+) s += (string.Format(0*1=2, i, j, i * j).PadRight(8); Console.WriteLine(s); Console.ReadKey(); 3-7运行结果:实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _3_7 class Program static void Main(string args) int m, k, i, num = 0; /方法一:利用for循环和break语句 Console.WriteLine(方法一:1100间所有的素数为:); for (m = 2; m = 100; m+) k = (int)(Math.Sqrt(m); for (i = 2; i = k; i+) if (m % i = 0) bre
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 亳州涡阳县县直公立医院和乡镇卫生院招聘考试真题2024
- 馆员考试题及答案
- 牛顿考试题及答案
- 兵团考试题及答案
- 前端考试题及答案
- 中级财务会计学(上)知到智慧树答案
- 危重患者抢救制度试题(附参考答案)
- 网络搭建模拟题(附答案)
- 护理技术操作并发症预防及处理试题
- 中学化学教学设计知到智慧树答案
- 三年级 人教版 数学 第六单元《两位数乘一位数(不进位)口算》课件
- 民爆信息系统网络服务平台
- 2025年度智慧企业ERP系统集成与运维服务合同模板2篇
- 2024年优居房产全国加盟手册3篇
- 污水处理工程施工工程组织设计
- 氨基酸作为药物靶点
- 经销商独家授权书
- 空气源热泵计算
- 第9课-秦统一中国【课件】1
- 园林绿化资料范例
- 万达入职性格在线测评题
评论
0/150
提交评论