您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > C#-实验一:设计一个简单的密码验证程序
1.创建C#控制台应用程序。设计一个简单的密码验证程序,若密码正确,则显示“欢迎进入本系统!”,否则显示“密码输入错误,请重新输入!”。若连续三次密码输入错误,则显示“对不起,超过最多输入次数,取消服务!”,程序退出。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){inti=0;stringmima=123321;boolk=true;Console.WriteLine();Console.WriteLine(》》》》欢迎使用本系统《《《《\n\n);Console.WriteLine(请输入您的服务秘密);while(k){stringget=Console.ReadLine();if(get!=mima){i++;if(i==3){Console.WriteLine(对不起,您输入的密码错误次数已经超过三次,\n\n已取消服务,请按任意键结束!!);Console.ReadLine();break;}elseConsole.WriteLine(对不起,您输入的密码有误,请重新输入!);}else{Console.WriteLine(欢迎进入本系统!!);Console.ReadLine();break;}}}}}2.创建一个点Point类,属性包括横坐标、纵坐标。要求能够完成点的移动操作、求两点距离操作,并利用运算符重载,对两个点进行比较(相等和不等)依据是两坐标点相等指它们横坐标和纵坐标分别相等。编写一个测试程序对产生的类的功能进行验证。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace_1_2{classpoint{publicdoublex,y;publicpoint(doublea,doubleb){x=a;y=b;}publicvoidmove(doublea,doubleb){x=x+a;y=y+b;}publicstaticbooloperator==(pointa,pointb){if((a.x==b.x)&&(a.y==b.y))returntrue;elsereturnfalse;}publicstaticbooloperator!=(pointa,pointb){if((a.x!=b.x)||(a.y!=b.y))returntrue;elsereturnfalse;}publicdoubledistance(pointa,pointb){returnMath.Sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}}classProgram{staticvoidMain(){pointa=newpoint(1,1);pointb=newpoint(2,2);Console.WriteLine(a点的坐标:({0},{1}),a.x,a.y);Console.WriteLine(b点的坐标:({0},{1}),b.x,b.y);Console.WriteLine(现在将对a点的坐标进行移动2和3,请按enter键开始移动!);//stringget1=Console.ReadLine();//Console.WriteLine(现在将对a点的纵坐标进行移动,请输入您要移动的Y坐标数);//stringget2=Console.ReadLine();//a.move((double)get1,(double)get2);a.move(2,3);Console.ReadLine();Console.WriteLine(移动后a点得坐标是:({0},{1}),a.x,a.y);Console.WriteLine(a点坐标移动后与b点坐标的距离是:{0},a.distance(a,b));if(a==b)Console.WriteLine(a点和b点相等\n);elseConsole.WriteLine(a点和b点不相等\n);Console.WriteLine(现将对b点坐标分别移动3和4,按enter确认!);b.move(1,2);Console.ReadLine();Console.WriteLine(移动后b点得坐标是:({0},{1}),b.x,b.y);//Console.WriteLine(b点坐标移动后与a点坐标的距离是:{0},b.distance(a,b));if(a==b)Console.WriteLine(a点和b点相等);elseConsole.WriteLine(a点和b点不相等);Console.ReadLine();}}}3.定义一个顺序表SqlList类,要求能够完成在顺序表中插入元素和删除元素,确定元素在顺序表中位置,检索元素,清空表,判断表是否为空等操作。编写一个测试程序进行验证。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceshiyan13{classSqlList{privateint[]list;privateintlen;publicSqlList(int[]a,intb){list=a;len=b;}publicvoidprint(){//Console.WriteLine(顺序表序列是:);for(inti=0;ilen;i++){Console.Write({0}\0,list[i]);}}publicboolinsert(intc,intd){inttemp=0,i=d-1;for(;ilen;i++){temp=list[i];list[i]=c;c=temp;}if(dlen||d1){Console.WriteLine(\n对不起,您的插入位置有误,请重新输入插入位置!);returnfalse;}returntrue;}publicbooldelete(inte){intj=e;for(;jlen;j++)list[j-1]=list[j];len--;if(elen||e1){Console.WriteLine(\n对不起,没有您要删除的元素,请重新输入您要删除的位置!\n);returnfalse;}returntrue;}publicintlookup(inta){inti=0;for(i=0;ilen;i++)if(list[i]==a)break;if(i==len)return-1;elsereturn(i+1);}publicintreserch(inta){inti=0,j=0;for(;ilen;i++)if(list[i]==a)j++;returnj;}publicvoidclear(){len=0;}publicvoidshow(){if(len==0)Console.WriteLine(顺序表已清空!\n);elseConsole.WriteLine(顺序表未清空!\n);}}classProgram{staticvoidMain(string[]args){int[]a={1,2,3,4,5,6,7,8,9};intb=9;SqlListlist=newSqlList(a,b);Console.WriteLine(顺序表初始化为:);list.print();list.insert(4,6);Console.WriteLine(\n\n在顺序表的第6个数据前插入数据4后为:);list.print();Console.WriteLine(\n\n在顺序表检索数据3,得到的个数:{0},list.reserch(3));Console.WriteLine(\n\n在顺序表检索数据4,得到的个数:{0},list.reserch(4));Console.WriteLine(\n\n在顺序表找到第一个数据3所在位置:{0},list.lookup(3));Console.WriteLine(\n\n在顺序表找到第一个数据4所在位置:{0},list.lookup(4));list.delete(3);Console.WriteLine(\n\n删除顺序表的第3个数据:);list.print();Console.WriteLine(\n\n判断顺序表是否为空:);list.show();list.clear();Console.WriteLine(\n清空顺序表后判断:);list.show();Console.Read();}}}4.定义一个shape抽象类,利用它作为基类派生出Rectangle、Circle等具体形状类,已知具体形状类均具有两个方法GetArea和GetPerim,分别用来求形状的面积和周长。最后编写一个测试程序对产生的类的功能进行验证。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceshiyan14{publicabstractclassShape{publicdoubleGetArea(){return0;}publicdoubleGetPerim(){return0;}}publicclassCircle:Shape{privatedoubler;publicCircle(doublea){r=a;}publicnewdoubleGetArea(){returnMath.PI*r*r;}publicnewdoubleGetPerim(){returnMath.PI*2*r;}}publicclassRectangle:Shape{privatedoublea,b;publicRectangle(doublec,doubled){a=c;b=d;}publicnewdoubleGetArea(){returna*b;}publicnewdoubleGetPerim(){return(2*(a+b));}}classProgram{staticvoidMain(string[]args){Circlestr=newCircle(3);Rectanglech=newRectangle(5,10);Console.WriteLine(\n\0圆的半径初始化为:R=3\n);Console.WriteLine(=圆的面积为:{0}\n,str.GetArea());Console.WriteLine(=圆的周长为:{0}\n,str.GetPerim());Console.WriteLine(\n\0初始化长方形长为:10,宽为:5\n);Console.WriteLine(=长方形面积:{0}\n,ch.GetArea());Console.WriteLine(=长方形周长:{0}\n,ch.GetPerim());Console.Read();}}}5.编程实现一个模拟闹铃的程序,具有闹铃、继续闹铃、打会盹儿,停止闹铃的功能。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceshiyan15{publicclassclock{System.Media.SoundPlayermusic;publicvoidalarm(){music=newSystem.Media.SoundPlayer(Track06.wav);music.Play();}publicvoidgoon(){music=
本文标题:C#-实验一:设计一个简单的密码验证程序
链接地址:https://www.777doc.com/doc-4699675 .html