您好,欢迎访问三七文档
1P90杨辉三角usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace_001{classProgram{constintN=10;staticvoidMain(string[]args){inti,j;int[,]a=newint[N,N];for(i=1;iN;i++){a[i,i]=1;a[i,1]=1;}for(i=3;iN;i++)for(j=2;j=i-1;j++)2a[i,j]=a[i-1,j-1]+a[i-1,j];for(i=1;iN;i++){for(j=1;j=i;j++)Console.Write({0,-2},a[i,j]);Console.WriteLine();Console.ReadKey();}}}}结果截图:3P101假设10个整数用一个一维数组存放,求其最大值和次大值int[]a=newint[10]{5,98,64,25,48,31,43,54,7,56};Array.Sort(a);Console.WriteLine(最大值{0},a[9]);Console.WriteLine(次大值{0},a[8]);Console.ReadKey();用一个二维数组存放5个考生4门功课的考试成绩,求每位考生的平均成绩。inti,jint[,]a=newint[5,4]{{84,95,47,54},{74,58,49,79},{87,47,486,68},{78,68,85,75},{98,74,58,67}};for(i=0;i=4;i++){intsum=0;for(j=0;j=3;j++)sum+=a[i,j];Console.WriteLine(平均成绩:{0},sum/4);5P113例题6usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace_111{classStudent{intno;stringname;intdeg1;intdeg2;intdeg3;staticintsum1=0;staticintsum2=0;staticintsum3=0;staticintsn=0;publicStudent(intn,stringna,intd1,intd2,6intd3){no=n;name=na;deg1=d1;deg2=d2;deg3=d3;sum1+=deg1;sum2+=deg2;sum3+=deg3;sn++;}publicvoiddisp(){Console.WriteLine(学号:{0}姓名:{1}语文:{2}数学:{3}英语:{4}平均分:{5:f},no,name,deg1,deg2,deg3,(double)(deg1+deg2+deg3)/3);}publicstaticdoubleavg1(){return(double)sum1/sn;}publicstaticdoubleavg2(){return(double)sum2/sn;}publicstaticdoubleavg3(){return(double)sum3/sn;}};classProgram7{staticvoidMain(string[]args){Students1=newStudent(1,王华,67,89,90);Students2=newStudent(2,李明,68,90,91);Students3=newStudent(3,张兵,69,89,92);Students4=newStudent(4,王超,70,92,93);Console.WriteLine(输出结果);s1.disp();s2.disp();s3.disp();s4.disp();Console.WriteLine(语文平均分:{0}数学平均分:{1}英语平均分:{2},Student.avg1(),Student.avg2(),Student.avg3());Console.ReadKey();}8}}//P115计算长方体的体积publicclassTpoint3{intx,y,h;publicintpx{get{returnx;}set{x=value;}}9publicintpy{get{returny;}set{y=value;}}publicintph{get{returnh;}set{h=value;}}}classProgram{staticvoidMain(string[]args){Tpoint3p=newTpoint3();p.px=3;p.py=4;p.ph=6;Console.WriteLine(x=({0}),p.px);10Console.WriteLine(y=({0}),p.py);Console.WriteLine(h=({0}),p.ph);Console.WriteLine(长方形的体积=({0}),p.px*p.py*p.ph);Console.ReadKey();}}}11课本115页,求长方体体积usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{publicclassTPoint3{intl,w,h;publicintpl{get{returnl;}set{l=value;}}publicintpw{get{returnw;}12set{w=value;}}publicintph{get{returnh;}set{h=value;}}};classProgram{staticvoidMain(string[]args){TPoint3p=newTPoint3();p.pl=3;p.pw=8;p.ph=9;Console.WriteLine(体积{0},p.pl*p.pw*p.ph);Console.ReadKey();}13}}截图如下usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication5{publicclassTpoint{publicintdisp(intx,inty,inth,refintvol){intv=0;14//s=2*(x*y+x*h+y*h);v=x*y*h;returnv;}};classProgram{staticvoidMain(string[]args){intvol,s=0;Tpointt=newTpoint();vol=t.disp(6,7,8,refs);Console.WriteLine(vol);Console.ReadKey();}}}截图如下15P1176.7.4代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication2{publicclassMyClass4{intnum=1;publicvoidaddnum(intnum1,refintnum2){num2=num+num1;}}classProgram16{staticvoidMain(string[]args){intx=0;MyClass4s=newMyClass4();s.addnum(5,refx);Console.WriteLine(x);Console.ReadKey();}}}结果截图:17P118代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication3{publicclassMyClass5{intnum=1;publicvoidaddnum(intnum1,outintnum2){num2=num+num1;}}classProgram{staticvoidMain(string[]args){intx;MyClass5s=newMyClass5();18s.addnum(5,outx);Console.WriteLine(x);Console.ReadKey();}}}结果截图:P125显示月份代码:usingSystem;usingSystem.Collections.Generic;19usingSystem.Linq;usingSystem.Text;namespace_123{classMonthCollection{string[]months={January,February,March,April,May,Jume,July,August,September,October,November,December};privateintGetMonth(stringtestMonth){inti=1;foreach(stringmonthinmonths){if(month==testMonth)returni;i++;}return-1;}publicintthis[stringmonth]20{get{return(GetMonth(month));}}}classProgram{staticvoidMain(string[]args){MonthCollectionyear=newMonthCollection();Console.WriteLine(January:{0}:,year[January]);Console.WriteLine(February:{0}:,year[February]);Console.WriteLine(March:{0}:,year[March]);Console.WriteLine(Marc:{0}:,year[abc]);Console.ReadKey();}}}结果截图:21P145第一题Proj6_14代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace_111{publicclassPerson{22publicintlegs1=2;protectedintweight1=48;publicintAdd10KG(){//weight1=weight1+10;returnweight1;}}publicclassAnimal{publicintlegs2=4;protectedintweight2=90;publicintAdd10KG(){//weight2=weight2+10;23returnweight2;}}classProgram{staticvoidMain(string[]args){Persona1=newPerson();Console.WriteLine(legs1={0},a1.legs1);Console.WriteLine(weight1={0},a1.Add10KG());Animala2=newAnimal();Console.WriteLine(legs2={0},a2.legs2);Console.WriteLine(weight2={0},a2.Add10KG());24Console.ReadKey();}}}结果截图:P127例题6.10代码:usingSystem;25usingSystem.Collections.Generic;u
本文标题:1C#编译实验报告
链接地址:https://www.777doc.com/doc-5499699 .html