计算机与软件工程第二次作业

作业一

简易四则运算

  • 作业要求

    1.别能够实现小学一、二、三、四、五年级的四则运算要求, 逐步实现各个年级的难度
    2.要求能够通过输入来选择不同年级,每个年级还得区分难,中,易三个等级
    3.对于三、四、五年级需要支持括号与多个运算符
    4.程序支持判断对错及累计得分与时间
    5.一次可以出100道题目,而且不能重复(比如2+3 与 3+2 算重复的)
    6.充分发挥想象增加满足小学生数学检测需要的功能

代码


#include<iostream>
#include<stdarg.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<fstream>
using namespace std;
int main()
{
ofstream Savefile;
Savefile.open("cpp-home.txt");
cout<<endl;
cout<<"简易四则运算程序"<<endl;
cout<<endl;
cout<<endl;
Again:
double Q1=1;
int Q01;
int Q2=1;
int Q3=100;
char Q4='y';
int Q5=1;
char Q6='n';
char Q7='n';
double ans=0;
int right=0;
cout<<" 输入题目数量(<=100):";
cin>>Q1;
Q01=floor(Q1);
// cout<<"输入每行打印题目数(1-5):";
// cin>>Q2;
cout<<" 每行间距(正整数):";
cin>>Q5;
cout<<" 请输入算式中数值的最大值:";
cin>>Q3;
while(1)
{
cout<<" 是否为三年级以上学生?y/n:";
cin>>Q4;
cout<<" 是否包含负数计算?y/n:";
cin>>Q7;
cout<<"-------------------------------------------------------------------------"<<endl;
cout<<"开始进行答题:"<<endl;
srand(time(NULL));
if(Q4=='y')
{
while(1)
{
if(Q1<1)
{
cout<<"输入有误,请重新输入题目数量:";
cin>>Q1;
Q01=floor(Q1);
}
else
{
for(int j=0;j<Q01;j++)
{
if(j!=0&&j%Q2==0)
{
for(int i=0;i<Q5;i++)
{
cout<<endl;
}
}
int num1=rand()%Q3;
int num2=rand()%Q3;
int sign=rand()%4;
switch(sign)
{
case 0:
cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1+num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"错误"<<endl;
Savefile<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
cout<<"正确答案是:"<<num1+num2<<endl;
Savefile<<"正确答案是:"<<num1+num2<<endl;
}
break;
case 1:
if(Q7=='y')
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正确"<<endl;
right++;
}
else
{

cout<<"错误"<<endl;
cout<<"正确答案是:"<<num1-num2<<endl;
Savefile<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num1-num2<<endl;
}
}
else
{
if(num1>num2)
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"错误"<<endl;
cout<<"正确答案是:"<<num1-num2<<endl;
Savefile<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num1-num2<<endl;
}
}
else
{
cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<"\t";
cin>>ans;
if(ans==num2-num1)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"错误"<<endl;
cout<<"正确答案是:"<<num2-num1<<endl;
Savefile<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num2-num1<<endl;
}
}
}
break;
case 2:
cout<<j+1<<":"<<" "<<num1<<"*"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1*num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"错误"<<endl;
cout<<"正确答案是:"<<num1*num2<<endl;
Savefile<<j+1<<":"<<" "<<num1<<"*"<<num2<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num1*num2<<endl;
}
break;
case 3:
if(num2!=0)
{
cout<<j+1<<":"<<" "<<num1<<"/"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1/num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"错误"<<endl;
cout<<"正确答案是:"<<num1/num2<<endl;
Savefile<<j+1<<":"<<" "<<num1<<"/"<<num2<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num1/num2<<endl;
}
}
else
{
j--;
}
break;
}
}
break;
}
}
cout<<"共答对"<<right<<"道题;"<<"答错"<<Q01-right<<"道题。";
break;
}
if(Q4=='n')
{
while(1)
{
if(Q01<1)
{
cout<<"输入有误,请重新输入题目数量:";
cin>>Q1;
Q01=floor(Q1);
}
else
{
for(int j=0;j<Q01;j++)
{
if(j!=0&&j%Q2==0)
{
for(int i=0;i<=Q5;i++)
{
cout<<endl;
}
}
int num1=rand()%Q3;
int num2=rand()%Q3;
int sign=rand()%2;
switch(sign)
{
case 0:
cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1+num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"错误"<<endl;
cout<<"正确答案是:"<<num1+num2<<endl;
Savefile<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num1+num2<<endl;
}
break;
case 1:
if(Q7=='y')
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"错误"<<endl;
cout<<"正确答案是:"<<num1-num2<<endl;
Savefile<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num1-num2<<endl;
}
break;
}
else
{
if(num1>num2)
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正确"<<endl;
right++;
}
else
{
cout<<"错误"<<endl;
cout<<"正确答案是:"<<num1-num2<<endl;
Savefile<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num1-num2<<endl;
}
break;
}
else
{
cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<"\t";
cin>>ans;
if(ans==num2-num1)
{
cout<<"正确";
}
else
{
cout<<"错误"<<endl;
cout<<"正确答案是:"<<num2-num1<<endl;
Savefile<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<ans<<"\t";
Savefile<<"错误"<<endl;
Savefile<<"正确答案是:"<<num2-num1<<endl;
}
break;
}
}
break;
}
}
}
break;
}
cout<<"共答对"<<right<<"道题;"<<"答错"<<Q01-right<<"道题。"<<endl;
break;
}
else
{
cout<<"输入有误,请按要求输入!"<<endl;
}
}
cout<<endl;
while(1)
{
cout<<"是否继续?(y:继续;n:退出)";
cin>>Q6;
if(Q6=='y')
{
goto Again;
}
if(Q6=='n')
{
goto Exit;
}
else
{
cout<<"输入有误,请重新输入:";
}
}
Savefile.close();
Exit:
// SaveFile.close();
return 0;
}

代码运行截图

小结

代码部分有点困难,目前实行现了选题分大概年级功能,借鉴网络.没有详细分为3,4,5,年级和选择难度程度

作业二

gitee代码托管链接
https://gitee.com/gardonD/dl-git1.git

小结

代码托管花了很大工夫,看不懂官方托管流程,借鉴了网上很多博主的教程,一步一步注册git,配置,拉取远程代码仓库
问题解决见以下
注册问题
代码托管

posted @ 2020-02-27 16:07  DDDDDL  阅读(194)  评论(2编辑  收藏  举报