软件工程个人作业02
设计思路:(1)设计四个函数分别是加减有负数和加减无负数以及乘除有余数和无余数。
(2)在主函数里面将所有的6种情况(1.无乘除,无负数.2.无乘除,有负数.3.有乘除,无余数,无负数.4.有乘除,有余数,无负数.5.有乘除,无余数,有负数.6.有乘除,有余
数 ,有负数.)分别调用不同的函数。
源代码:
#include<iostream> #include<stdlib.h> #include<conio.h> using namespace std; void DealAddAndSubtract1(int n/*取值*/,int m/*题数*/,int a[][2],int b[])/*无负数*/ { for(int p=0;p<m;p++) { int a=(int)rand()%n; int b=(int)rand()%n; if(b>a) { int c; c=b; b=a; a=c; } int i=(int)rand()%n; int j=(int)rand()%n; for(;;) { if(i<=j&&j!=0) break; i=(int)rand()%n; j=(int)rand()%n; } int c=(int)rand()%n; int d=(int)rand()%n; for(;;) { if(c<=d&&d!=0) break; c=(int)rand()%n; d=(int)rand()%n; } if(c*j<d*i) { int e,f; e=i; i=c; c=e; f=j; j=d; d=f; } int k=(int)rand()%4; switch(k) { case 0: { cout<<a<<"+"<<b<<"="; break; } case 1: { cout<<a<<"-"<<b<<"="; break; } case 2: { cout<<"("<<c<<"/"<<d<<")"<<"+"<<"("<<i<<"/"<<j<<")"<<"="; break; } case 3: { cout<<"("<<c<<"/"<<d<<")"<<"-"<<"("<<i<<"/"<<j<<")"<<"="; break; } } if (p%5==4) { cout<<endl; } else { cout<<'\t'; } } } void DealAddAndSubtract2(int n/*取值*/,int m/*题数*/,int a[][2],int b[])/*有负数*/ { for(int p=0;p<m;p++) { int a=(int)rand()%n; int b=(int)rand()%n; int i=(int)rand()%n; int j=(int)rand()%n; for(;;) { if(i<=j&&j!=0) break; i=(int)rand()%n; j=(int)rand()%n; } int c=(int)rand()%n; int d=(int)rand()%n; for(;;) { if(c<=d&&d!=0) break; c=(int)rand()%n; d=(int)rand()%n; } int k=(int)rand()%4; switch(k) { case 0: { cout<<a<<"+"<<b<<"="; break; } case 1: { cout<<a<<"-"<<b<<"="; break; } case 2: { cout<<"("<<c<<"/"<<d<<")"<<"+"<<"("<<i<<"/"<<j<<")"<<"="; break; } case 3: { cout<<"("<<c<<"/"<<d<<")"<<"-"<<"("<<i<<"/"<<j<<")"<<"="; break; } } if (p%5==4) { cout<<endl; } else { cout<<'\t'; } } } void DealMultiplicationAndDivison1(int n/*取值*/,int m/*题数*/,int a[][2],int b[])/*无余数*/ { for(int p=0;p<m;p++) { int a=(int)rand()%n; int b=(int)rand()%n; for(;;) { if(b!=0&&a>b&&a%b==0) break; a=(int)rand()%n; b=(int)rand()%n; } int i=(int)rand()%n; int j=(int)rand()%n; for(;;) { if(i<=j&&j!=0&&i!=0) break; i=(int)rand()%n; j=(int)rand()%n; } int c=(int)rand()%n; int d=(int)rand()%n; for(;;) { if(c<=d&&d!=0) break; c=(int)rand()%n; d=(int)rand()%n; } int k=(int)rand()%4; switch(k) { case 0: { cout<<a<<"*"<<b<<"="; break; } case 1: { cout<<a<<"/"<<b<<"="; break; } case 2: { cout<<"("<<c<<"/"<<d<<")"<<"*"<<"("<<i<<"/"<<j<<")"<<"="; break; } case 3: { cout<<"("<<c<<"/"<<d<<")"<<"/"<<"("<<i<<"/"<<j<<")"<<"="; break; } } if (p%5==4) { cout<<endl; } else { cout<<'\t'; } } } void DealMultiplicationAndDivison2(int n/*取值*/,int m/*题数*/,int a[][2],int b[])/*有余数*/ { for(int p=0;p<m;p++) { int a=(int)rand()%n; int b=(int)rand()%n; for(;;) { if(b!=0) break; b=(int)rand()%n; } int i=(int)rand()%n; int j=(int)rand()%n; for(;;) { if(i<=j&&j!=0&&i!=0) break; i=(int)rand()%n; j=(int)rand()%n; } int c=(int)rand()%n; int d=(int)rand()%n; for(;;) { if(c<=d&&d!=0) break; c=(int)rand()%n; d=(int)rand()%n; } int k=(int)rand()%4; switch(k) { case 0: { cout<<a<<"*"<<b<<"="; break; } case 1: { cout<<a<<"/"<<b<<"="; break; } case 2: { cout<<"("<<c<<"/"<<d<<")"<<"*"<<"("<<i<<"/"<<j<<")"<<"="; break; } case 3: { cout<<"("<<c<<"/"<<d<<")"<<"/"<<"("<<i<<"/"<<j<<")"<<"="; break; } } if (p%5==4) { cout<<endl; } else { cout<<'\t'; } } } void main() { int b[1000]; int a[1000][2]; int z; p:cout<<"请输入选项:"<<endl<<"1.无乘除,无负数."<<endl<<"2.无乘除,有负数."<<endl<<"3.有乘除,无余数,无负数."<<endl<<"4.有乘除,有余数,无负数."<<endl<<"5.有乘除,无余数,有负数."<<endl <<"6.有乘除,有余数,有负数."<<endl; cin>>z; if(z==1)/*无乘除,无余数*/ { int m,n; cout<<"请输入随机数的范围:"<<endl; cin>>n; cout<<"请输入题目的个数:"<<endl; cin>>m; DealAddAndSubtract1(n/*取值*/, m/*题数*/,a,b); int j; cout<<"是否继续:"<<endl<<"1.继续"<<endl<<"2.退出"<<endl; cin>>j; if(j==1) { goto p; } else { exit(1); } } else if(z==2)/*无乘除,无负数*/ { int m,n; cout<<"请输入随机数的范围:"<<endl; cin>>n; cout<<"请输入题目的个数:"<<endl; cin>>m; DealAddAndSubtract2(n/*取值*/, m/*题数*/,a,b); int j; cout<<"是否继续:"<<endl<<"1.继续"<<endl<<"2.退出"<<endl; cin>>j; if(j==1) { goto p; } else { exit(1); } } else if(z==3)/*有乘除,无余数,无负数*/ { int m,n; cout<<"请输入随机数的范围:"<<endl; cin>>n; cout<<"请输入题目的个数:"<<endl; cin>>m; for(int i=0;i<m;i++) { int k=(int)rand()%2; switch(k) { case 0: { DealMultiplicationAndDivison1(n/*取值*/,1/*题数*/,a,b); break; } case 1: { DealAddAndSubtract1(n/*取值*/, 1/*题数*/,a,b); break; } } if (i%5==4) { cout<<endl; } else { cout<<'\t'; } } int j; cout<<"是否继续:"<<endl<<"1.继续"<<endl<<"2.退出"<<endl; cin>>j; if(j==1) { goto p; } else { exit(1); } } else if(z==4)/*有乘除,有余数,无负数*/ { int m,n; cout<<"请输入随机数的范围:"<<endl; cin>>n; cout<<"请输入题目的个数:"<<endl; cin>>m; for(int i=0;i<m;i++) { int k=(int)rand()%2; switch(k) { case 0: { DealMultiplicationAndDivison2(n/*取值*/,1/*题数*/,a,b); break; } case 1: { DealAddAndSubtract1(n/*取值*/, 1/*题数*/,a,b); break; } } if (i%5==4) { cout<<endl; } else { cout<<'\t'; } } int j; cout<<"是否继续:"<<endl<<"1.继续"<<endl<<"2.退出"<<endl; cin>>j; if(j==1) { goto p; } else { exit(1); } } else if(z==5)/*有乘除,无余数,有负数*/ { int m,n; cout<<"请输入随机数的范围:"<<endl; cin>>n; cout<<"请输入题目的个数:"<<endl; cin>>m; for(int i=0;i<m;i++) { int k=(int)rand()%2; switch(k) { case 0: { DealMultiplicationAndDivison1(n/*取值*/,1/*题数*/,a,b); break; } case 1: { DealAddAndSubtract2(n/*取值*/, 1/*题数*/,a,b); break; } } if (i%5==4) { cout<<endl; } else { cout<<'\t'; } } int j; cout<<"是否继续:"<<endl<<"1.继续"<<endl<<"2.退出"<<endl; cin>>j; if(j==1) { goto p; } else { exit(1); } } else if(z==6)/*有乘除,有余数,有负数*/ { int m,n; cout<<"请输入随机数的范围:"<<endl; cin>>n; cout<<"请输入题目的个数:"<<endl; cin>>m; for(int i=0;i<m;i++) { int k=(int)rand()%2; switch(k) { case 0: { DealMultiplicationAndDivison2(n/*取值*/,1/*题数*/,a,b); break; } case 1: { DealAddAndSubtract2(n/*取值*/, 1/*题数*/,a,b); break; } } if (i%5==4) { cout<<endl; } else { cout<<'\t'; } } int j; cout<<"是否继续:"<<endl<<"1.继续"<<endl<<"2.退出"<<endl; cin>>j; if(j==1) { goto p; } else { exit(1); } } else { cout<<"输入有误!,请重新选择."<<endl; goto p; } }
周活动总结表姓名:杨国力 日期:19/3/2016
日期/任务 | 听课 | 编程 | 阅读课本 | 准备考试 | 日总计 | ||
周日 | 0 | 0 | 0 | 0 | 0 | ||
周一 | 120 | 60 | 30 | 0 | 210 | ||
周二 | 0 | 60 | 30 | 0 | 90 | ||
周三 | 0 |
60 |
0 | 0 | 60 | ||
周四 | 0 | 0 | 0 | 0 | 0 | ||
周五 | 0 | 0 | 0 | 0 | 0 | ||
周六 | 0 | 60 | 0 | 0 | 60 | ||
周总计 | 120 | 240 | 60 | 0 |
420 |
学生:杨国力 日期:2016.3.19教师:王建明 课程:软件工程概论
日期 | 开始时间 | 结束时间 | 中断时间 | 净时间 | 活动 | 备注 | C | U |
3.14 | 8:00 | 9:50 | 10 | 100 | 听课 | 休息 | ||
14:00 | 14:20 | 0 | 20 | 阅读 | ||||
3.15 | 15:00 | 16:25 | 25 | 60 | 编程 | 上厕所.休息 | ||
17:00 | 17:30 | 0 | 30 | 阅读 | ||||
3.16 | 15:00 | 16:10 | 10 | 60 | 编程 | |||
3.19 | 15:00 | 15:40 | 10 | 30 | 编程 | 上厕所 | ||
17:00 | 17:30 | 30 | 编程 | |||||
3.14 | 14:30 | 15:30 | 0 | 60 | 编程 | |||
16:00 | 16:30 | 0 | 30 | 阅读 | ||||
|
编程总结:在编程当中遇到了好些问题,比如在分数的除法当中忘了分母不能为0.通过这一次编程。我认识到了严谨是一个软件工程师不可缺少的品质。