2022年C#程序设计实验报告.pdf





《2022年C#程序设计实验报告.pdf》由会员分享,可在线阅读,更多相关《2022年C#程序设计实验报告.pdf(20页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、姓名专业软件工程课 程 名称C#程序设计一、实验名称:实验 2二、实验目的:掌握使用命令行开发简单的C# 应用程序掌握使用 Visual Studio编写控制台应用程序掌握 Visual Studio环境下程序的跟踪调试了解 Visual Studio在线帮助的使用掌握应用程序命令行参数的使用三、实验内容及要求利用完成数据的增、删、改、查四、实验材料、工具、或软件Windows XP Professional SP3Visual Studio 2005五、实验步骤、结果(或记录)实验二 : 程序流程控制2-1 输入半径,求对应的圆的周长、面积、对应球体的体积。运行结果:实验代码:using S
2、ystem;using ;using ;namespace _2_1 class Program static void Main(string args) 精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 1 页,共 20 页 - - - - - - - - - - const double PI = ; double r, perimeter, area, volume; (请输入半径 :); String s = (); r = (s); (圆的半径为 =0,r); perimeter = 2 * P
3、I * r; area = PI * r * r; volume = 4 / 3 * PI * (r, 3); (圆的周长为 =0 ,面积为 =1,perimeter ,area ); (球体的体积 =0,volume ); (); 2-2 求三角形的周长和面积运行结果:实验代码:using System;using ;using ;namespace _2_2 class Program static void Main(string args) double a, b, c, p, h, area; (请输入三角形的边a:);精品资料 - - - 欢迎下载 - - - - - - - -
4、- - - 欢迎下载 名师归纳 - - - - - - - - - -第 2 页,共 20 页 - - - - - - - - - - string s = (); a = (s); Console .Write (请输入三角形的边b:); s = (); b = (s); (请输入三角形的边c:); s = (); c = (s); if (a 0 & b 0 & c 0 & a + b c & a + c b & b + c a) (三角形三边分别为:a=0,b=1,c=2,a,b,c); p = a + b + c; h = p / 2; area = (h * (h - a) * (h
5、 - b) * (h - c); (三角形的周长 =0, 面积为 =1,p,area); else (无法构成三角形!); (); 2-3 分段函数的实现运行结果实验代码:using System;using ;using ;namespace _2_3_2 class Program static void Main(string args) double x, y; Console .Write (请输入 x:); string s = (); x = (s);精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - -
6、 -第 3 页,共 20 页 - - - - - - - - - - y = (x * x - 3 * x) / (x + 1) + 2 * + (x); if(x=0) y = (x * x - 3 * x) / (x + 1) + 2 * + (x); if(x=0) y = (x * x - 3 * x) / (x + 1) + 2 * + (x); else y=(-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)
7、; y=(x=0)?(x * x - 3 * x) / (x + 1) + 2 * + (x):(-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 ;using ;namespace _2_4 class Program static void Main(string args) int a, b,
8、 c, a1, b1, c1, t, Nmax, Nmin, Nmid; Random rMun = new Random(); a = (101); b = (101);精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 4 页,共 20 页 - - - - - - - - - - c= (101); (原始值: 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
9、 = t; if (b c) t = b; b = c; c = t; (方法一 ) 升序值: a=0,b=1,c=2),a,b,c); a = a1; b = b1; c = c1; Nmax =Math .Max (Math .Max (a,b),c); Nmin = (a, b), c); Nmid = a + b + c - Nmax - Nmin; a = Nmin; b = Nmid; c = Nmax; (方法二 ) 升序值: a=0,b=1,c=2,a,b,c); (); 2-5 求解一元二次方程运行结果:实验代码:using System;using ;namespace C
10、onsole2_5精品资料 - - - 欢迎下载 - - - - - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 5 页,共 20 页 - - - - - - - - - - class Program static void Main(string args) double a, b, c, delta, x1, x2, realPart, imagePart; (请输入系数a:); String s = (); a = (s); (请输入系数b:); s = (); b = (s); (请输入系数c:); s = (); c = (s); if(a
11、=0) if(b=0) (此方程无解! ); else (此方程的解为:0,-c/b); else delta=b*b-4*a*c; if(delta0) x1=(-b+(delta)/(2*a); x2=(delta)/(2*a); (此方程有两个不等实根:0 ,1,x1,x2); else if(delta =0)(此方程有两个相等实根:0,-b/(2*a); else realPart=-b/(2*a); imagePart=(-delta)/(2*a); (此方程有两个不等实根:0+1i和0-1i,realPart,imagePart); 精品资料 - - - 欢迎下载 - - - -
12、 - - - - - - - 欢迎下载 名师归纳 - - - - - - - - - -第 6 页,共 20 页 - - - - - - - - - - (); 2-6switch语句实现多重分支运行结果:实验代码:using System;using ;namespace ConsoleApplication1 class Program static void Main(string args) int i; (输入一个数字(17) : ); String s = (); i = (s); switch(i) case 1: (对应的星期为:星期一); break; case 2: (对应
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022 C# 程序设计 实验 报告

限制150内