C#实验报告.docx
《C#实验报告.docx》由会员分享,可在线阅读,更多相关《C#实验报告.docx(24页珍藏版)》请在冰豆网上搜索。
C#实验报告
C#程序设计
实验报告
姓名:
王海洲
学号:
109074092
班级:
计算机科学与技术103班
指导老师:
李伟
1、实验目的:
1、熟练掌握C#各种数据类型,常量,变量的表达形式。
2、熟练掌握C#的运算符和表达式。
3、加深理解面向对象变成的概念,如类,对象,实例化等。
4、熟练掌握方法的声名,理解并学会使用方法的参数传递,方法的重载。
5、熟练掌握接口的定义和实现。
6、熟练集合接口的使用。
7、理解异常的长生过程和异常处理的概念。
8、掌握C#异常处理的方法。
9、掌握建立WINDOWS应用程序的步骤和方法。
10、掌握使用windowsforms控件,菜单和对话框的使用。
二、实验内容:
实验2-1
程序
usingSystem;
namespacetest2_1
{
classClass1
[STAThread]
staticvoidMain(string[]args)
inta,b,c,d;
for(a=1;a<=4;a++)
for(b=1;b<=4;b++)
for(c=1;c<=4;c++)
if(a!
=b&&b!
=c&&c!
=a)
d=10-a-b-c;
if((c==1^b==2)&&(c==2^d==3)&&(a==2^d==4))
Console.Write("红球放在{0}号,黄球放在{1}号,",a,b);
Console.WriteLine("黑球放在{0}号,白球放在{1}号",c,d);
}
Console.Read();
截图
实验3-2
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespace_3_2
classProgram
ProgramT=newProgram();
Card[]books;
int[]index;
inti,k;
Cardcard=newCard();
Console.Write("请输入需要入库图书的总数:
");
stringsline=Console.ReadLine();
intnum=int.Parse(sline);
books=newCard[num];
for(i=0;ibooks[i]=newCard();index=newint[num];for(i=0;i{Console.Write("请输入书名:");card.Title=Console.ReadLine();Console.Write("请输入作者:");card.Author=Console.ReadLine();Console.Write("请输入入库量:");sline=Console.ReadLine();card.Total=int.Parse(sline);books[i].store(refcard);index[i]=i;}Console.Write("请选择关键字排序(1、按书名;2、按作者;3、按入库量)");sline=Console.ReadLine();intmethod=int.Parse(sline);T.sort(books,index,method);for(i=0;i{k=index[i];(books[k]).show();}Console.Read();}voidsort(Card[]book,int[]index,intmethod){inti,j,m,n,temp;if(method==1)//按书名排序{for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Title,book[j].Title)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==2){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Author,book[j].Author)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==3){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
books[i]=newCard();
index=newint[num];
for(i=0;i{Console.Write("请输入书名:");card.Title=Console.ReadLine();Console.Write("请输入作者:");card.Author=Console.ReadLine();Console.Write("请输入入库量:");sline=Console.ReadLine();card.Total=int.Parse(sline);books[i].store(refcard);index[i]=i;}Console.Write("请选择关键字排序(1、按书名;2、按作者;3、按入库量)");sline=Console.ReadLine();intmethod=int.Parse(sline);T.sort(books,index,method);for(i=0;i{k=index[i];(books[k]).show();}Console.Read();}voidsort(Card[]book,int[]index,intmethod){inti,j,m,n,temp;if(method==1)//按书名排序{for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Title,book[j].Title)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==2){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Author,book[j].Author)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==3){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
Console.Write("请输入书名:
card.Title=Console.ReadLine();
Console.Write("请输入作者:
card.Author=Console.ReadLine();
Console.Write("请输入入库量:
sline=Console.ReadLine();
card.Total=int.Parse(sline);
books[i].store(refcard);
index[i]=i;
Console.Write("请选择关键字排序(1、按书名;2、按作者;3、按入库量)");
intmethod=int.Parse(sline);
T.sort(books,index,method);
for(i=0;i{k=index[i];(books[k]).show();}Console.Read();}voidsort(Card[]book,int[]index,intmethod){inti,j,m,n,temp;if(method==1)//按书名排序{for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Title,book[j].Title)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==2){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Author,book[j].Author)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==3){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
k=index[i];
(books[k]).show();
voidsort(Card[]book,int[]index,intmethod)
inti,j,m,n,temp;
if(method==1)//按书名排序
for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Title,book[j].Title)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==2){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Author,book[j].Author)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==3){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
for(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Title,book[j].Title)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==2){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Author,book[j].Author)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==3){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
i=index[n];j=index[n+1];
if(string.Compare(book[i].Title,book[j].Title)>0)
temp=index[n];
index[n]=index[n+1];
index[n+1]=temp;
if(method==2)
for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Author,book[j].Author)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==3){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
for(n=0;n{i=index[n];j=index[n+1];if(string.Compare(book[i].Author,book[j].Author)>0){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}if(method==3){for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
if(string.Compare(book[i].Author,book[j].Author)>0)
if(method==3)
for(m=0;mfor(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
for(n=0;n{i=index[n];j=index[n+1];if(book[i].Total>book[j].Total){temp=index[n];index[n]=index[n+1];index[n+1]=temp;}}}}}}classCard{privatestringtitle,author;privateinttotal;publicCard(){title="";author="";total=0;}publicCard(stringtitle,stringauthor,inttotal){this.title=title;this.author=author;this.total=total;}publicvoidstore(refCardcard){title=card.title;author=card.author;total=card.total;}publicvoidshow(){Console.WriteLine("Title:{0},Author:{1},Total:{2}",title,author,total);}publicstringTitle{get{returntitle;}set{title=value;}}publicstringAuthor{get{returnauthor;}set{author=value;}}publicintTotal{get{returntotal;}set{total=value;}}}截图程序如下:usingSystem;namespaceConsoleApplication1{classClass1{interfaceIEnglishDimensions{floatLength();floatWidth();}interfaceIMetricDimensions{floatLength();floatWidth();}classBox:IEnglishDimensions,IMetricDimensions{floatlengthInches;floatwidthInches;publicBox(floatlength,floatwidth){lengthInches=length;widthInches=width;}floatIEnglishDimensions.Length(){returnlengthInches;}floatIEnglishDimensions.Width(){returnwidthInches;}floatIMetricDimensions.Length(){returnlengthInches*2.54f;}floatIMetricDimensions.Width(){returnwidthInches*2.54f;}}publicstaticvoidMain(){BoxmyBox=newBox(30.0f,20.0f);IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;IMetricDimensionsmDimensions=(IMetricDimensions)myBox;System.Console.WriteLine("Length(in):{0}",eDimensions.Width());System.Console.WriteLine("Width(in);{0}",eDimensions.Width());System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());}}}截图实验5程序usingSystem;enumMonthName{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}classWhatDay{staticvoidMain(){try{Console.Write("pleaseinputadaynumberbetween1and365:");stringline=Console.ReadLine();intdayNum=int.Parse(line);if(dayNum<1||dayNum>365){thrownewArgumentOutOfRangeException("dayoutofrange!");}intmonthNum=0;foreach(intdaysInMonthinDaysInMonths){if(dayNum<=daysInMonth){break;}else{dayNum-=daysInMonth;monthNum++;}}MonthNametemp=(MonthName)monthNum;stringmonthName=Enum.Format(typeof(MonthName),temp,"g");Console.WriteLine("{0},{1}",dayNum,monthName);}catch(Exceptioncaught){Console.WriteLine(caught);}finally{Console.ReadLine();}}StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};}截图异常:正常:实验6-2程序Form1.Designer.cs代码如下:namespace_6_2{partialclassForm1{//////必需的设计器变量。///privateSystem.ComponentModel.IContainercomponents=null;//////清理所有正在使用的资源。//////如果应释放托管资源,为true;否则为false。protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);}#regionWindows窗体设计器生成的代码//////设计器支持所需的方法-不要///使用代码编辑器修改此方法的内容。///privatevoidInitializeComponent(){this.groupBox1=newSystem.Windows.Forms.GroupBox();this.radioButton4=newSystem.Windows.Forms.RadioButton();this.radioButton3=newSystem.Windows.Forms.RadioButton();this.radioButton2=newSystem.Windows.Forms.RadioButton();this.radioButton1=newSystem.Windows.Forms.RadioButton();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.checkBox1=newSystem.Windows.Forms.CheckBox();this.checkBox2=newSystem.Windows.Forms.CheckBox();this.checkBox3=newSystem.Windows.Forms.CheckBox();this.checkBox4=newSystem.Windows.Forms.CheckBox();this.checkBox5=newSystem.Windows.Forms.CheckBox();this.checkBox6=newSystem.Windows.Forms.CheckBox();this.textBox1=newSystem.Windows.Forms.TextBox();this.button1=newSystem.Windows.Forms.Button();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.SuspendLayout();////groupBox1//this.groupBox1.Controls.Add(this.radioButton4);this.groupBox1.Controls.Add(this.radioButton3);this.groupBox1.Controls.Add(this.radioButton2);this.groupBox1.Controls.Add(this.radioButton1);this.groupBox1.Location=newSystem.Drawing.Point(12,12);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(127,127);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="背景颜色";////radioButton4//this.radioButton4.AutoSize=true;this.radioButton4.Location=newSystem.Drawing.Point(65,77);this.radioButton4.Name="radioButton4";this.radioButton4.Size=newSystem.Drawing.Size(35,16);this.radioButton4.TabIndex=3;this.radioButton4.TabStop=true;this.radioButton4.Text="无";this.radioButton4.UseVisualStyleBackColor=true;this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);////radioButton3//this.radioButton3.AutoSize=true;this.radioButton3.Location=newSystem.Drawing.Point(11,77);this.radioButton3.Name="radioButton3";this.radioButton3.Size=newSystem.Drawing.Size(35,16);this.radioButton3.TabIndex=2;this.radioButton3.TabStop=true;this.radioButton3.Text="蓝";this.radioButton3.UseVisualStyleBackColor=true;this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);////radioButton2//this.radioButton2.AutoSize=true;this.radioButton2.Location=newSystem.Drawing.Point(65,39);this.radioButton2.Name="radioButton2";this.radioButton2.Size=newSystem.Drawing.Size(35,16);this.radioButton2.TabIndex=1;this.radioButton2.TabStop=true;this.radioButton2.Text="绿";this.radioButton2.UseVisualStyleBackColor=true;this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);////radioButton1//this.radioButton1.AutoSize=true;this.radioButton1.Location=newSystem.Drawing.Point(11,39);this.radioButton1.Name="radioButton1";this.radioButton1.Size=newSystem.Drawing.Size(35,16);this.radioButton1.TabIndex=0;this.radioButton1.TabStop=true;this.radioButton1.Text="红";this.radioButton1.UseVisualStyleBackColor=true;this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);////groupBox2//this.groupBox2.Controls.Add(this.checkBox1);this.groupBox2.Controls.Add(this.checkBox2);this.groupBox2.Controls.Add(this.checkBox3);this.groupBox2.Controls.Add(this.checkBox4);this.groupBox2.Controls.Add(this.checkBox5);this.groupBox2.Controls.Add(this.checkBox6);this.groupBox2.Location=newSystem.Drawing.Point(162,12);this.groupBox2.Name="groupBox
if(book[i].Total>book[j].Total)
classCard
privatestringtitle,author;
privateinttotal;
publicCard()
title="";author="";
total=0;
publicCard(stringtitle,stringauthor,inttotal)
this.title=title;
this.author=author;
this.total=total;
publicvoidstore(refCardcard)
title=card.title;
author=card.author;
total=card.total;
publicvoidshow()
Console.WriteLine("Title:
{0},Author:
{1},Total:
{2}",title,author,total);
publicstringTitle
get{returntitle;}
set{title=value;}
publicstringAuthor
get{returnauthor;}
set{author=value;}
publicintTotal
get{returntotal;}
set{total=value;}
程序如下:
namespaceConsoleApplication1
interfaceIEnglishDimensions
floatLength();
floatWidth();
interfaceIMetricDimensions
classBox:
IEnglishDimensions,IMetricDimensions
floatlengthInches;
floatwidthInches;
publicBox(floatlength,floatwidth)
lengthInches=length;
widthInches=width;
floatIEnglishDimensions.Length()
returnlengthInches;
floatIEnglishDimensions.Width()
returnwidthInches;
floatIMetricDimensions.Length()
returnlengthInches*2.54f;
floatIMetricDimensions.Width()
returnwidthInches*2.54f;
publicstaticvoidMain()
BoxmyBox=newBox(30.0f,20.0f);
IEnglishDimensionseDimensions=(IEnglishDimensions)myBox;
IMetricDimensionsmDimensions=(IMetricDimensions)myBox;
System.Console.WriteLine("Length(in):
{0}",eDimensions.Width());
System.Console.WriteLine("Width(in);{0}",eDimensions.Width());
System.Console.WriteLine("Length(cm);{0}",mDimensions.Length());
System.Console.WriteLine("Width(cm);{0}",mDimensions.Width());
实验5
enumMonthName
{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}
classWhatDay
staticvoidMain()
try
Console.Write("pleaseinputadaynumberbetween1and365:
stringline=Console.ReadLine();
intdayNum=int.Parse(line);
if(dayNum<1||dayNum>365)
thrownewArgumentOutOfRangeException("dayoutofrange!
intmonthNum=0;
foreach(intdaysInMonthinDaysInMonths)
if(dayNum<=daysInMonth)
break;
else
dayNum-=daysInMonth;
monthNum++;
MonthNametemp=(MonthName)monthNum;
stringmonthName=Enum.Format(typeof(MonthName),temp,"g");
Console.WriteLine("{0},{1}",dayNum,monthName);
catch(Exceptioncaught)
Console.WriteLine(caught);
finally
Console.ReadLine();
StaticSystem.Collections.ICollectionDaysInMonths=newint[12]{31,28,31,30,31,30,31,31,30,31,30,31};
异常:
正常:
实验6-2
Form1.Designer.cs代码如下:
namespace_6_2
partialclassForm1
///
///必需的设计器变量。
privateSystem.ComponentModel.IContainercomponents=null;
///清理所有正在使用的资源。
///如果应释放托管资源,为true;否则为false。
protectedoverridevoidDispose(booldisposing)
if(disposing&&(components!
=null))
components.Dispose();
base.Dispose(disposing);
#regionWindows窗体设计器生成的代码
///设计器支持所需的方法-不要
///使用代码编辑器修改此方法的内容。
privatevoidInitializeComponent()
this.groupBox1=newSystem.Windows.Forms.GroupBox();
this.radioButton4=newSystem.Windows.Forms.RadioButton();
this.radioButton3=newSystem.Windows.Forms.RadioButton();
this.radioButton2=newSystem.Windows.Forms.RadioButton();
this.radioButton1=newSystem.Windows.Forms.RadioButton();
this.groupBox2=newSystem.Windows.Forms.GroupBox();
this.checkBox1=newSystem.Windows.Forms.CheckBox();
this.checkBox2=newSystem.Windows.Forms.CheckBox();
this.checkBox3=newSystem.Windows.Forms.CheckBox();
this.checkBox4=newSystem.Windows.Forms.CheckBox();
this.checkBox5=newSystem.Windows.Forms.CheckBox();
this.checkBox6=newSystem.Windows.Forms.CheckBox();
this.textBox1=newSystem.Windows.Forms.TextBox();
this.button1=newSystem.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
//groupBox1
this.groupBox1.Controls.Add(this.radioButton4);
this.groupBox1.Controls.Add(this.radioButton3);
this.groupBox1.Controls.Add(this.radioButton2);
this.groupBox1.Controls.Add(this.radioButton1);
this.groupBox1.Location=newSystem.Drawing.Point(12,12);
this.groupBox1.Name="groupBox1";
this.groupBox1.Size=newSystem.Drawing.Size(127,127);
this.groupBox1.TabIndex=0;
this.groupBox1.TabStop=false;
this.groupBox1.Text="背景颜色";
//radioButton4
this.radioButton4.AutoSize=true;
this.radioButton4.Location=newSystem.Drawing.Point(65,77);
this.radioButton4.Name="radioButton4";
this.radioButton4.Size=newSystem.Drawing.Size(35,16);
this.radioButton4.TabIndex=3;
this.radioButton4.TabStop=true;
this.radioButton4.Text="无";
this.radioButton4.UseVisualStyleBackColor=true;
this.radioButton4.CheckedChanged+=newSystem.EventHandler(this.radioButton4_CheckedChanged);
//radioButton3
this.radioButton3.AutoSize=true;
this.radioButton3.Location=newSystem.Drawing.Point(11,77);
this.radioButton3.Name="radioButton3";
this.radioButton3.Size=newSystem.Drawing.Size(35,16);
this.radioButton3.TabIndex=2;
this.radioButton3.TabStop=true;
this.radioButton3.Text="蓝";
this.radioButton3.UseVisualStyleBackColor=true;
this.radioButton3.CheckedChanged+=newSystem.EventHandler(this.radioButton3_CheckedChanged);
//radioButton2
this.radioButton2.AutoSize=true;
this.radioButton2.Location=newSystem.Drawing.Point(65,39);
this.radioButton2.Name="radioButton2";
this.radioButton2.Size=newSystem.Drawing.Size(35,16);
this.radioButton2.TabIndex=1;
this.radioButton2.TabStop=true;
this.radioButton2.Text="绿";
this.radioButton2.UseVisualStyleBackColor=true;
this.radioButton2.CheckedChanged+=newSystem.EventHandler(this.radioButton2_CheckedChanged);
//radioButton1
this.radioButton1.AutoSize=true;
this.radioButton1.Location=newSystem.Drawing.Point(11,39);
this.radioButton1.Name="radioButton1";
this.radioButton1.Size=newSystem.Drawing.Size(35,16);
this.radioButton1.TabIndex=0;
this.radioButton1.TabStop=true;
this.radioButton1.Text="红";
this.radioButton1.UseVisualStyleBackColor=true;
this.radioButton1.CheckedChanged+=newSystem.EventHandler(this.radioButton1_CheckedChanged);
//groupBox2
this.groupBox2.Controls.Add(this.checkBox1);
this.groupBox2.Controls.Add(this.checkBox2);
this.groupBox2.Controls.Add(this.checkBox3);
this.groupBox2.Controls.Add(this.checkBox4);
this.groupBox2.Controls.Add(this.checkBox5);
this.groupBox2.Controls.Add(this.checkBox6);
this.groupBox2.Location=newSystem.Drawing.Point(162,12);
this.groupBox2.Name="groupBox
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1