vc++ 2.docx
- 文档编号:11482129
- 上传时间:2023-03-01
- 格式:DOCX
- 页数:18
- 大小:17.19KB
vc++ 2.docx
《vc++ 2.docx》由会员分享,可在线阅读,更多相关《vc++ 2.docx(18页珍藏版)》请在冰豆网上搜索。
vc++2
找规律:
四位数6174
xiaojing2011/3/1914:
37:
30
任意输入一个四位数,其每一位不能完全相同(如1111),将组成该数的各位数字重新排序,组成一个最大数和一个最小数,然后使它们的相减的差仍为自然数,重复上述运算,观察并总结最后结果。
#include
usingnamespacestd;
intcin_number()/*用于数据的输入*/
{
inta,b,c,d,x;
xj:
cin>>x;
a=x/1000;
b=(x-a*1000)/100;
c=(x-a*1000-b*100)/10;
d=x%10;
if((x>=10000||x<=999)||(a==b&&b==c&&c==d))
{
cout<<"cinagain"< gotoxj; } returnx; } voidmax(inttmp[])/*对数组进行排序*/ { intmax; max=tmp[0]; for(inti=0;i<3;i++)/*4个数进行简单选择排序*/ { intk=i; for(intj=k+1;j<4;j++) { if(tmp[j]>tmp[k]) {max=tmp[j]; tmp[j]=tmp[k]; tmp[k]=max;} } } } intcha(intb[])/*求差值*/ { intx,y,z; x=b[0]*1000+b[1]*100+b[2]*10+b[3];/*x是四位组合的最大数*/ if(b[3]! =0)/*四位数最高位不能为0*/ y=b[3]*1000+b[2]*100+b[1]*10+b[0];/*x是四位组合的最小数*/ else y=b[2]*1000+b[1]*10+b[0]; z=x-y; returnz; } intmain() { intx; x=cin_number(); do { inttmp[4]; inta,b,c,d,result; a=x/1000; b=(x-a*1000)/100; c=(x-a*1000-b*100)/10; d=x%10; tmp[0]=a;tmp[1]=b;tmp[2]=c;tmp[3]=d; max(tmp); result=cha(tmp); cout<<"result="< cout< x=result; system("pause"); }while (1); return0; } 3好多人参加比赛,统计成绩。 xiaojing2011/3/1914: 36: 29 有7个评委,每个评委都要给选手打分,现在要求去掉一个最高分和去掉一个最低分,在算出平均分。 结果精确到小数点后两位。 输入 测试数据包括多个实例。 每组包括7个实数,代表评委们对该选手的评分。 紧接着是选手的名字,名字的长度不超过30个字符。 输入直到文件结束。 输出 算出每为选手名字和最终得分,结果保留两位小数。 样例输入 1010101010109xiaoyuanwang 0000000beast 样例输出 Xiaoyuanwang10.00 Beast0.00 源代码: #include"stdafx.h" #include #include usingnamespacestd; classhappy { public: happy() { cout<<"请输入7个数据数据: "; for(inti=0;i<7;i++) cin>>a[i]; cout<<"请输入被评议人姓名: "; /*for(intj=0;j<=30;j++) cin>>s1[j];*/ cin>>s1; } voidpaixu() { floattmp=0.0; for(inti=0;i<6;i++) { for(intj=0;j<6-i;j++) if(a[j]>a[j+1]) { tmp=a[j]; a[j]=a[j+1]; a[j+1]=tmp; } } a[0]=0.0; a[6]=0.0; } voidoutput() { floatsum1=0.0; for(inti=0;i<7;i++) sum1=sum1+a[i]; sum1=(sum1*1.0)/7; cout< } private: floata[7]; strings1; }; intmain() { intn; while((cin>>n)&&n! =EOF) { happyh; h.paixu(); h.output(); } return0; } 、打印以下矩阵: xiaojing2011/3/1914: 36: 01 *** ********* *************** ********************** *************** ********* *** *** ********* *************** ********************** *************** ********* *** *** ********* *************** ********************** *************** ********* *** #include usingnamespacestd; intmain() { inth,tmp,m,n; cout<<"请输入一个奇数(菱形高度): "< cin>>h; cout<<"请输入一个数(菱形矩阵高度): "< cin>>m; cout<<"请输入一个数(菱形矩阵宽度): "< cin>>n; tmp=(h+1)/2; for(intt=0;t { for(inti=0;i { for(intl=0;l { for(intj=tmp-i-1;j>=0;j--) { cout<<""; } for(intk=1;k<=(i*2+1);k++) { cout<<"*"; } for(j=tmp-i-1;j>=0;j--) { cout<<""; } } cout< } for(i=tmp-1;i>=0;i--) { for(intl=0;l { for(intm=0;m<=tmp-i;m++) { cout<<""; } for(intn=0;n<=2*(i-1);n++) { cout<<"*"; } for(m=0;m<=tmp-i;m++) { cout<<""; } } cout< } } return0; } (2) 用类来实现: #include usingnamespacestd; classlingxingjuzhen { public: lingxingjuzhen() { cout<<"请输入一个奇数(菱形高度): "< cin>>h; cout<<"请输入一个数(菱形矩阵高度): "< cin>>m; cout<<"请输入一个数(菱形矩阵宽度): "< cin>>n; } voidshixian() { tmp=(h+1)/2; for(intt=0;t { for(inti=0;i { for(intl=0;l { for(intj=tmp-i-1;j>=0;j--) { cout<<""; } for(intk=1;k<=(i*2+1);k++) { cout<<"*"; } for(j=tmp-i-1;j>=0;j--) { cout<<""; } } cout< } for(i=tmp-1;i>=0;i--) { for(intl=0;l { for(intm=0;m<=tmp-i;m++) { cout<<""; } for(intn=0;n<=2*(i-1);n++) { cout<<"*"; } for(m=0;m<=tmp-i;m++) { cout<<""; } } cout< } } } private: inth,tmp,m,n; }; intmain() { intn; while((cin>>n)&&n) { lingxingjuzhenl1; l1.shixian(); } return0; } 标题: Re2、打印以下矩阵: xiaojing2011/3/1914: 39: 55 是这个图形 *** ********* *************** ********************** *************** ********* *** *** ********* *************** ********************** *************** ********* *** *** ********* *************** ********************** *************** ********* *** 链表的实现 xiaojing2011/3/1914: 35: 09 #include"stdio.h" #include"stdlib.h" #include //usingnamespacestd; #defineNULL0 #defineLENsizeof(structstudent) structstudent { longnum; floatscore; structstudent*next; }; intn; structstudent*creat()//creat { structstudent*head; structstudent*p1,*p2; n=0; p1=p2=(structstudent*)malloc(LEN); scanf("%d,%f",&p1->num,&p2->score); head=NULL; while(p1->num! =0) { n=n+1; if(n==1)head=p1; elsep2->next=p1; p2=p1; p1=(structstudent*)malloc(LEN); scanf("%ld,%f",&p1->num,&p1->score); } p2->next=NULL; return(head); } voidprint(structstudent*head)//print { structstudent*p; printf("\nNow,These%drecordsare: \n",n); p=head; if(head! =NULL) do { printf("%ld,%5.1f\n",p->num,p->score); p=p->next; }while(p! =NULL); } structstudent*del(structstudent*head,longnum)//del { structstudent*p1,*p2; if(head==NULL) { printf("\nlistnul! \n"); gotoend; } p1=head; while(num! =p1->num&&p1->next! =NULL) { p2=p1; p1=p1->next; } if(num==p1->num) { if(p1==head)head=p1->next; else p2->next=p1->next; printf("delete: %ld\n",num); n=n-1; } elseprintf("%ldnotbeenfound! \n",num); end: return(head); } structstudent*insert(structstudent*head,structstudent*stud)//insert { structstudent*p0,*p1,*p2; p1=head; p0=stud; if(head==NULL) { head=p0; p0->next=NULL; } else { while((p0->num>p1->num)&&(p1->next! =NULL)) { p2=p1; p1=p1->next; } if(p0->num<=p1->num) { if(head==p1)head=p0; else p2->next=p0; p0->next=p1; } else { p1->next=p0; p0->next=NULL; } } n=n+1; return(head); } intmain() { structstudent*head,*stu; longdel_num; printf("inputrecodes: \n"); head=creat(); print(head); printf("\ninputthedeletednumber: "); scanf("%ld",&del_num); while(del_num! =0) { head=del(head,del_num); print(head); printf("inputthedeletedrescord: "); scanf("%ld",&del_num); } printf("inputtheinsertedrescord: "); stu=(structstudent*)malloc(LEN); scanf("%ld,%f",&stu->num,&stu->score); while(stu->num! =0) { head=insert(head,stu); print(head); printf("inputtheinsertedrescord: "); stu=(structstudent*)malloc(LEN); scanf("%ld,%f",&stu->num,&stu->score); } return0; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- vc+ vc