C#程序设计实验报告5Word文档格式.docx
- 文档编号:19770701
- 上传时间:2023-01-10
- 格式:DOCX
- 页数:24
- 大小:334.23KB
C#程序设计实验报告5Word文档格式.docx
《C#程序设计实验报告5Word文档格式.docx》由会员分享,可在线阅读,更多相关《C#程序设计实验报告5Word文档格式.docx(24页珍藏版)》请在冰豆网上搜索。
请输入直角三角形的直角边A(>
0):
"
);
//直角边A
a=double.Parse(Console.ReadLine());
请输入直角三角形的直角边B(>
//直角边B
b=double.Parse(Console.ReadLine());
c=Math.Sqrt(Math.Pow(a,2)+Math.Pow(b,2));
//斜边C
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));
三角形的周长={0},面积={1}"
p,area);
doublesinA=a/c;
doubleaAngle=Math.Round(Math.Asin(sinA)*180/Math.PI,0);
doublecosB=a/c;
doublebAngle=Math.Round(Math.Acos(sinA)*180/Math.PI,0);
三角形的两个锐角的度数分别为:
{0}和{1}"
aAngle,bAngle);
Console.ReadKey();
}
}
10-2
namespaceConsoleApplication4
System.Collections.ArrayListredBalls=newSystem.Collections.ArrayList(){1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33};
System.Collections.ArrayListblueBalls=newSystem.Collections.ArrayList(){1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
System.Collections.ArrayListredBall=newSystem.Collections.ArrayList();
RandomrandObj=newRandom();
intblueBall=randObj.Next(1,16);
for(inti=1;
i<
=6;
i++)
intindex1=randObj.Next(0,33-i);
redBall.Add(redBalls[index1]);
redBalls.RemoveAt(index1);
红球"
foreach(ObjectobjinredBall)
{0}"
obj);
\n篮球:
{0}"
blueBall);
10-3
namespace_10_3
conststrings4="
;
//空4格
intnYear=DateTime.Today.Year;
//当前的年份
for(intnMonth=1;
nMonth<
=12;
nMonth++)
{//打印1~12月的日历
DateTimed1=newDateTime(nYear,nMonth,1);
{0}/{1}"
d1.Year,d1.Month);
SUNMONTUEWEDTHUFRISAT"
intiWeek=(int)d1.DayOfWeek;
//获取当年当月1号的星期
intiLastDay=d1.AddMonths
(1).AddDays(-1).Day;
//获取当年当月最后1天的日期
for(inti=0;
iWeek;
Console.Write(s4);
iLastDay;
{0:
00}"
i);
if((i+iWeek)%7==0)//一行打印7天
Console.WriteLine();
10-4
namespace_10_4
stringtext=@"
Thequickbrownfoxjumpedoverthelazydog."
+
@"
Anappleadaykeepsthedoctoraway."
Canafoxandadogbefriends?
"
字符串为:
text);
stringsearchTerm="
the"
string[]source=text.ToLower().Split(newchar[]{'
.'
'
?
'
!
'
:
},StringSplitOptions.RemoveEmptyEntries);
intwordCount=0;
foreach(stringsinsource)
if(s.CompareTo(searchTerm)==0)
wordCount++;
Console.WriteLine("
单词{0}总共出现了{1}次,频率{2:
#0.##%}"
searchTerm,wordCount,wordCount/(double)source.Length);
Console.ReadKey();
10-5
namespacesy10_5
{//创建一个StringBuilder对象
StringBuildersb=newStringBuilder();
boolbContinue=true;
while(bContinue)//输入若干行英文单词,查到某行直接按回车结束
请输入英文单词:
Strings=Console.ReadLine();
if(s!
="
)
{//在StringBuilder对象后追加英文单词
sb.Append(s);
sb.Append("
else//某行直接按了回车,结束字符串的输入
bContinue=false;
//显示StringBuilder的长度和内容
stringstr=sb.ToString();
总共{0}字符,内容为:
{1}"
sb.Length,str);
//把字符串转换为字符串数组
string[]source=str.ToLower().Split(newchar[]{'
'
},StringSplitOptions.RemoveEmptyEntries);
//数组排序
Array.Sort(source);
//显示排序数组
foreach(stringsinsource)Console.WriteLine(s);
11-1
usingSystem.IO;
namespace_11_1
classDriveInfoTest
DriveInfo[]allDrives=DriveInfo.GetDrives();
foreach(DriveInfodinallDrives)
驱动器{0}"
d.Name);
类型{0}"
d.DriveType);
if(d.IsReady==true)
卷标:
d.VolumeLabel);
文件系统:
d.DriveFormat);
当前用户可用空间:
{0,15}"
d.AvailableFreeSpace);
可用空间:
d.TotalFreeSpace);
磁盘总大小:
d.TotalSize);
11-2
namespaceConsoleApplication5
stringpath0=@"
C:
\WINDOWS\security"
stringpath1=@"
\WINDOWS"
try
应用程序当前工作目录:
\n{0}"
System.IO.Directory.GetCurrentDirectory());
string[]subdirectoryEntries=
System.IO.Directory.GetDirectories
(System.IO.Directory.GetDirectoryRoot
(System.IO.Directory.GetCurrentDirectory()));
根目录中子目录总数为{0}。
子目录名称分别为:
subdirectoryEntries.Length);
foreach(stringsubdirectoryinsubdirectoryEntries)
subdirectory);
string[]dirs=System.IO.Directory.GetFiles(path0);
目录{0}下的总文件总数为{1}。
文件名称分别为:
path0,dirs.Length);
foreach(stringdirindirs)Console.WriteLine("
dir);
string[]dirs1=System.IO.Directory.GetFiles(path1,"
*.ini"
目录{0}下拓展名为.sys的文件总数为{1}。
path1,dirs1.Length);
foreach(stringdirindirs1)Console.WriteLine("
catch(Exceptione)
\n操作失败:
e.ToString());
Console.ReadLine();
11-3
namespace_11_3
strings;
stringpath=@"
d:
\Chapter01\SrcFile.txt"
FileInfofi1=newFileInfo(path);
if(!
fi1.Exists)
{//创建源文件可以写入内容.
using(StreamWritersw=fi1.CreateText())
while(bContinue)//输入若干行文件内容,直到某行直接按回车结束
请输入文件内容:
s=Console.ReadLine();
)sw.WriteLine(s);
//添加文件内容
elsebContinue=false;
//某行直接按了回车,结束字符串的输入
fi1=newFileInfo(path);
源文件{0}所在的目录为:
\n\t{1}"
path,fi1.DirectoryName);
源文件{0}的长度为:
\n\t{1}"
path,fi1.Length);
//打开源文件读取内容
源文件{0}的内容为:
path);
using(StreamReadersr=fi1.OpenText())
s="
while((s=sr.ReadLine())!
=null)Console.WriteLine("
\t{0}"
s);
stringpath2=@"
Chapter01\DesFile.txt"
FileInfofi2=newFileInfo(path2);
//删除目标文件,确保成功复制
fi2.Delete();
//文件复制
fi1.CopyTo(path2);
源文件成功复制至目标文件:
\n\t{0}."
path2);
//删除目标文件
目标文件{0}成功删除."
11-4
namespace_11_4
privateconststringFILE_NAME=@"
\TestFile.txt"
using(StreamWritersw=newStreamWriter(FILE_NAME))
sw.WriteLine("
文本文件的写入/读取示例:
------------------------------------"
写入整数,浮点数,Boolean值,字符,字符串,日期"
请输入整数:
inti=int.Parse(Console.ReadLine());
sw.WriteLine(i);
请输入浮点数:
floatf=float.Parse(Console.ReadLine());
sw.WriteLine(f);
请输入Boolean值:
boolb=bool.Parse(Console.ReadLine());
sw.WriteLine(b);
请输入字符:
charc=char.Parse(Console.ReadLine());
sw.WriteLine(c);
请输入字符串:
strings=Console.ReadLine();
sw.WriteLine(s);
当前日期为:
sw.WriteLine(DateTime.Now);
try
using(StreamReadersr=newStreamReader(FILE_NAME))
{stringline;
while((line=sr.ReadLine())!
=null)Console.WriteLine(line);
catch(Exceptione)
Console.WriteLine("
该文件不能正常读取,原因如下:
Console.WriteLine(e.Message);
11-5
namespace_11_5
strings,textReaderText="
while(bContinue)
请输入文件内容(以.结束):
)textReaderText=textReaderText+s+"
\n"
原始文本内容如下:
-------------------------------------------\n{0}"
textReaderText);
stringaLine,aParagraph=null;
StringReaderstrReader=newStringReader(textReaderText);
while(true)
aLine=strReader.ReadLine();
if(aLine!
=null)
aParagraph=aParagraph+aLine+"
else
aParagraph=aParagraph+"
bre
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 程序设计 实验 报告