我要编写一个关于四则运算的程序。设计思路:
①设计算法,需要运用随机数;②设置一个随机数z,让z对4求余得x;(3)设置分类语句让四则运算通过x随机出现;(4)设置每行输出10个的语句.
首先,我先进行了程序估算,在我的估算中:
查看资料等消耗15分钟左右;
编写代码需要30分钟左右;
调试程序及优化需要20分钟左右;
整个程序完成时间约70分钟。
实验结果:
我使用了35分钟编写完成了这个程序并进行了调试优化;整体来说对于程序语言的知识掌握的不够精确。
程序代码:
1 #include<iostream> 2 #include<time.h> 3 #include<stdlib.h> //调用随机函数; 4 using namespace std; 5 int main() 6 { 7 srand((unsigned)time(NULL));//使随机产生的题目不重复; 8 int x,y,n;//x,y为随机数,n为题目数量; 9 int ch; 10 cout<<"enter the amount of you want to get:"; 11 cin>>n; 12 for(int i=1;i<=n;i++) 13 { 14 x=rand()%100;y=rand()%100; 15 ch=rand()%4; 16 switch(ch) 17 { 18 case 0:cout<<x<<"+"<<y<<"="<<" "; 19 break; 20 case 1:cout<<x<<"-"<<y<<"="<<" "; 21 break; 22 case 2:cout<<x<<"*"<<y<<"="<<" "; 23 break; 24 case 3:cout<<x<<"/"<<y<<"="<<" "; 25 } 26 if(i%10==0) 27 { 28 cout<<endl; 29 } 30 } 31 return 0; 32 }