软件工程第二次作业——四则运算结对编程3.0版本(最终版本)

姓名:杨然 学号:1500802102
博客园地址:https://home.cnblogs.com/u/yang-r/
随文地址:http://www.cnblogs.com/yang-r/p/6837459.html
姓名:马柯宇 学号:1500802096
博客园地址:http://www.cnblogs.com/mkyz/
随文地址:http://www.cnblogs.com/mkyz/p/6837701.html
coding代码地址:
https://coding.net/u/Apiciallover/p/sizeyunsuan-A/git/tree/master/

  • 界面:

  • 整数计算功能(加减乘除):


整数计算功能代码:
z=true;

for(int p=0;p<100;p++)
	str[p]=_T("");
for(int p=0;p<100;p++)
{
  int i=(int)rand()%10;
  int j=(int)rand()%9+1;
  int k=(int)rand()%100/25;
  CString str0("");
  switch(k)
  {
    case 0:
      a[p]=i+j;
	  str0+=_T("+");
      break;
    case 1:
      a[p]=i-j;
	  str0+=_T("-");
      break;
    case 2:
      a[p]=i*j;
	   str0+=_T("*");
      break;
    case 3:
      try
      {
        a[p]=i/j;
		 str0+=_T("/");
      }
      catch(...)
     {
        p--;
     }

  }        
  
 CString stri((char)(i+48));
 CString strj((char)(j+48));
 str[p]+=stri+=str0+=strj;
  • 真分数计算功能(加减乘除):


真分数计算功能代码:

for(int p=0;p<100;p++)
str2[p]=_T("");
for(int p=0;p<100;p++)
{
int i=(int)rand()%10;
int j=(int)rand()%10;
CString strk1("/");
CString strk2("");
CString strk3("/");
CString strk4("(");
CString strk5(")");
while(j0||i>=j)
{
i=(int)rand()%10;
j=(int)rand()%10;
}
int x=(int)rand()%10;
int y=(int)rand()%10;
while(y
0||x>=y)
{
x=(int)rand()%10;
y=(int)rand()%10;
}
int k=(int)rand()%100/25;
switch(k)
{
case 0:

		    strk2+=_T(")+(");
		
            b[p][0]=i*y+x*j;
            b[p][1]=j*y;
            break;
        case 1:
        
		    strk2+=_T(")-(");
			
            b[p][0]=i*y-x*j;
            b[p][1]=j*y;
            break;
        case 2:
          
		    strk2+=_T(")*(");
		
            b[p][0]=i*x;
            b[p][1]=j*y;
            break;
        case 3:
            b[p][0]=i*y;
            b[p][1]=j*x;
         
		    strk2+=_T(")/(");
		
        }
        
      CString stri((char)(i+48));
 CString strj((char)(j+48));
 CString strx((char)(x+48));
 CString stry((char)(y+48));
 str2[p]+=strk4+=stri+=strk1+=strj+=strk2+=strx+=strk3+=stry+=strk5;
 
}
  • 清屏:

清屏代码:

	CString str("0");
    GetDlgItem(IDC_STATIC)->SetWindowText(str);
	GetDlgItem(DAAN)->SetWindowText(str);
    GetDlgItem(sdfgsdgs)->SetWindowText(str);
    GetDlgItem(truejieguo)->SetWindowText(str);
	GetDlgItem(shijian)->SetWindowText(str);
  • 约分功能:

约分功能代码:

int mm=2;
if(b[n-1][0]>b[n-1][1])
{ mm=b[n-1][1];
}
else
mm=b[n-1][0];
for(int i=2;i<=mm||i<=(-mm);i++)
{if(b[n-1][1]%i0&&b[n-1][0]%i0)
{
b[n-1][0]=b[n-1][0]/i;
b[n-1][1]=b[n-1][1]/i;
i--;
}
}

  • 判断对错功能:

代码:(判断对错和统计出题数以及正确题数)

UpdateData(TRUE);

CString strm[100],strn[100];
strm[n].Format(_T("%d"),n);
if(z)
{
	GetDlgItem(shumu)->SetWindowText(strm[n]);
	int i = _ttoi(o);
	if(i==a[n-1])
	{
		GetDlgItem(sdfgsdgs)->SetWindowText(_T("回答正确"));
		 x=x+1;
	 strn[n].Format(_T("%d"),x);
   GetDlgItem(zhengque)->SetWindowText(strn[n]);

	}
	else
	{
		GetDlgItem(sdfgsdgs)->SetWindowText(_T("回答错误"));
		 strn[n].Format(_T("%d"),x);
  GetDlgItem(zhengque)->SetWindowText(strn[n]);
	
	}
}


else
{
	GetDlgItem(shumu)->SetWindowText(strm[n]);
	int x1,y1;
	CString z1;
	CString m1;
	int i=0;
	while(o.GetAt(i)!='/'&& o.GetAt(i)!='\0')
	{
		z1+=o.GetAt(i);
		i++;
	}
	if(o.GetAt(i)=='\0'||o.GetAt(i+1)=='\0')
	{
		GetDlgItem(IDC_EDIT5)->SetWindowText(_T("请重新输入"));
	}
	else
	{
		x1=_ttoi(z1);
		i++;
		while(o.GetAt(i)!='\0')
		{
			m1+=o.GetAt(i);
			i++;
		}
		y1=_ttoi(m1);
		if(x1==b[n-1][0]&&y1==b[n-1][1])
		{
			GetDlgItem(sdfgsdgs)->SetWindowText(_T("回答正确"));
			  x=x+1;
	 strn[n].Format(_T("%d"),x);
	 GetDlgItem(zhengque)->SetWindowText(strn[n]);
		}
		else
		{
			GetDlgItem(sdfgsdgs)->SetWindowText(_T("回答错误"));
			strn[n].Format(_T("%d"),x);
  GetDlgItem(zhengque)->SetWindowText(strn[n]);

		
		}
	}


}
  • 统计用户练习题数目以及正确数量:

  • 倒计时:
    (每个题目必须在20秒内完成,若完不成则自动出下一题并得0分记计算错误。)
    倒计时代码:

void CsizeyunsuanDlg::OnBnClickedButton7()
{

	SetTimer(1,1000,NULL);

}
void CsizeyunsuanDlg::OnTimer(UINT nIDEvent)
{
i--;
strt[i].Format(_T("%d"),i);
CString strt(strt[i]);
GetDlgItem(shijian)->SetWindowText(strt);
if(i==0)
{i=20;
OnBnClickedButton5();
}

}


输出正确结果代码:

CString strz;//输出正确结果
CString strz1;
CString strz2;
if(z)
{
	
	strz.Format(_T("%d"),a[n-1]);
	 GetDlgItem(truejieguo)->SetWindowText(strz);
}
else
{
	strz1.Format(_T("%d"),b[n-1][0]);
	strz1+=_T("/");
	strz2.Format(_T("%d"),b[n-1][1]);
	strz+=strz1+=strz2;
	 GetDlgItem(truejieguo)->SetWindowText(strz);
}
  • 结对编程照片

  • 心得体会
    通过这次结对编程我们互相学习到了很多,对于同一个问题有不同的思路和见解,使得我们的整体的思路拓宽。而且结对编程最大的好处是轮换充当监督者,这样在打代码的过程中能够更加快速的发现错误并及时改正。会经常出现意见不同的时候,需要两个人协商着来,统一意见然后做出修改。
posted @ 2017-05-10 19:28  MicrosoftTeam  阅读(196)  评论(0编辑  收藏  举报