版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第一章:习题一、习题二
usingSystem;usingSystem.Collections.Generic;namespaceWindowsFormsApplication2
usingSystem.Linq;usingSystem.Text;publicForm1(){InitializeComponent();}
namespaceConsoleApplication1privatevoidbutton1_Click(objectsender,
EventArgse)
{classProgram{label1.Font=newFont(“华文彩云”,80);
{staticvoidMain(string[]args)label1.ForeColor=System.Drawing.Color.Blue;
{Console.WriteLine(nHelloWorld!");button1.Enabled二false;}}}
Console.Read();
}}
})
第二章习题二
privatevoidbuttonl_Click(objectsender,EventArgse){
Strings,a;
s=Convert.ToString(textBoxl.Text);
a=s.ToUpper();
textBoxl.Text=a.ToStringO;}
privatevoidbutton2_Click(objectsender,EventArgse){
Strings,a;s=Convert.ToString(textBox1.Text);
a=s.ToLower();textBox1.Text=a.ToStringO;
}))
习题六
privatevoidbuttonl_Click(objectsender,EventArgse)
{stringa;a=Convert.ToString(textBox1.Text);
MessageBox.Show(Converl.ToString(a)+,\欢迎进入C#的世界!”欢迎进入C#的世界!”,
MessageBoxButtons.OK,MessageBoxIcon.Information);}
习题三
privatevoidbuttonl_Click(objectsender,EventArgse)
(
inta,b,c,d,x;
x=Convert.ToInt32(textBox1.Text);
a=x/1000;
b=x/100-a*10;
c=x/10-a*100-b*10;
d=x%10;
textBox2.Text=Convert.ToString(a);
textBox3.Text=Convert.ToString(b);
textBox4.Text=Convert.ToString(c);
textBox5.Text=Convert.ToString(d);
)
习题四银行贷款的月还额
privatevoidbuttonl_Click(objectsender,EventArgse)
doublep,r,a,b;
intn;
p=Convert.ToDouble(textBox1.Text);
r=Convert.ToDouble(textBox2.Text);
n=Convert.ToInt32(textBox3.Text);
b=Math.Pow((l+r),n);
a=p*r*b/(b-1);
textBox4.Text=a.ToString(".##");
习题五、随机数
privatevoidbuttonl_Click(objectsender,EventArgse)
{Randomintra=newRandom();inta=intra.Next(l,101);
charb=(char)a;textBoxl.Text=Convert.ToString(a);
textBox2.Text=Convert.ToString(b);}
第三章
习题二是否是闰年
privatevoidbutton1_Click(objectsender,EventArgse)
inta;
a=Convert.ToInt32(textBoxl.Text);
if(a%4==0&&a%100!二0||a%400==0)
label2.Text="闰年";
else
label2.Text="不是闰年”;
习题三一元二次方程组
privatevoidbuttonl_Click(objectsender,EventArgse){
inta,b,c;doublex;
a=Conveil.ToInt32(textBox1.Text);b=Convert.ToInt32(textBox2.Text);
c二Convert.ToInt32(textBox3.Text);x=Math.Pow(b,2);
if(a==0)
abe14.Text="不是一元二次方程";
else{if(x-4*a*c==0)label4.Text="有两个相等的实根”;
elseif(x-4*a*c>0)label4.Text="有两个不等的实根”;
elselabel4.Text="无解";}}
习题四
privatevoidbutton1_Click(objectsender,EventArgse)
(
doublea,b,c,m,s;
a=Convert.ToDouble(textBox1.Text);
b=Convert.ToDouble(textBox2.Text);
c=Convert.ToDouble(textBox3.Text);
m=(a+b+c)/2;
if(a>0&&b>0&&c>0)
(
if(a+b>c&&a+c>b&&b+c>a)
(
s=Math.Sqrt(m*(m・a)*(m-b)*(m・c));
label4.Text二"三角形面积为”+s;
)
else
(
MessageBox.Show(n输入错误",”提示n,MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
label4.Text=,M,;}}
else{MessageBox.Show("输入错误","提示",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
labe14.Text二}}
习题一、
privatevoidbutton1_Click(objectsender,EventArgse)
(
inta,b,c,max,min;
a=Convert.ToInt32(textBoxl.Text);
b=Convert.ToInt32(textBox2.Text);
c=Convert.ToInt32(textBox3.Text);
max=(a>b?a:b)>c?(a>b?a:b):c;
min=(a<b?a:b)<c?(a<b?a:b):c;
b=a+b+c・max-min;
label5.Text=max+”,"+b+”,"+min;
第四章习题三
privatevoidbutton1_Click(objectsender,EventArgse)
{ints=0;
for(inti=l;i<=100;i++)
for(intj=0;j<=i;j++)
{s=s+j;}
textBoxl.Text=Convert.ToString(s);
privatevoidbuttonl_Click(objectsender,EventArgse)
(
ints=0,u=0;
for(inti=1;i<=100;i++)
(
u=u+i-l;
s=s+u+i;
)
textBoxl.Text=Converl.ToString(s);
习题五、3和7的倍数
privatevoidbuttonl_Click(objectsender,EventArgse)
(
for(inti=1;i<=100;i++){
if(i%3==0&&i%7==0)
textBoxl.Text二
textBoxl.Text+”\r\n"+Convert.ToString(i);}
习题一
privatevoidbuttonl_Click(objectsender,EventArgse)
(
ints=0;
for(inti=l;i<=100;i++){
s=s+i;
}
textBoxl.Text=Convert.ToString(s)
第五章习题六
privatevoidbuttonl_Click(objectsender,EventArgse)
{int[]a;inti,n;
n二Convert.ToInt32(textBox1.Text);
BestPersonf=newBestPerson();f.getBestPosition(n,outa);
for(i=0;i<n;i++)
textBox3.Text=textBox3.Text+Convert.ToString(a[i]);}
publicpartialclassBestPerson{
publicvoidgetBestPosition(inta,outint[]s)
{s=newint[50];inti,j=-1,k;
for(i=0;i<a;i++){s[i]=0;}
for(i=1;iv=a;i++)
{k=0;
do{j++;if(j=a)j=0;if(s[j]==0)k++;
}while(k!=7);
s[j]=i;
})
第五章习题八
privatevoidbuttonl_Click(objectsender,EventArgse)
(
Students=newStudent();
MasterStudentm=newMasterStudent();
m.Age=Convert.ToInt32(textBox2.Text);
m.Name=textBoxl.Text;
m.Number=textBox4.Text;
m.Sex二textBox3.Text;
m.Major=textBox5.Text;
m.Teacher=textBox6.Text;
if(m.UpdateAge(m.Age))
m.sayHallo();
elseMessageBox.Show("年龄有错!)
publicclassStudent
{privatestringnumber;publicstringNumber
{get{returnnumber;}
set{number=value;}}
privatestringname;publicstringName
{get{returnname;}set{name=value;}}
privatestringsex;
publicstringSex{get{returnsex;}set{sex=value;}
privateintage;
publicintAge{get{returnage;}set{age=value;}}
publicBooleanUpdateAge(inta){
if(a>0&&a<=120){age=a;returntrue;}
else
returnfalse;}
publicvoidsayHallo(){
MessageBox.Show("我是一名学生,我的名字是:n+Name.ToStringO+年龄:
”+Age.ToStringO+”,性别:”+Sex.ToStringO+“,学号:"+Number.ToStringO);}}
publicclassMasterStudent:Student{
publicstringMajor;
publicstringTeacher;
publicnewvoidsayHallo(){
MessageBox.Show("我是一名研究生,我的名字是:"+Name.ToStringO+年龄:”+
Age.ToStringO+\性别:”+Sex.ToStringO+”,学号:n+Number.ToStringO+",方向:
“+Major+”,指导老师"+Teacher);}}}
习题5
intfac(intn){if(n>0){
if(n==1)return(1);
elsereturn(n*fac(n-1));}
elsereturn1;}
privatevoidbuttonl_Click(objectsender,EventArgse)
{intn,s;
n=Convert.ToInt32(textBox1.Text);
s=fac(n);
textBox2.Text二Convert.ToString(s);}
}
)
第六章习题七
privatevoidbuttonl_Click(objectsender,EventArgse)
(
inti;party[]p=newparty[3];
partypl=newparty。;communistPartyp2=newcommunistPartyO;
kuomintangp3=newkuoinintangO;
p[O]=pl;p[l]=p2;p[2]=p3;
for(i=0;i<3;i++)
p[i].sayPolicy();}}
publicclassparty
{publicvirtualvoidsayPolicyO{
MessageBox.Show("两岸同属于一个中国。”);
})
publicclasscommunistPai'ty:party{
publicoverridevoidsayPolicyO{
MessageBox.Show("两岸同属于一个中国,用一国两制统一中国。");
})
publicclasskuomintang:party{
publicoverridevoidsayPolicy(){
MessageBox.Show("两,同属于一个中国,用三民主义统一中国。");)
})
privatevoidbuttonl_Click(objectsender,EventArgse)
{Catc=newCat();=textBoxl.Text;
Mousem=newMouse();=textBox2.Text;
c.getUp十=newsayGetUpDelegate(m.sayGetUp);
c.crow();}}
习题八
publicdelegatevoidsayGetUpDelegate();
publicclassCat
(
publiceventsayGetUpDelegategetUp;
publicstringname;
publicvoidcrow()
(
Messag6Box.Show(name+”口芮〜啼〜啼〜口帝〜喷〜喷〜”);
getUp();
)
)
publicclassMouse
(
publicstringname;
publicvoidsayGetUp()
(
MessageBox.Show(name+"快跑!!!!");
习题九
privatevoidbutton1_Click(objectsender,EventArgse)
{traint=newtrain();=textBoxl.Text;
catc=newcat();=textBox2.Text;
c.h=Convert.ToInt16(textBox3.Text);
t.nshow();c.nshow();}
privatevoidbutton2_Click(objectsender,EventArgse)
{traint=newtrain();
catc=newcat();
t.shout();
c.shout();}}
publicinterfacemakeVoice{inth{get;set;}voidshout();}
publicabstractclassVehicle{publicstringname;publicabstractvoidnshow();}
publicabstractclassAnima{publicstringname;publicabstractvoidnshow();}
publicclasstrain:Vehicle,makeVoice{intH;publicinth
{get{returnthis.H;}set{this.H=value;}}
publicoverridevoidnshow(){MessageBox.Show("train的名字是”+name);}
publicvoidshout(){MessageBox.Show(”train"+”呜呜嗒嗒。。。…呜呜嗒嗒)}}
publicclasscat:Aniinal,makeVoice{intH;
publicinth{
get{returnthis.H;}
set{this.H=value;}}
publicoverridevoidnshow(){
MessageBox.Show(ncatfi\J^^^"+name+,,^j^^',+h);)
publicvoidshout(){
MessageBox.Show(“cat"+"哺唯瞄。。…。唯嘀嘀");}}}
第七章习题一
随机产生10个两位整数,找出其中最大值,最小值、高于平均数的数
privatevoidbuttonl_Click(objectsender,EventArgse){
intsum=0;intz;Randomra=newRandom();
int[]a=newint[10];
for(inti=0;i<a.Length;i++){a[i]=ra.Next(10,100);}
z,
for(inti=0;i<a.Length;i++){textBoxl.Text十二Convert.ToString(a[i]+")};
for(inti=0;i<a.Length;i++){sum+二a[i]};
z=sum/10;
textBox4.Text=Convert.ToString(z)
for(inti=0;i<a.Length;i++)
(
if(a[i]>=z)
(
textBox5.Text+=Convert.ToString(a[i]+〃);
)
}Array.Sort(a);
textBox2.Text二Convert.ToString(a[9]);
textBox3.Text=Convert.ToString(a[0]);}
产生10个学生的成绩,并用冒泡进行排序
privatevoidbuttonlClick(objectsender,EventArgse){
Randomra=newRandom();
int[]a=newint[10];
for(inti=0;i<a.Length;i++){a[i]=ra.Next(1,100);
textBoxl.Text+二Convert.ToString(a[i]+"〃);}
for(inti=0;i<a.Length-1;i++)
{for(intj=i+1;j<a.Length;j++)
{if(a[i]<a[j])
{intt;t=a[i];a[i]=a[j];a[j]=t;}}}
for(inti=0;i<a.Length;i++)
{textBox2.Text+=Convert.ToString(a[i]+〃〃);}}
交错数组
privatevoidbuttonl_Click(objectsender,EventArgse)
(
int[][]jcArray=newint[4][];
jcArrayfO]=newint[]{1,32,89,6,8};
jcArray[l]=newint[]{2,17,8};
jcArray[2]=newint[]{3,5};
jcArray[3]=newint[]{4,9,23,12);
textBoxl.Text=”交错数组的数据:"+"\r\n”;
foreach(intf]jinjcArray)
(
intx=0;
foreach(intiinj)
{
x+=i;
textBoxl.Text+=Convert.ToString(i)+n\tn;
)
textBoxl.Text+="\r\n"+”该行数据总和为:
n+Convert.ToString(x)+"\r\nH;
}}}}
用二维数组存储学生成绩
privatevoidbuttonl_Click(objectsender,EventArgse)
(
int[,]cj={{1001,93},{1004,78},{1002,59},{1005,87},{2001,55}};
textBoxl.Text=〃学生成绩〃;
for(inti=0;i<cj.GetLength(0);i++)
for(intj=0;j<cj.GetLength(1);j++)
{if(j=1)
textBoxl.Text=textBoxl.Text+〃\t〃+Convert.ToString(cj[i,j]);
elsetextBoxl.Text=textBoxl.Text++Convert.ToString(cj[i,j]);
textBoxl.Text=textBoxl.Text+〃\r\n〃+〃不及格的学生”;
for(inti=0;i<cj.GetLength(O);i++)
if(cj[i,1]<60)
textBoxl.Text=textBoxl.Text+〃\r\n〃+Convert.ToString(cj[i,0])+
,z\t/z+Convert.ToString(cj[i,1])
textBoxl.Text+=〃\r\rT+〃平均成绩〃;
intsum=0;intz;;
for(inti=0;i<cj.GetLength(O);i++)
{sum+=cj[i,1];}
z=sum/cj.GetLength(O);
textBoxl.Text+=Convert.ToString(z);}}}
第十章
简易文本编辑器
privatevoidbuttonl_Click(objectsender,EventArgse)
(
richTextBoxl.Text=〃〃;
)
privatevoidbutton2_Click(objectsender,EventArgse)
(
openFileDialogl.FileName=〃〃;
openFileDialogl.ShowReadOnly=true;
openFileDialogl.ReadOnlyChecked=true;
openFileDialogl.Filter=text|text|RTF文件(*.rtf)|rtf〃;
if(openFileDialogl.ShowDialogO==DialogResult.OK)
richTextBoxl.LoadFi1e(openFi1eDialog1.FileName,
RichTextBoxStreamType.RichText);
)
privatevoidbutton3_Click(objectsender,EventArgse)
(
saveFi1eDialog1.InitialDirectory=
saveFileDialogl.Filter=〃*.texttext|RTF文件(*.rtf)*.rtf”;
if(saveFileDialogl.ShowDialogO==DialogResult.OK)
richTextBoxl.SaveFile(saveFileDialogl.FileName,
RichTextBoxStreamType.RichText);
)
privatevoidbutton4_Click(objectsender,EventArgse)
(
fontDialogl.ShowApply=true;
if(fontDialogl.ShowDialogO==DialogResult.OK)
richTextBoxl.Font=fontDialogl.Font;
privatevoidbutton5_Click(objectsender,EventArgse)
{
colorDialogl.ShowHelp=true;
if(colorDialogl.ShowDialogO==DialogResult.OK)
richTextBoxl.SelectionColor=colorDialogl.Color;
)
privatevoidForml_Load(objectsender,EventArgse)
(
)
}
)
第H^一章
通讯录(数据库)
OleDbConnectionmConn=newOleDbConnectionO;
OleDbDataAdaptermAdapter;
01eDbCommandBui1dermBuilder;
DataTablemDatatable=newDataTable();
intmRowposition=0;
privatevoidshowRecord()
(
if(mDatatable.Rows.Count==0)
{
textBoxl.Text=〃〃;
textBox2.Text=〃〃;
textBox3.Text=〃〃;
textBox4.Text=〃〃;
textBox5.Text=〃〃;
)
textBoxl.TextmDatatable.Rows[mRowposition][〃编号
ToStringO;
textBox2.TextmDatatable.Rows[mRowposition][〃姓名
〃]・ToStringO;
textBox3.TextmDatatable.Rows[mRowposition][〃性别
ToStringO;
textBox4.TextmDatatable.Rows[mRowposition][〃籍贯
〃]・ToStringO;
textBox5.TextmDatatable.Rows[mRowposition][〃电话
〃].ToStringO;
)
publicForml0
InitializeComponent();
privatevoidlabell_Click(objectsender,EventArgse)
privatevoidForml_Load(objectsender,EventArgse)
(
mConn.ConnectionString=@,zProvider
=Microsoft.Jet.OLEDB.4.0;DataSource=F:\新建文件夹\1208150129林相玲(12)\
通讯录.mdb〃;
mConn.Open();
mAdapter=newOleDbDataAdapter(,zselect*from通讯录〃,mConn);
mBuilder=newOleDbCommandBuiIder(mAdapter);
mAdapter.Fill(mDatatable);
this.showRecord();
)
privatevoidForml_FormClosing(objectsender,FormClosingEventArgse)
(
mConn.Close();
mConn.Dispose();
)
privatevoidlabel5_Click(objectsender,EventArgse)
(
)
privatevoidbuttonl_Click(objectsender,EventArgse)
{
mRowposition=0;
this.showRecord();
}
privatevoidbutton2_Click(objectsender,EventArgse)
(
if(mRowposition<mDatatable.Rows.Count-1)
(
mRowposition=mRowposition+1;
this.showRecord();
)
)
privatevoidbutton3_Click(objectsender,EventArgse)
(
if(mRowposition!=0)
mRowposition=mRowposition-1;
this.showRecord();
}
privatevoidbutton4_Click(objectsender,EventArgse)
if(mDatatable.Rows.Count!=0)
mRowposition=mDatatable.Rows.Count-1;
this.showRecord();
)
privatevoidbutton5_Click(objectsender,EventArgse)
(
if(button5.Text==〃添加〃)
{
button5.Text=〃确认添加〃;
textBoxl.Text=〃〃;
textBox2.Text=〃〃;
textBox3.Text=〃〃;
)
else
(
button5.Text=〃添加〃;
DataRowmNewrow=mDatatable.NewRowO;
mNewrow[”编号〃]=textBoxl.Text;
mNewrow[〃姓名〃]=textBox2.Text;
mNewrow[〃电话号码〃]=textBox3.Text;
mDatatable.Rows.Add(mNewrow);
mAdapter.Update(mDatatable);
mRowposition=mDatatable.Rows.Count-1;
this.showRecord();
)
}
privatevoidbutton6_Click(objectsender,EventArgse){
if(mDatatable.Rows.Count!=0){
mDatatable.Rows[mRowposition][〃编号〃]=textBoxl.Text;
mDatatable.Rows[mRowposition][〃姓名〃]=textBox2.Text;
mDatatable.Rows[mRowposition][〃电话号码〃]=textBox3.Text;
mAdapter.Update(mDatatable);
)
)
privatevoidbutton7_Click(objectsender,EventArgse)
(
if(mDatatable.Rows.Count!=0)
(
mDatatable.Rows[mRowposition].Delete();
mAdapter.Update(mDatatable);
mRowposition=mRowposition-1;
this.showRecord();
privatevoidbutton8_Click(objectsender,EventArgse)
(
Booleanf=false;
DataRowmrow;
for(inti=0;i<mDatatable.Rows.Count;i++)
(
mrow=mDatatable.Rows[i];
if(Convert.ToString(mrow[〃编号〃])==〃01〃){
f=true;
mRowposition=i;
this.showRecord();
break;}
if(f==false)
MessageBox.Show(〃没有找到!!〃);}}}}
第八章
文件的加密解密
publicpartialclassForml:Form
(
DESdes=newDESCryptoServiceProvider();
publicForml()
(
InitializeComponent();
}
privatevoidbuttonl_Click(objectsender,EventArgse)
(
inti;
FileStreamfin=newFileStream(textBoxl.Text,FileMode.Open,
FileAccess.Read);
FileStreamfout=newFileStream(textBox2.Text,
Fi1eMode.OpenOrCreate,FileAccess.Write);
fout.SetLength(O);
Byte[]bin=newbyte[100];
longrdlen=0;
longtolen=fin.Length;
intlen;
textBox3.Text=des.Key[0].ToStringO;
for(i=0;i<8;i++)
{
textBox3.Text=textBox3.Text+〃,〃+des.Key[i].ToStringO;
)
CryptoStreamencStream=newCryptoStream(fout,
des.CreateEncryptor(),CryptoStreamMode.Write);
while(rdlen<tolen)
(
len=fin.Read(bin,0,100);
encStream.Write(bin,0,len);
rdlen=rdlen+len;
)
encStream.Close();
fout.Close();
fin.Close();
)
privatevoidbutton2_Click(objectsender,EventArgse)
{
inti;
FileStreamfin=newFileStream(textBox2.Text,FileMode.Open,
FileAccess.Read);
FileStreamfout=newFileStream(textBox4.Text,
FileMode.OpenOrCreate,FileAccess.Write);
fout.SetLength(0);
Byte[]bin=newbyte[100];
longrdlen=0;
longtolen=fin.Length;
intlen;
textBox3.Text=des.Key[0].ToStringO;
for(i=0;i<8;i++)
(
textBox3.Text=textBox3.Text+〃,〃+des.Key[i].ToStringO;
)
CryptoStreamencStreaml=newCryptoStream(fout,
des.CreateDecryptor(),CryptoStreamMode.Write);
while(rdlen<tolen)
(
len=fin.Read(bin,0,100);
encStreaml.Write(bin,0,len);
rdlen=rdlen+len;
)
encStreaml.Close();
fout.Close();
fin.Close();
)
)
}
绘制五环
privatevoidbuttonl_Click(objectsender,EventArgse)
Penpel,pe2,pe3,pe4,pe5;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年上海建桥学院单招职业技能测试题库含答案详解
- 2026年上饶职业技术学院单招综合素质考试题库附答案详解
- 2026年海南职业技术学院单招职业技能测试题库及参考答案详解1套
- 2026年泉州工程职业技术学院单招职业倾向性考试题库附答案详解
- 烟台医院面试题目及答案
- 三甲医院医生面试题目及答案
- 2025年招聘天津津彩城投投资管理有限公司面向社会公开选聘备考题库含答案详解
- 2025安全生产环保工作总结(2篇)
- 2025年广州医科大学附属第五医院人才招聘计划备考题库完整参考答案详解
- 2025年复旦大学附属妇产科医院招聘超声科主任备考题库及一套答案详解
- 2025年云南省人民检察院聘用制书记员招聘(22人)模拟笔试试题及答案解析
- 2025年党的基础知识题库及答案入党理论知识考试试题
- 2026民航招飞心理测试题及答案
- 2026年超市采购工作计划模版(三篇)
- 时间序列期末试题及答案
- 2025年10月自考02275计算机基础与程序设计试题及答案版
- 临床技能规范化培训实施方案
- 设计师提成合同协议书
- 2025年三级安全教育培训试卷(附答案)
- 辖区民警校园安全课件
- (2025年)陪诊师考试过程解析试题及答案
评论
0/150
提交评论