一.实验题目
四则运算扩展----能接受答案并判断对错然后给出成绩。
二.实验思路
在每次输出算式后面输入答案,然后判断对错,对则统计。
稍微优化了一下界面。
三.代码
1 // 12345.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include"iostream" 6 #include<stdlib.h> 7 #include<time.h> 8 #include<math.h> 9 using namespace std; 10 int main() 11 { 12 cout<<endl; 13 cout<<"***************好***好***学***习 天***天***向***上****************"<<endl; 14 cout<<endl; 15 cout<<endl; 16 Again: 17 double Ques1=1; 18 int Ques01; 19 int Ques2=1; 20 int Ques3=100; 21 char Ques4='y'; 22 int Ques5=1; 23 char Ques6='n'; 24 char Ques7='n'; 25 double ans=0; 26 int right=0; 27 cout<<" 一.请输入题目数量:"; 28 cin>>Ques1; 29 Ques01=floor(Ques1); 30 // cout<<"请输入每行打印题目数(1-5):"; 31 // cin>>Ques2; 32 cout<<" 二.行间距(正整数):"; 33 cin>>Ques5; 34 cout<<" 三.请输入算式中数值的最大值:"; 35 cin>>Ques3; 36 while(1) 37 { 38 cout<<" 四.运算中需要乘除法吗?y:需要;n:不需要"; 39 cin>>Ques4; 40 cout<<" 五.减法中需要有负数吗?y:需要;n:不需要"; 41 cin>>Ques7; 42 cout<<"`````````````````````````````````````````````````````````````````````````"<<endl; 43 cout<<"开始答题:"<<endl; 44 srand(time(NULL)); 45 if(Ques4=='y') 46 { 47 while(1) 48 { 49 if(Ques1<1) 50 { 51 cout<<"输入有误,请重新输入题目数量:"; 52 cin>>Ques1; 53 Ques01=floor(Ques1); 54 } 55 else 56 { 57 for(int j=0;j<Ques01;j++) 58 { 59 if(j!=0&&j%Ques2==0) 60 { 61 for(int i=0;i<Ques5;i++) 62 { 63 cout<<endl; 64 } 65 } 66 int num1=rand()%Ques3; 67 int num2=rand()%Ques3; 68 int sign=rand()%4; 69 switch(sign) 70 { 71 case 0: 72 cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<" "; 73 cin>>ans; 74 if(ans==num1+num2) 75 { 76 cout<<"正确"<<endl; 77 right++; 78 } 79 else 80 { 81 cout<<"答错了!"<<endl; 82 cout<<"正确答案是:"<<num1+num2<<endl; 83 } 84 break; 85 case 1: 86 if(Ques7=='y') 87 { 88 cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<" "; 89 cin>>ans; 90 if(ans==num1-num2) 91 { 92 cout<<"正确"<<endl; 93 right++; 94 } 95 else 96 { 97 cout<<"答错了!"<<endl; 98 cout<<"正确答案是:"<<num1-num2<<endl; 99 } 100 } 101 else 102 { 103 if(num1>num2) 104 { 105 cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<" "; 106 cin>>ans; 107 if(ans==num1-num2) 108 { 109 cout<<"正确"<<endl; 110 right++; 111 } 112 else 113 { 114 cout<<"答错了!"<<endl; 115 cout<<"正确答案是:"<<num1-num2<<endl; 116 } 117 } 118 else 119 { 120 cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<" "; 121 cin>>ans; 122 if(ans==num2-num1) 123 { 124 cout<<"正确"<<endl; 125 right++; 126 } 127 else 128 { 129 cout<<"答错了!"<<endl; 130 cout<<"正确答案是:"<<num2-num1<<endl; 131 } 132 } 133 } 134 break; 135 case 2: 136 cout<<j+1<<":"<<" "<<num1<<"*"<<num2<<"="<<" "; 137 cin>>ans; 138 if(ans==num1*num2) 139 { 140 cout<<"正确"<<endl; 141 right++; 142 } 143 else 144 { 145 cout<<"答错了!"<<endl; 146 cout<<"正确答案是:"<<num1*num2<<endl; 147 } 148 break; 149 case 3: 150 if(num2!=0) 151 { 152 cout<<j+1<<":"<<" "<<num1<<"/"<<num2<<"="<<" "; 153 cin>>ans; 154 if(ans==num1/num2) 155 { 156 cout<<"正确"<<endl; 157 right++; 158 } 159 else 160 { 161 cout<<"答错了!"<<endl; 162 cout<<"正确答案是:"<<num1/num2<<endl; 163 } 164 } 165 else 166 { 167 j--; 168 } 169 break; 170 } 171 } 172 break; 173 } 174 } 175 cout<<"共答对"<<right<<"道题;"<<"答错"<<Ques01-right<<"道题。"; 176 cout<<"继续努力!"<<endl; 177 break; 178 } 179 if(Ques4=='n') 180 { 181 while(1) 182 { 183 if(Ques01<1) 184 { 185 cout<<"输入有误,请重新输入题目数量:"; 186 cin>>Ques1; 187 Ques01=floor(Ques1); 188 } 189 else 190 { 191 for(int j=0;j<Ques01;j++) 192 { 193 if(j!=0&&j%Ques2==0) 194 { 195 for(int i=0;i<=Ques5;i++) 196 { 197 cout<<endl; 198 } 199 } 200 int num1=rand()%Ques3; 201 int num2=rand()%Ques3; 202 int sign=rand()%2; 203 switch(sign) 204 { 205 case 0: 206 cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<" "; 207 cin>>ans; 208 if(ans==num1+num2) 209 { 210 cout<<"正确"<<endl; 211 right++; 212 } 213 else 214 { 215 cout<<"答错了!"<<endl; 216 cout<<"正确答案是:"<<num1+num2<<endl; 217 } 218 break; 219 case 1: 220 if(Ques7=='y') 221 { 222 cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<" "; 223 cin>>ans; 224 if(ans==num1-num2) 225 { 226 cout<<"正确"<<endl; 227 right++; 228 } 229 else 230 { 231 cout<<"答错了!"<<endl; 232 cout<<"正确答案是:"<<num1-num2<<endl; 233 } 234 break; 235 } 236 else 237 { 238 if(num1>num2) 239 { 240 cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<" "; 241 cin>>ans; 242 if(ans==num1-num2) 243 { 244 cout<<"正确"<<endl; 245 right++; 246 } 247 else 248 { 249 cout<<"答错了!"<<endl; 250 cout<<"正确答案是:"<<num1-num2<<endl; 251 } 252 break; 253 } 254 else 255 { 256 cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<" "; 257 cin>>ans; 258 if(ans==num2-num1) 259 { 260 cout<<"正确"; 261 } 262 else 263 { 264 cout<<"答错了!"<<endl; 265 cout<<"正确答案是:"<<num2-num1<<endl; 266 } 267 break; 268 } 269 } 270 break; 271 } 272 } 273 } 274 break; 275 } 276 cout<<"共答对"<<right<<"道题;"<<"答错"<<Ques01-right<<"道题。"<<endl; 277 cout<<"继续努力!"<<endl; 278 break; 279 } 280 281 else 282 { 283 cout<<"输入有误,请按要求输入!"<<endl; 284 } 285 } 286 cout<<endl; 287 while(1) 288 { 289 cout<<"还需要继续出题还是退出?(y:继续出题;n:退出)"; 290 cin>>Ques6; 291 if(Ques6=='y') 292 { 293 goto Again; 294 } 295 if(Ques6=='n') 296 { 297 goto Exit; 298 } 299 else 300 { 301 cout<<"输入有误,请重新输入:"; 302 } 303 } 304 Exit: 305 return 0; 306 }
四.运行结果
五.
缺陷日志表
学生 梁世豪
日期 2014.3.21_______
教师 王建民
日期 |
编号 |
类型 |
引入阶段 |
排除阶段 |
修复时间 |
修复缺陷 |
程序号_______________
项目计划总结表
姓名:梁世豪 日期:2015/3/21
上课 |
编程 |
看书 |
日总计 |
||
周日 |
|||||
周一 |
|||||
周二 |
100 |
60 |
160 |
||
周三 |
60 |
60 |
120 |
||
周四 |
|||||
周五 |
100 |
60 |
60 |
||
周六 |
120 |
120 |
|||
周总计 |
200 |
240 |
120 |
560 |
时间记录总结表
姓名:梁世豪 日期:2015/3/21
日期 |
开始 |
结束 |
中断时间 |
净时间 |
活动 |
备注 |
C |
U |
3.17 |
8:00 |
9:50 |
10 |
100 |
上课 |
|||
3.17 |
19:00 |
20:20 |
20 |
60 |
编程 |
|||
3.18 |
14:30 |
16:00 |
30 |
60 |
编程 |
|||
3.18 |
16:00 |
17:00 |
60 |
看书 |
||||
3.20 |
8:00 |
9:50 |
10 |
100 |
上课 |
|||
3.20 |
21:00 |
22:00 |
60 |
看书 |
||||
3.16 |
20:00 |
22:30 |
30 |
120 |
编程 |