zoukankan      html  css  js  c++  java
  • 结对编程--四则运算

    代码地址

    题目描述

    我们在个人作业1中,用各种语言实现了一个命令行的四则运算小程序。进一步,本次要求把这个程序做成GUI(可以是Windows PC 上的,也可以是Mac、Linux,web,手机上的),成为一个有基本功能、一定价值的程序。在下面的功能需求中实现两个:
    
    记录用户的对错总数,程序退出再启动的时候,能把以前的对错数量保存并在此基础上增量计算。
    有计时功能,能显示用户开始答题后的消耗时间。
    界面支持中文简体/中文繁体/英语,用户可以选择一种;
    

    结对分工

    109 王钧任    
    101 曾丽君
    

    思维导图

    主要代码实现

    随机生成题目的代码就用上次的稍加修改就可以了。

    判断答案正确并输出:

    char * edaanpanduan(char daan[],char * shuru,char * timu)
    {
    	static char panduanjieguo[30];
    	FILE * in ,* out,* cuoti;
    
    	in=fopen("leijitimushu.txt","r");
    	fscanf(in,"%d,%d",&eright,&ewrong);
    	fclose(in);
    
    
    	if(strcmp(shuru,edaan)==0)
    	{
    		strcpy(panduanjieguo,"Right!");
    		eright++;
    		
    	}
    	else
    	{
    		strcpy(panduanjieguo,"wrong!");
    		strcat(panduanjieguo,"Answer is:");
    		strcat(panduanjieguo,edaan);
    		ewrong++;
    		cuoti=fopen("cuotiji.txt","a");
    		fprintf(cuoti,"%s=%s  wrong!Right answer is %s
    ",timu,shuru,edaan);
    		fclose(cuoti);
    	}
    
    	out=fopen("leijitimushu.txt","w");
    	fprintf(out,"%d,%d",eright,ewrong);
    	fclose(out);
    
    
    
    	return panduanjieguo;
    }
    

    实现生成题目的按钮触发事件:

    void c1::OnButton1() 
    {
    	// TODO: Add your control notification handler code here
    	UpdateData();
    	m_etimu=etimushengcheng();
    	UpdateData(false);
    	estart=clock();
    }
    

    实现提交答案并判读输出的按钮:

    void c1::OnButton2() 
    {
    	// TODO: Add your control notification handler code here
    	extern char daan[10];
    	char s[20];
    	UpdateData();
    	char *shuru =m_eshuru.GetBuffer(m_eshuru.GetLength());
    	char *timu=m_etimu.GetBuffer(m_etimu.GetLength());
    	m_edaan=edaanpanduan(daan,shuru,timu);
    	efinish= clock();
    	eduration =(double)(efinish-estart)/CLOCKS_PER_SEC;
    	sprintf(s,"%g",eduration);
    	m_eyongshi=s;
    	itoa(eright,s,10);
    	m_eright=s;
    	itoa(ewrong,s,10);
    	m_ewrong=s;
    	UpdateData(false);
    }
    

    按下按钮打开错题集文本:

    void c1::OnButton3() 
    {
    
    	::WinExec("notepad.exe cuotiji.txt",SW_SHOW);
    }
    

    功能实现截图:


    小结

    1:与队友第二次合作,但是这次的合作没有那么顺利。
    2:结对编程中,代码的规范还是挺重要的!

    PSP

  • 相关阅读:
    sqlserver表结构导出excel格式
    c#对象深复制demo
    aspose.cells导出Demo
    复制表结构数据至另一数据库
    C#安全类型转换基于convert
    c# winform devexpress TreeList过滤和绑定
    万能分页存储过程
    WebSocket简单使用
    本地搭建持续集成(AzureDevops)
    centos 7 安装nginx并启动(笔记)
  • 原文地址:https://www.cnblogs.com/wjunren/p/6548077.html
Copyright © 2011-2022 走看看