C#程序设计实验报告2.
y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x);
if(x<0)
y=Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math.E ,4)-Math .Pow (x+1,3));
实验代码:
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;
{
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);
Console .WriteLine ("方法一:x={0},y={1}",x,y);
if(x>=0)
y = (x * x - 3 * x) / (x + 1) + 2 * Math.PI + Math.Sin(x);
if(x<0)
y=Math.Log(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow (Math.E,4)-Math .Pow (x+1,3));
Console.ReadLine();
}
}
}
2-2求三角形的周长和面积
运行结果:
实验代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2_2
{
class Program
利用完成数据的增、删、改、查1.1鼠标、窗口、菜单的操作
1.2用户账户的管理
1.3桌面图标的排列、设置桌面背景和屏幕保护程序
1.4设置任务栏、语言栏
1.5选择输入法、在“记事本”文件中输入各种符号
2.1了解“资源管理器的使用”
2.2设置文件夹选项、查找文件或文件夹
2.3文件/文件夹操作
Console .WriteLine ("方法二:x={0},y={1}",x,y);
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));
实验报告二
姓名
专业
软件工程
课程名称
C#程序设计
一、实验名称:
实验2
二、实验目的:
掌握使用命令行开发简单的C#应用程序
掌握使用Visual Studio编写控制台应用程序
掌握Visual Studio环境下程序的跟踪调试
了解Visual Studio在线帮助的使用
掌握应用程序命令行参数的使用
三、实验内容及要求
2.4使用回收站
具体要求请见《大学计算机应用基础学习指导》P37~P48
四、实验材料、工具、或软件
Windows XP Professional SP3
Visual Studio 2005
五、实验步骤、结果(或记录)
实验二:程序流程控制
2-1输入半径,求对应的圆的周长、面积、对应球体的体积。
运行结果:
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)
{
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:");
Console .WriteLine ("方法三:x={0},y={1}",x,y);
area = PI * r * r;
volume = 4 / 3 * PI * Math.Pow(r, 3);
Console.WriteLine("圆的周长为={0},面积为={1}",perimeter ,area );
Console.WriteLine("球体的体积={0}",volume );
double r, perimeter, area, volume;
Console.Write ("请输入半径:");
String s = Console.ReadLine();
r = double.Parse(s);
Console.WriteLine("圆的半径为={0}",r);
perimeter = 2 * PI * r;
ace _2_3_2
{
class Program
{
static void Main(string[] args)
{
double x, y;
Console .Write ("请输入x:");
string s = Console.ReadLine();
x = double.Parse(s);
}
else Console.WriteLine("无法构成三角形!");
Console.ReadKey();
}
}
}
2-3分段函数的实现
运行结果
实验代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;