复印程序设计题.docx

上传人:b****6 文档编号:7236085 上传时间:2023-01-22 格式:DOCX 页数:32 大小:33.51KB
下载 相关 举报
复印程序设计题.docx_第1页
第1页 / 共32页
复印程序设计题.docx_第2页
第2页 / 共32页
复印程序设计题.docx_第3页
第3页 / 共32页
复印程序设计题.docx_第4页
第4页 / 共32页
复印程序设计题.docx_第5页
第5页 / 共32页
点击查看更多>>
下载资源
资源描述

复印程序设计题.docx

《复印程序设计题.docx》由会员分享,可在线阅读,更多相关《复印程序设计题.docx(32页珍藏版)》请在冰豆网上搜索。

复印程序设计题.docx

复印程序设计题

第一章

1.编写一个C#Windows应用程序,程序的设计界面如图所示。

程序运行时单击【退出】按钮将结束应用程序的执行。

namespaceD_1_1

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{

Application.Exit();

}

}

}

2.找出下列程序中的错误,并用VisualStudio.NET中的命令行编译器CS.EXE.进行编译。

classExample1

{publicstaticvoidMain()

{stringa;

a=System.Console.ReadLine();

System.Console.WriteLine("a={0}",a);

}

}

第二章

1.编写一个程序,从键盘上输入3个数,输出这三个数的积及它们的和。

要求编写成控制台应用程序。

classTest2_1

{publicstaticvoidMain()

{inta,b,c,sum,mul;

a=Convert.ToInt32(Console.ReadLine());

b=Convert.ToInt32(Console.ReadLine());

c=Convert.ToInt32(Console.ReadLine());

sum=a+b+c;

mul=a*b*c;

Console.WriteLine("Sum={0},Mul={1}",sum,mul);

}

}

2.编写一个程序,输入梯形的上底、下底和高,输出梯形的面积。

要求编写成Windows应用程序,程序的运行界面如图所示

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{

doublea,b,h,s;

a=Convert.ToSingle(textBox1.Text);//输入上底

b=Convert.ToSingle(textBox2.Text);//输入下底

h=Convert.ToSingle(textBox3.Text);//输入下底

s=1.0/2.0*(a+b)*h;//求面积;

textBox4.Text=Convert.ToString(s);//显示面积

}

第三章

1.编写一个进行加、减、乘、除四则运算的程序,要求:

输入两个单精度数,然后输入一个运算符号,输出两个单精度数进行该运算后的结果。

要求编写为控制台程序。

usingSystem;

classD_3_1

{publicstaticvoidMain()

{doubleop1,op2,result=0;

charkind;

op1=Convert.ToDouble(Console.ReadLine());

op2=Convert.ToDouble(Console.ReadLine());

kind=(char)Console.Read();

switch(kind)

{case'+':

result=op1+op2;break;

case'-':

result=op1-op2;break;

case'*':

result=op1*op2;break;

case'/':

result=op1/op2;break;

}

Console.WriteLine("{0}{1}{2}={3}",op1,kind,op2,result);

}

}

2.兔子繁殖问题。

设有一对新生的兔子,从第三个月开始它们每个月都生一对兔子,新生的兔子从第三个月开始又每个月生一对兔子。

按此规律,并假定兔子没有死亡,20个月后共有多少兔子?

要求编写为控制台应用程序。

usingSystem;

classD_3_2

{publicstaticvoidMain()

{inta,b,c,i;

a=1;b=1;

Console.Write("{0}{1}",a,b);

for(i=3;i<=20;i++)

{c=a+b;

Console.Write("{0}",c);

a=b;

b=c;

if(i%5==0)Console.WriteLine();

}

}

}

第四章

1.编写程序,把由10个元素组成的一维数组逆序存放再输出。

usingSystem;

classD_4_1

