第六次课程作业
第六次课程作业
要求1:学习C++界面编程,可以学QT、MFC或者VS,选择其一即可,用博客记录学习到的知识以及心得体会。
本来要去学MFC,结果安装MFC的时候出了点事故把vs搞崩了,害我换了个编译器,后来我去看了QT,感觉还行,但时间很赶,没学到什么。
附上QT的helloword:
要求2:用栈改进算法
这是我改后的代码:
double Mycount::calculateResult(double random1,double random2,double random3,double random4,int sign1,int sign2,int sign3){
double r1[6],r2[6],r[6]={random1,random2,random3,random4};
int rlen1=0,rlen2=0,s1[5],s2[5],slen1=0,slen2=0,s[5]={sign1,sign2,sign3};
r1[rlen1++]=r[0];
for(int i=0;i<3;i++){
r1[rlen1++]=r[i+1];
if(s[i]>=4){rlen1-=2;r1[rlen1]=qcount(r1[rlen1],r1[rlen1+1] ,s[i]);rlen1++;}
else s1[slen1++]=s[i];}
r2[rlen2++]=r1[0];
for(int i=0;i<slen1;i++){
r2[rlen2++]=r1[i+1];
if(s1[i]>=2){rlen2-=2;r2[rlen2]=qcount(r2[rlen2], r2[rlen2+1], s1[i]);rlen2++;}
else s2[slen2++]=s1[i];}
for(int i=0;i<slen2;i++){
r2[i+1]=qcount(r2[i], r2[i+1], s2[i]);}
return r2[slen2];
}
下面是刚开始的:
double Mycount::calculateResult(double random1,double random2,double random3,double random4,int sign1,int sign2,int sign3){
double count1,count2,count3,result;
if(sign1>3){count1=qcount(random1,random2,sign1);
if(sign2>3){count2=qcount(count1,random3,sign2);result=qcount(count2,random4,sign3);}
else{if(sign3>3){result=qcount(count1,qcount(random3,random4,sign3),sign2);}
else{if(sign2>1){result=qcount(qcount(count1,random3,sign2),random4,sign3);}
else{if(sign3>1){result=qcount(count1,qcount(random3,random4,sign3),sign2);}
else{result=qcount(qcount(count1,random3,sign2),random4,sign3);}}}}
}else{if(sign2>3){count2=qcount(random2,random3,sign2);
if(sign3>3){result=qcount(random1,qcount(count2,random4,sign3),sign1);}
else{if(sign1>1){result=qcount(qcount(random1,count2,sign1),random4,sign3);}
else{if(sign3>1){result=qcount(random1,qcount(count2,random4,sign3),sign1);}
else{result=qcount(qcount(random1,count2,sign1),random4,sign3);}}}
}else{if(sign3>3){count3=qcount(random3,random4,sign3);
if(sign1>1){result=qcount(qcount(random1,random2,sign1),count3,sign2);}
else{if(sign2>1){result=qcount(random1,qcount(random2,count3,sign2),sign1);}
else{result=qcount(qcount(random1,random2,sign1),count3,sign2);}}
}else{
//无括号运算(大于三代表存在括号的运算)
if(sign1>1){
count1=qcount(random1,random2,sign1);
if(sign2>1)result=qcount(qcount(count1,random3,sign2),random4,sign3);
else{
if(sign3>1) {
count3=qcount(random3,random4,sign3);
result=qcount(count1,count3,sign2);
}else {
result=qcount(qcount(count1,random3,sign2),random4,sign3);
}}
}else{
if(sign2>1){count2=qcount(random2,random3,sign2);
if(sign3>1){
result=qcount(random1,qcount(count2,random4,sign3),sign1);}
else{result=qcount(qcount(random1,count2,sign1),random4,sign3);}}
else{if(sign3>1){count3=qcount(random3,random4,sign3);result=qcount(qcount(random1,random2,sign1),count3,sign2);
}else{count1=qcount(random1,random2,sign1);result=qcount(qcount(count1,random3,sign2),random4,sign3);}}}}}}
return result;
}
用了很多个if else。看了头就晕,那时候的我竟然有毅力把它写下来,厉害了我的哥。
感想:
作业有点赶,没有学好或没有写好的地方,我后面会花些时间补。