复印程序设计题Word格式文档下载.docx

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

复印程序设计题Word格式文档下载.docx

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

复印程序设计题Word格式文档下载.docx

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

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

{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;

*'

result=op1*op2;

/'

result=op1/op2;

{0}{1}{2}={3}"

op1,kind,op2,result);

2.兔子繁殖问题。

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

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

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

classD_3_2

{inta,b,c,i;

a=1;

b=1;

Console.Write("

{0}{1}"

a,b);

for(i=3;

i<

=20;

i++)

{c=a+b;

{0}"

c);

a=b;

b=c;

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

第四章

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

classD_4_1

{int[]a=newint[]{1,2,3,4,5,6,7,8,9,10};

//定义数组并初始化

inti,j,t;

反序之前:

"

);

for(i=0;

10;

a[i]);

i=0;

j=9;

while(i<

j)

{t=a[i];

a[i]=a[j];

a[j]=t;

i++;

j--;

}

\n反序之后:

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

classD_4_2

{constintM=2;

constintN=2;

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

inti,j,jishu,oushu;

jishu=0;

oushu=0;

RandomrandObj=newRandom();

//生成随机数变量

M;

i++)/*通过random函数产生一个数组*/

for(j=0;

j<

N;

j++)

a[i,j]=randObj.Next(1,100);

//产生随机数并赋值给数组

i++)/*按行输出数组*/

{Console.WriteLine();

//换行

j++)//本循环输出一行元素

a[i,j]);

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

elseoushu=oushu+a[i,j];

\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);

    }

{intk;

longresult;

k=Convert.ToInt32(textBox1.Text);

result=f(k);

textBox2.Text=Convert.ToString(result);

privatevoidbutton2_Click(objectsender,System.EventArgse)

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;

k;

n=n/10;

return((int)n%10);

{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’

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

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

privatevoidForm1_Load(objectsender,System.EventArgse)

stringSStr,DStr;

inti;

charc;

SStr=textBox1.Text;

DStr="

;

for(i=0;

SStr.Length;

{c=SStr[i];

if(c>

='

a'

&

&

c<

z'

||c>

A'

Z'

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

'

+3||c>

+3)

c=(char)(c-26);

DStr=DStr+c.ToString();

textBox2.Text=DStr;

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

privatevoidlabel3_Click(objectsender,System.EventArgse)

stringSStr1,DStr,delstr;

SStr1=textBox1.Text;

delstr=textBox2.Text;

DStr="

SStr1.Length;

if(SStr1.Substring(i,1)!

=delstr)

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

textBox3.Text=DStr;

第七章

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

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

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

namespaceD_7_1

{

publicclassvehicle

{

publicdoubleSpeed;

publicdoubleMaxSpeed;

publicdoubleWeight;

publicvirtualstringRun()

return("

一辆车在马路上奔跑。

publicvirtualstringStop()

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

publicclassbicycle:

vehicle

{publicdoublePrice;

publicbicycle(doubleS,doubleM,doubleW,doubleP)

Speed=S;

MaxSpeed=M;

Weight=W;

Price=P;

publicoverridestringRun()

{return("

一辆自行车在马路上奔跑。

);

publicoverridestringStop()

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

publicclasscar:

publicdoublePrice;

return("

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

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

publiccar(doubleS,doubleM,doubleW,doubleP)

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类的功能进行验证。

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'

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

Name=xm;

for(inti=0;

5;

Score[i]=cj[i];

publicdoubleCalAver()

{doublesum=0;

sum=sum+Score[i];

Aver=sum/5;

return(Aver);

{

RandomrandomObj=newRandom();

textBox4.Text="

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

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

"

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.编写一个冒泡法排序程序。

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

RandomrandObj=newRandom();

a[i]=randObj.Next(10,99);

/*产生随机数并赋值给数组元素*/

textBox1.Text="

i++)//输出整个数组

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

{inti,j,t;

//定义循环变量和交换用的临时变量

try

for(i=1;

=N;

i++)/*i表示轮次*/

for(j=0;

=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;

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

catch(IndexOutOfRangeExceptionex)

{textBox2.Text="

数组下标越界"

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

privatevoidbutton4_Click(objectsender,System.EventArgse)

op=4;

labe

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

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

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

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