{publicstaticvoidMain()

{int[]a=newint[]{1,2,3,4,5,6,7,8,9,10};//定义数组并初始化

inti,j,t;

Console.WriteLine("反序之前:

");

for(i=0;i<10;i++)

Console.Write("{0}",a[i]);

i=0;j=9;

while(i

{t=a[i];a[i]=a[j];a[j]=t;

i++;j--;

}

Console.WriteLine("\n反序之后:

");

for(i=0;i<10;i++)

Console.Write("{0}",a[i]);

}

}

2.编写程序,统计4*5二维数组中奇数的个数和偶数的个数。

usingSystem;

classD_4_2

{publicstaticvoidMain()

{constintM=2;

constintN=2;

int[,]a=newint[M,N];

inti,j,jishu,oushu;

jishu=0;oushu=0;

RandomrandObj=newRandom();//生成随机数变量

for(i=0;i

for(j=0;j

a[i,j]=randObj.Next(1,100);//产生随机数并赋值给数组

for(i=0;i

{Console.WriteLine();//换行

for(j=0;j

Console.Write("{0}",a[i,j]);

}

for(i=0;i

for(j=0;j

{if(a[i,j]%2==1)jishu=jishu+a[i,j];

elseoushu=oushu+a[i,j];

}

Console.WriteLine("\n奇数和为{0},偶数和为{1}",jishu,oushu);

}

}

第五章

1.编写一个递归方法求下式的和s,n的值由用户输入。

s(n)=1²+2²+3²+……+n²

longf(intn)

{

if(n==1)return

(1);

elsereturn(f(n-1)+n*n);

    }

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{intk;longresult;

k=Convert.ToInt32(textBox1.Text);

result=f(k);

textBox2.Text=Convert.ToString(result);

}

privatevoidbutton2_Click(objectsender,System.EventArgse)

{

Application.Exit();

}

}

}

2.编写一个求整数任意位数字的过程,过程的调用形式为:

digit(n,k),其功能是取出数n从右边起的第k位数字,例如:

digit(1234,3)=2,digit(1234,4)=1,digit(1234,6)=0.

protectedoverridevoidDispose(booldisposing)

{

if(disposing)

{

if(components!

=null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}

intdigital(longn,intk)

{inti;

for(i=1;i

n=n/10;

return((int)n%10);

}

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidbutton2_Click(objectsender,System.EventArgse)

{

Application.Exit();

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{longnum;intm,w;

num=Convert.ToInt64(textBox1.Text);

m=Convert.ToInt32(textBox2.Text);

w=digital(num,m);

textBox3.Text=Convert.ToString(w);

}

}

}

 

第六章

1.编写一个应用程序用来对输入的字符串进行加密,对于字母字符加密规则如下:

‘a’→’d’‘b’→’e’‘w’→’z’……‘x’→’a’‘y’→’b’‘z’→’c’

‘A’→’D’‘B’→’E’‘W’→’Z’……’X’→’A’‘Y’→’B’‘Z’→’C’

对于其他字符,不进行加密。

程序的运行界面如图所示。

 

 

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidForm1_Load(objectsender,System.EventArgse)

{

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{

stringSStr,DStr;

inti;

charc;

SStr=textBox1.Text;DStr="";

for(i=0;i

{c=SStr[i];

if(c>='a'&&c<='z'||c>='A'&&c<='Z')

{

c=(char)(SStr[i]+3);

if(c>'z'&&c<='z'+3||c>'Z'&&c<='Z'+3)

c=(char)(c-26);

}

DStr=DStr+c.ToString();

}

textBox2.Text=DStr;

}

privatevoidbutton2_Click(objectsender,System.EventArgse)

{

Application.Exit();

}

}

}

2.编写一个应用程序用来从一个字符串中删除一个字符,程序的界面如图所示

 

 

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidlabel3_Click(objectsender,System.EventArgse)

{

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{

stringSStr1,DStr,delstr;

inti;

SStr1=textBox1.Text;

delstr=textBox2.Text;

DStr="";

for(i=0;i

if(SStr1.Substring(i,1)!

=delstr)

DStr=DStr+SStr1.Substring(i,1);

textBox3.Text=DStr;

}

privatevoidbutton2_Click(objectsender,System.EventArgse)

{

Application.Exit();

}

}

}

 

第七章

1.定义一个车辆(Vehicle)基类,具有Run、Stop等方法,具有Speed(速度)、MaxSpeed(最大速度)、Weight(重量)等域。

然后以该类为基类,派生出bicycle、car等类。

并编程对派生类的功能进行验证。

usingSystem;

namespaceD_7_1

{

publicclassvehicle

{

publicdoubleSpeed;

publicdoubleMaxSpeed;

publicdoubleWeight;

publicvirtualstringRun()

{

return("一辆车在马路上奔跑。

");

}

publicvirtualstringStop()

{

return("一辆车在马路上停了下来。

");

}

}

publicclassbicycle:

vehicle

{publicdoublePrice;

publicbicycle(doubleS,doubleM,doubleW,doubleP)

{

Speed=S;

MaxSpeed=M;

Weight=W;

Price=P;

}

publicoverridestringRun()

{return("一辆自行车在马路上奔跑。

");

}

publicoverridestringStop()

{

return("一辆自行车在马路上停了下来。

");

}

}

publicclasscar:

vehicle

{

publicdoublePrice;

publicoverridestringRun()

{

return("一辆小汽车在马路上奔跑。

");

}

publicoverridestringStop()

{

return("一辆小汽车在马路上停了下来。

");

}

publiccar(doubleS,doubleM,doubleW,doubleP)

{

Speed=S;

MaxSpeed=M;

Weight=W;

Price=P;

}

}

}

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{

vehiclev=newvehicle();

label1.Text=v.Run()+""+v.Stop();

bicyclebike=newbicycle(50,100,50,285);

label2.Text=bike.Run()+"速度:

"+bike.Speed.ToString()+""+bike.Stop();

carCar=newcar(100,250,300,150000.0);

label3.Text=Car.Run()+"速度:

"+Car.Speed.ToString()+""+Car.Stop();

 

}

}

}

2.编写出一个通用的人员类(Person),该类具有姓名(Name),年龄(Age),性别(Sex)等域。

然后通过对Person类的继承得到一个学生类(Student),该类能够存放学生的5门

课的成绩,并能求出平均成绩,要求对该类构造函数进行重载,至少给出三个形式。

最后编程对Student类的功能进行验证。

usingSystem;

namespaceD_7_2

{

publicclassPerson

{

publicstringName;

publicintAge;

publiccharSex;

}

publicclassStudent:

Person

{publicdouble[]Score;

publicdoubleAver;

publicStudent(stringxm,intnl,charxb)

{Name=xm;

Age=nl;

Sex=xb;

Score=newdouble[5];

}

publicStudent()

{Name="";

Age=18;

Sex='M';

Score=newdouble[5];

}

publicStudent(stringxm,intnl,charxb,double[]cj)

{

Name=xm;

Age=nl;

Sex=xb;

Score=newdouble[5];

for(inti=0;i<5;i++)

Score[i]=cj[i];

}

publicdoubleCalAver()

{doublesum=0;

for(inti=0;i<5;i++)

sum=sum+Score[i];

Aver=sum/5;

return(Aver);

}

}

}

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{

RandomrandomObj=newRandom();

textBox4.Text="";

for(inti=0;i<5;i++)

{

cj[i]=randomObj.Next(0,101);

textBox4.Text=textBox4.Text+cj[i].ToString()+",";

}

}

privatevoidbutton2_Click(objectsender,System.EventArgse)

{

stringxm=textBox1.Text;

intnl=Convert.ToInt32(textBox2.Text);

charxb=Convert.ToChar(textBox3.Text);

StudentS1=newStudent(xm,nl,xb,cj);

S1.CalAver();

textBox5.Text=S1.Aver.ToString();

}

}

}

 

第八章

1.编写一个冒泡法排序程序。

要求在程序中能够捕获到数组下标越界的异常。

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidbutton1_Click(objectsender,System.EventArgse)

{

inti;

RandomrandObj=newRandom();//生成随机数变量

for(i=0;i

a[i]=randObj.Next(10,99);/*产生随机数并赋值给数组元素*/

textBox1.Text="";

for(i=0;i

textBox1.Text+=a[i].ToString()+",";

}

privatevoidbutton2_Click(objectsender,System.EventArgse)

{inti,j,t;//定义循环变量和交换用的临时变量

try

{

for(i=1;i<=N;i++)/*i表示轮次*/

for(j=0;j<=N-i;j++)/*j表示每轮比较的次数*/

if(a[j]>a[j+1])/*如果后面的元素值小,则交换*/

{t=a[j];a[j]=a[j+1];a[j+1]=t;}

textBox2.Text="";

for(i=0;i

textBox2.Text+=a[i].ToString()+",";

}

catch(IndexOutOfRangeExceptionex)

{textBox2.Text="数组下标越界";

}

 

}

}

}

2、编写一个计算机应用程序,要求在程序中能够捕获到被0除的异常与算术运算溢出的异常。

staticvoidMain()

{

Application.Run(newForm1());

}

privatevoidbutton4_Click(objectsender,System.EventArgse)

{

op=4;labe

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1