5、
if(k==4)Console.WriteLine("鞍點(diǎn):第{0}行,第{1}列",i+l,maxj+l);}
}staticvoidMain(string[]args)
{
inta=20,b=16,i=20;
do
{
if(i%a==0&i%b==0)break;
3)
i++;
}while(true);
Console.WriteLine("最小公倍數(shù):{0}",i);
i=16;
do
{
if(a%i==0&b%i==0)break;
i--;
}while(true);Console.WriteLine(”最大公約數(shù):{0}",i);
6、
}
4)
staticvoidMain(string[]args)
{
inti,j,k;
floats=1.0f;
for(i=2;i<11;i++)
{
k=1;
for(j=2;j<=i;j++)k+=j;
s+=1.0f/k;
}
Console.WriteLine("s={0}",s);
}
5)
staticvoidMain(string[]args)
{
Strings="a,b2>4[AG6p(";
inti,n1=0,n2=0,n3=0,n4=0;for(i=0;i=65&s[i]<=
7、90)n1++;
if(s[i]>=97&s[i]<=122)n2++;if(s[i]>=48&s[i]<=57)n3++;
}
n4=s.Length-n1-n2-n3;
Console.WriteLine("大寫字母?jìng)€(gè)數(shù):{0};小寫字母?jìng)€(gè)數(shù):{1};數(shù)字個(gè)數(shù):{2};其余字符個(gè)數(shù):{3}",n1,n2,n3,n4);
}
staticvoidMain(string[]args)
{
inti,s=1;
for(i=0;i<5;i++)
6)
s=2*(s+1);
}
Console.WriteLine("小猴子第一天摘了{(lán)0}個(gè)桃子",s);
}
說明:
8、由最后一天往前推算。后一天吃了前一天桃子數(shù)量的一半多1個(gè),剩余桃子數(shù)量是前一天桃子數(shù)量的一半減1,則,前一天的桃子數(shù)量是后一天的桃子數(shù)量加1的2倍。
—*
第三章
1.判斷題
(1)v(2)X(3)V(4)V(5)V(6)X(7)V(8)X(9)X(10)V
(11)V(12)V(13)V(14)X(15)V(16)V(17)X(18)V(19)V(20)X(21)X(22)V(23)V(24)V(25)X(26)X(27)X
2.選擇題
(I) C(2)B(3)C(4)D(5)C(6)B(7)D(8)C(9)A(10)A
(II) B(12)A(13)D(14)B(15)C
9、
3. 分析下列程序的運(yùn)行結(jié)果
(1) s=32,s1=32,s2=34
x=11,y=21
(2) x1=3,x2=4
y1=1,y2=4
4. 編程題
(1)
classStudent
{
publicstringstudentid;
publicstringstudentname;
privatestringbirthplace;
privateDateTimebirthdate;
publicStudent(stringid,stringname)
{
studentid=id;
studentname=name;
}
publicstringStu
10、dentId
{
get{returnstudentid;}
set{studentid=value;}
}
publicstringStudentName
{
get{returnstudentname;}set{studentname=value;}
publicstringBirthPlace
{
get{returnbirthplace;}
set{birthplace=value;}
}
publicDateTimeBirthDate
{
get{returnbirthdate;}
set{birthdate=value;}
}
publicint
11、Age
{
get
{
returnDateTime.Now.Year-birthdate.Year+1;
}
}
}
2)
classPoint
{
publicintx,y;
publicPoint(intx1,inty1)
{
x=x1;y=y1;
}
publicstaticPointoperator++(Pointp1)
{returnnewPoint(p1.x+1,p1.y+1);
}
publicstaticPointoperator--(Pointp1)
{returnnewPoint(p1.x-1,p1.y-1);
}
public
12、staticdoubleoperator-(Pointp1,Pointp2)
{returnMath.Sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
}
3)
classPerson
{
publicstringname;publicstringsex;
publicDateTimebirthdate;
}
classTeacher:Person
{
publicstringworkid;
publicDateTimebeginwork;
publicdoublewage;
publicstatic
13、intnum;
publicdoubleWorkYears
{
get
{
returnDateTime.Now.Year-beginwork.Year
}
}
publicTeacher()
{
num++;
}
publicstaticintGetNum()
{
returnnum;
}
}
4)
abstractclassAnimal
{
publicstringName
{
get;
set;
}
publicintColor
{
get;
set;
}
publicabstractvoidShout();
publicab
14、stractvoidEat();
}
classTiger:Animal
{
publicoverridevoidShout()
{
Console.WriteLine("老虎叫”);
}
publicoverridevoidEat()
{
Console.WriteLine("老虎吃東西”);
}
}
classDuck:Animal
{
publicvoidSwim()
{
Console.WriteLine("游泳”);
}
publicoverridevoidShout()
{
Console.WriteLine("嘎嘎”);;
}
pub
15、licoverridevoidEat()
{
Console.WriteLine("鴨子吃東西”);
}
}
5)
publicinterfaceIShape
{
doublePerimeter();
doubleArea();
}
classCircle:IShape
{
publicdoubleRadius{get;set;}
publicCircle(doubler)
{
Radius=r;
}
publicdoubleArea()
{
returnMath.PI*Radius*Radius;
}
publicdoublePerimeter()
16、
{
return2*Math.PI*Radius;
classRectangle:IShape
{
publicdoubleLength{get;set;}
publicdoubleHeight{get;set;}publicRectangle(doublel,doubleh){
Length=l;Height=h;
}
publicdoubleArea()
{
returnLength*Height;
}
publicdoublePerimeter()
{
return2*(Length+Height);
}
}
第四章
1.判斷題
(1)v(2)X
17、(3)x(4)X(5)V(6)X(7)V(8)V(9)X(10)V
(11)V(12)X(13)X(14)X(15)V
2.選擇題
(I) C(2)A(3)C(4)C(5)B(6)A(7)B(8)C(9)D(10)A
(II) C(12)D(13)D(14)C(15)B(16)C(17)D(18)C(19)D(20)B
3.編程題
(1)新建一個(gè)Windows窗口應(yīng)用程序,在窗口上拖放一個(gè)標(biāo)簽label1和一個(gè)定時(shí)器timer1將timerl的Enabled屬性改成True。給窗口類添加一個(gè)私有字節(jié)類型字段D1,編寫timerl的Tick事件處理處理方法:
privatebyte
18、D1=0;
privatevoidtimer1_Tick(objectsender,EventArgse)
{
switch(D1)
{
case0:label1.Left+=10;if(label1.Right>this.ClientSize.Width)D1=1;break;
case1:label1.Top+=10;if(label1.Bottom>this.ClientSize.Height)D1=2;break;
case2:
label1.Left-=10;
if(label1.Left<0)D1=3;
break;
case3:
label1.Top-=1
19、0;
if(label1.Top<0)D1=0;
break;
}
}
2. 新建一個(gè)Windows窗口應(yīng)用程序,按照運(yùn)行效果圖設(shè)計(jì)窗口界面。其中的運(yùn)算操作數(shù)輸入和結(jié)果顯示采用TextBox控件,名稱分別為textBoxl、textBox2和textBox3;運(yùn)算符選擇采用RadioButton控件,加減乘除分別為radioButtonl到radioButton4;“=”按鈕采用Button控件,名稱為buttonl,編寫buttonl的Click事件處理方法:
privatevoidbutton1_Click(objectsender,EventArgse)
{
double
20、v1,v2,v=0;
v1=double.Parse(textBox1.Text);v2=double.Parse(textBox2.Text);
if(radioButton1.Checked==true)if(radioButton2.Checked==true)if(radioButton3.Checked==true)if(radioButton4.Checked==true)textBox3.Text=v.ToString();
v=v1+v2;
v=v1-v2;
v=v1*v2;
{if(v2!=0)v=v1/v2;}
}
3.利用4.6節(jié)知識(shí),參考圖4-29設(shè)
21、計(jì)具有菜單、工具欄和狀態(tài)欄的Windows窗口應(yīng)用程序。
AA-—T-
第五章
1. 判斷題
(1)v(2)X(3)V(4)V(5)X(6)V(7)X
2. 選擇題
(1)A(2)無答案,應(yīng)該是TextReader(3)A(4)C(5)A(6)C
3. 編程題
創(chuàng)建Windows窗口用于程序,在窗口上放置一個(gè)Button控件,名稱為button1,編寫其Click事件處理方法:
privatevoidbutton1_Click(objectsender,EventArgse)
{
inti,j;
int[,]a=newint[3,3];
int[,]b=newint[
22、3,3];
int[,]c=newint[3,3];
strings1;
string[]ss;
FileStreamfs=newFileStream(@"d:\data1.txt",FileMode.Open);
StreamReadersr=newStreamReader(fs,Encoding.Default);
StreamWritersw;
BinaryWriterbw;
for(i=0;i<3;i++)
{
s1=sr.ReadLine();
ss=s1.Split('');
for(j=0;j<3;j++)
{
a[i,j]=int.Parse(ss[
23、j]);
}
}
for(i=0;i<3;i++)
{
s1=sr.ReadLine();
ss=s1.Split('');
for(j=0;j<3;j++)
{
b[i,j]=int.Parse(ss[j]);
}
}sr.Close();fs.Close();
for(i=0;i<3;i++)
for(j=0;j<3;j++)c[i,j]=a[i,j]+b[i,j];
SaveFileDialogsfd=newSaveFileDialog();
sfd.Filter="文本文件(*.txt)|*.txt";
if(sfd.ShowDialog()==Dial
24、ogResult.OK)
{
fs=newFileStream(sfd.FileName,FileMode.OpenOrCreate);sw=newStreamWriter(fs,Encoding.Default);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
sw.Write(c[i,j]);sw.Write("");
}sw.Write("\n");
}
sw.Close();
fs.Close();
}
sfd.Filter="二進(jìn)制文件(*.bin)|*.bin";
if(sfd.ShowDialog()==DialogRes
25、ult.OK)
{
fs=newFileStream(sfd.FileName,FileMode.OpenOrCreate);bw=newBinaryWriter(fs);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
bw.Write(c[i,j]);
bw.Close();
fs.Close();
}
}
說明:datal.txt文件中共9行整數(shù),每行3個(gè)整數(shù),每個(gè)數(shù)據(jù)之間以一個(gè)空格隔開。
1.判斷題
(1)V(2)X(3)X(4)X(5)V(6)V(7)V(8)X(9)X(10)V
2.選擇題
(1)C(2)D(3)C(4)A(5)B(6
26、)C(7)B(8)D
3.編程題
創(chuàng)建Windows窗口應(yīng)用程序,在窗口上放置一個(gè)toolStrip控件,并在其中添加兩個(gè)組合框,名稱分別為toolStripComboBox1和toolStripComboBox2,給toolStripComboBox1添加選項(xiàng):短劃線、點(diǎn)劃線、雙點(diǎn)劃線、虛線、實(shí)線,給toolStripComboBox2添加選項(xiàng):1、2、3、4。給窗口添加如下私有字段:
privateGraphicsg1;
privateDashStyledashstyle=DashStyle.Solid;
privatefloatpenwidth=1;
privatePenpe
27、n1;
privateboolbeDraw=false;
privatePointp1,p2;
編寫comboBox1和comboBox2的SelectedIndexChanged事件處理方法:
privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse){
dashstyle=(DashStyle)comboBox1.SelectedIndex;
}privatevoidcomboBox2_SelectedIndexChanged(objectsender,EventArgse)
{
penwidth=f
28、loat.Parse(comboBox2.Text);
}
編寫Form3的Load、MouseDown、MouseMove和MouseUp以及工具欄上兩個(gè)組合框的SelectedIndexChanged事件處理方法:
privatevoidForm3_Load(objectsender,EventArgse)
{
toolStripComboBox1.SelectedIndex=toolStripComboBox1.Items.Count-1;toolStripComboBox2.SelectedIndex=0;
}
privatevoidForm3_MouseDown(obj
29、ectsender,MouseEventArgse)pen1=newPen(Color.Red,penwidth);pen1.DashStyle=dashstyle;beDraw=true;
p1=e.Location;
g1=this.CreateGraphics();
}
privatevoidForm3_MouseMove(objectsender,MouseEventArgse)
{
if(beDraw==true)
{
p2=e.Location;
g1.DrawLine(pen1,p1,p2);
p1=p2;
}
}
privatevoidForm3_Mo
30、useUp(objectsender,MouseEventArgse)
{
beDraw=false;
}
privatevoidtoolStripComboBox1_SelectedIndexChanged(objectsender,EventArgse){
dashstyle=(DashStyle)toolStripComboBox1.SelectedIndex;
}
privatevoidtoolStripComboBox2_SelectedIndexChanged(objectsender,EventArgse){
penwidth=float.Parse(toolSt
31、ripComboBox2.Text);
}
第七章
1.判斷題
(I) v(2)X(3)x(4)X(5)V(6)X(7)V(8)X(9)V(10)X
(II) V(12)X(13)V(14)V(15)V(16)V
2.選擇題
(I) A(2)D(3)C(4)A(5)D(6)B(7)C(8)D(9)B(10)C
(II) C12)C13)A14)B15)D16)D
3.編程題
(1)創(chuàng)建Windows窗口應(yīng)用程序,在窗口上放置兩個(gè)Button控件,名稱分別為button1和button2,再放置一個(gè)ComboBox控件和DataGridView控件,名稱分別為comboBox
32、l和dataGridView1。
編寫button1的Click事件處理方法:
privatevoidbutton1_Click(objectsender,EventArgse)
{
OleDbConnectioncon=newOleDbConnection();
OleDbCommandcom=newOleDbCommand();
con.ConnectionString=@"Provider=microsoft.jet.oledb.4.0;datasource=d:\aaa.mdb";con.Open();
com.CommandType=CommandType.Text;
33、
com.CommandText="select*fromScorewherescore>80";
com.Connection=con;
OleDbDataReaderdr=com.ExecuteReader();
comboBox1.Items.Clear();
while(dr.Read()==true)
{
if(dr.IsDBNull(dr.GetOrdinal("StudentID"))==false)comboBox1.Items.Add(dr["StudentID"]);
}
}
說明:為了使用ADO.NET的0LEDB訪問方式,需要添加下列引用:
usin
34、gSystem.Data.OleDb;
(2)界面與(1)相同。
編寫button2的Click事件處理方法:
privatevoidbutton2_Click(objectsender,EventArgse)
{
OleDbConnectioncon=newOleDbConnection();
OleDbCommandcom=newOleDbCommand();
con.ConnectionString=@"Provider=microsoft.jet.oledb.4.0;datasource=d:\aaa.mdb";
con.Open();
OleDbDataAdapterda=newOleDbDataAdapter("selectClassas班級(jí),avg(Score)as平均成績(jī)fromScoregroupbyClass",con);
DataSetds=newDataSet();
da.Fill(ds,"平均成績(jī)表");dataGridViewl.DataSource=ds.Tables]"平均成績(jī)表"];
}
(3) 參考7.7節(jié)的學(xué)生信息管理程序,編寫通訊錄管理程序,細(xì)節(jié)略。