1、要求编写成Windows应用程序,程序的运行界面如图所示 double a,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.编写一个进行加、减、乘、除四则运算的程序,要求:输入两个单精度数,然后输入一个运算符号,输出两个单精度数进行该运算后的结果。要求编写为控
2、制台程序。using System;class D_3_1 double op1,op2,result=0; char kind; 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;012=3,op1,kind,op2,result); 2.
3、兔子繁殖问题。设有一对新生的兔子,从第三个月开始它们每个月都生一对兔子,新生的兔子从第三个月开始又每个月生一对兔子。按此规律,并假定兔子没有死亡,20个月后共有多少兔子?要求编写为控制台应用程序。class D_3_2 int a,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个元素组成的一维数组逆序存放再输出。class D_4_1 int a=new int 1,2,3,4,5,6,7,8,
4、9,10;/定义数组并初始化 int i,j,t;反序之前:); for(i=0;10;,ai); i=0;j=9; while(ij) t=ai;ai=aj;aj=t; i+;j-; n反序之后:2.编写程序,统计4*5二维数组中奇数的个数和偶数的个数。class D_4_2 const int M=2; const int N=2; int ,a=new int M,N; int i,j,jishu,oushu; jishu=0;oushu=0; Random randObj=new Random();/生成随机数变量M;i+) /*通过random 函数产生一个数组*/ for(j=0;
5、j=a & cAZ) c=(char)(SStri+3);+3| c+3) c=(char)(c-26); DStr=DStr+c.ToString() ; textBox2.Text =DStr;2.编写一个应用程序用来从一个字符串中删除一个字符,程序的界面如图所示 private void label3_Click(object sender, System.EventArgs e) string SStr1,DStr,delstr; SStr1=textBox1.Text ; delstr=textBox2.Text ; DStr=SStr1.Length ; if (SStr1.Sub
6、string(i,1)!=delstr) DStr=DStr+SStr1.Substring(i,1); textBox3.Text =DStr;第七章1. 定义一个车辆(Vehicle)基类,具有Run、Stop等方法, 具有Speed(速度)、MaxSpeed(最大速度)、Weight(重量)等域。然后以该类为基类,派生出bicycle、car等类。并编程对派生类的功能进行验证。namespace D_7_1 public class vehicle public double Speed; public double MaxSpeed; public double Weight; pub
7、lic virtual string Run() return(一辆车在马路上奔跑。 public virtual string Stop()一辆车在马路上停了下来。 public class bicycle:vehicle public double Price; public bicycle(double S,double M,double W,double P) Speed=S; MaxSpeed=M; Weight=W; Price=P; public override string Run() return(一辆自行车在马路上奔跑。) ; public override string
8、 Stop()一辆自行车在马路上停了下来。 public class car: public double Price; return(一辆小汽车在马路上奔跑。一辆小汽车在马路上停了下来。 public car(double S,double M,double W,double P) vehicle v=new vehicle(); label1.Text =v.Run()+ +v.Stop(); bicycle bike=new bicycle(50,100,50,285); label2.Text =bike.Run()+ 速度:+bike.Speed.ToString() +bike.S
9、top (); car Car=new car(100,250,300,150000.0); label3.Text =Car.Run()+Car.Speed.ToString() +Car.Stop ();2.编写出一个通用的人员类(Person),该类具有姓名(Name),年龄(Age),性别(Sex)等域。然后通过对Person类的继承得到一个学生类(Student),该类能够存放学生的5门课的成绩,并能求出平均成绩,要求对该类构造函数进行重载,至少给出三个形式。最后编程对Student类的功能进行验证。namespace D_7_2 public class Person public
10、 string Name; public int Age; public char Sex; public class Student:Person public double Score; public double Aver; public Student(string xm,int nl,char xb) Name=xm; Age=nl; Sex=xb; Score=new double5; public Student() Name= Age=18; Sex=M public Student(string xm,int nl,char xb,double cj ) Name=xm; f
11、or(int i=0;5; Scorei=cji; public double CalAver() double sum=0; sum=sum+Scorei; Aver=sum/5; return(Aver); Random randomObj=new Random(); textBox4.Text = cji=randomObj.Next(0,101); textBox4.Text =textBox4.Text +cji.ToString()+, string xm=textBox1.Text ; int nl=Convert.ToInt32(textBox2.Text ); char xb
12、=Convert.ToChar(textBox3.Text ); Student S1=new Student(xm,nl,xb,cj); S1.CalAver(); textBox5.Text =S1.Aver.ToString();第八章1.编写一个冒泡法排序程序。要求在程序中能够捕获到数组下标越界的异常。 Random randObj=new Random(); ai=randObj.Next(10,99);/*产生随机数并赋值给数组元素*/ textBox1.Text=i+)/输出整个数组 textBox1.Text +=ai.ToString()+ int i,j,t;/定义循环变量
13、和交换用的临时变量 try for(i=1;=N;i+)/*i表示轮次*/ for(j=0;=N-i;j+) /*j表示每轮比较的次数*/ if(ajaj+1)/*如果后面的元素值小,则交换*/ t=aj;aj=aj+1;aj+1=t; textBox2.Text = for(i=0; textBox2.Text +=ai.ToString()+ catch(IndexOutOfRangeException ex) textBox2.Text =数组下标越界 2、编写一个计算机应用程序,要求在程序中能够捕获到被0除的异常与算术运算溢出的异常。 private void button4_Click(object sender, System.EventArgs e) op=4;labe
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1