标签:
一、题目
在四则运算二的基础上,选择一个方向进行拓展,我选择的是增加了答题模块
二、设计思路
三、程序源代码
1 // sizeyunsuan.cpp : Defines the entry point for the console application. 2 // 3 4 #include "stdafx.h" 5 #include"time.h" 6 #include "iomanip" 7 #include"iostream" 8 #include"String" 9 using namespace std; 10 /*确定运算符*/ 11 char suanfu(int n) 12 { 13 switch(n) 14 { 15 case 0: 16 return ‘+‘; 17 case 1: 18 return ‘-‘; 19 case 2: 20 return ‘*‘; 21 case 3: 22 return ‘/‘; 23 } 24 } 25 26 /*结果判断函数*/ 27 int judge(float jsjg,float sjjg,int count) 28 { 29 while(!(cin>>jsjg)) 30 { 31 cout<<"输入错误,请重新输入:"; 32 cin.clear(); 33 cin.sync(); 34 } 35 if(sjjg==jsjg) //检查用户输入的答案 36 { 37 count++; 38 } 39 else 40 { 41 cout<<"错误"<<endl; 42 } 43 return count; 44 } 45 /*运算调整函数*/ 46 int yunsuan(int num1,int num2,int count,string s,string l) 47 { 48 int temp; 49 float jsjg=0; 50 float sjjg=0; 51 int operators=0; 52 num1=rand()%100; 53 num2=rand()%100; 54 if(s=="Y"||s=="y") 55 { 56 operators=rand()%4; 57 } 58 else 59 { 60 operators=rand()%2; 61 } 62 if(operators==1) //避免结果出现负数 63 { 64 if(l=="N"||l=="n") 65 { 66 if(num1<num2) 67 { 68 temp=num2; 69 num2=num1; 70 num1=temp; 71 } 72 } 73 } 74 else if(operators==3) //为了避免除不尽的情况,使除法运算调整为都能整除的。 75 { 76 num1=num2*(rand()%10); 77 } 78 switch(operators) //自动计算出正确的答案,便于检查用户输入的对错 79 { 80 case 0: 81 sjjg=num1+num2; 82 break; 83 case 1: 84 sjjg=num1-num2; 85 break; 86 case 2: 87 sjjg=num1*num2; 88 break; 89 case 3: 90 sjjg=num1/num2; 91 } 92 93 cout<<num1<<suanfu(operators)<<num2<<"="; 94 count=judge(jsjg,sjjg,count); 95 return count; 96 } 97 98 99 /*主函数*/ 100 int main() 101 { 102 int num1=0; 103 int num2=0; 104 int count=0; 105 string plus,add; 106 string judge; 107 int m; 108 cout<<"请输入题目数量:"; 109 while(!(cin>>m)) 110 { 111 cout<<"输入错误,请重新输入:"; 112 cin.clear(); 113 cin.sync(); 114 } 115 cout<<endl; 116 cout<<"是否有乘除法:"; 117 cin>>plus; 118 cout<<endl; 119 while(plus!="Y"&&plus!="y"&&plus!="N"&&plus!="n") 120 { 121 cout<<"输入错误,请重新输入(Y/N):"; 122 cin>>plus; 123 cout<<endl; 124 } 125 126 cout<<"是否加减出现负数:"; 127 cin>>add; 128 while(add!="Y"&&add!="y"&&add!="N"&&add!="n") 129 { 130 cout<<"输入错误,请重新输入(Y/N):"; 131 cin>>add; 132 cout<<endl; 133 } 134 cout<<endl; 135 cout<<"例子:13+15=28"<<endl; 136 cout<<endl; 137 srand((unsigned)time(NULL)); 138 for(int i=0;i<m;i++) 139 { 140 cout<<i+1<<"、"; 141 count=yunsuan(num1,num2,count,plus,add); 142 } 143 cout<<endl; 144 cout<<"正确:"<<count<<endl; 145 cout<<endl; 146 cout<<"错误:"<<m-count<<endl; 147 cout<<endl; 148 cout<<"正确率: "<<count<<"/"<<m<<"="<<fixed<<setprecision(2)<<float(count)/m*100<<"%"<<endl; //输出统计的数据 149 cout<<endl; 150 cout<<"是否继续(Y/N)"; 151 cin>>judge; 152 cout<<endl; 153 while(judge!="Y"&&judge!="y"&&judge!="N"&&judge!="n") 154 { 155 cout<<"输入错误,请重新输入(Y/N):"; 156 cin>>judge; 157 cout<<endl; 158 } 159 if(judge=="Y"||judge=="y") 160 { 161 main(); 162 } 163 else 164 { 165 return 0; 166 } 167 }
四、程序运行结果
五、实验结果分析
四则运算的作业已经做了三次,每次的题目都有一些拓展和改进,我所认识到的并不是说程序实现的怎么样,而是程序从开始到结束,是一个不断完善和改进的过程,每一次的拓展,实际上是对以前不足之处的改进,使之更加符合我们的需要,从程序到软件,都要经历开始,分析,实现,完善,改进,测试等方面。要做的不仅仅是把结果运行出来,而是要注重过程和思路
六、psp0级表格
项目计划总结:
周活动总结表
姓名:张世通 日期:3/21
日期 任务 |
听课 |
编写程序 |
阅读课本 |
准备考试 |
|
|
日总计 |
周日 |
|
|
|
|
|
|
|
周一 |
|
|
60 |
|
|
|
60 |
周二 |
100 |
|
|
|
|
|
100 |
周三 |
|
120 |
|
|
|
|
120 |
周四 |
|
|
60 |
|
|
|
60 |
周五 |
100 |
|
|
|
|
|
100 |
周六 |
|
120 |
|
|
|
|
120 |
周总结 |
200 |
240 |
120 |
|
|
|
560 |
阶段时间和效率 周数(上一次周活动表的周数+1):2
不包括上一周在内的累计时间
总计 |
200 |
240 |
120 |
|
|
|
560 |
平均 |
200 |
240 |
120 |
|
|
|
560 |
最大 |
200 |
240 |
120 |
|
|
|
560 |
最小 |
200 |
240 |
120 |
|
|
|
560 |
以前各周的累计时间
总计 |
200 |
160 |
70 |
|
|
|
430 |
平均 |
200 |
160 |
70 |
|
|
|
430 |
最大 |
200 |
160 |
70 |
|
|
|
430 |
最小 |
200 |
160 |
70 |
|
|
|
430 |
时间记录表:
学生 张世通 日期 3/21
教师 王建民 课程 PSP
日期 |
开始时间 |
结束时间 |
中断时间 |
净时间 |
活动 |
备注 |
3.18 |
19:25 |
21:25 |
|
120 |
课堂作业求最大子数组的和 |
|
3.21 |
08:30 |
10:30 |
|
120 |
课堂作业四则运算 |
|
三、缺陷记录日志: | ||||||
学生 张世通 | ||||||
日期 2015年3月14日 | ||||||
教员 王建民 | ||||||
程序号 01 | ||||||
日期 | 编号 | 类型 | 引入阶段 | 排除阶段 | 修复时间 | 修复缺陷 |
3.18 | 1 | 3 | 编码 | 编码 | 10min | |
描述:定义动态数组出错,int *father=new int[length] | ||||||
3.18 | 2 | 4 | 编码 | 调试 | 5min | |
描述:使用了sizeof(father),没有意识到sizeof(参数)参数应该是数据类型,而不是指针,求长度出错 | ||||||
3.21 | 3 | 3 | 编码 | 调试 | 20min | |
描述:参数传递问题,主函数定义的参数在调用函数中没有正确返回 | ||||||
标签:
原文地址:http://www.cnblogs.com/zhshto/p/4356158.html