1. 程式人生 > >第一階段結對作業驗收小學生四則運算:

第一階段結對作業驗收小學生四則運算:

程式程式碼

#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
void boom()
{
float d;
int z,n,m=0,zq=0,cw=0; 
int first_num,second_num;
srand((unsigned)time(NULL));
float daan[100];
cout<<"請輸入需要的題目數量:";
cin>>n;
cout<<"附註

:分式運算6位有效數字"<<endl;
for(int i=0;i<n;i++)
{
z=rand()%4;
first_num=rand()%100;//隨機取一個100以內的數
second_num=rand()%100;//隨機取一個100以內的數
switch(z)//設定加減乘除
{
case 0:
cout<<i+1<<""<<first_num<<"+"<<second_num<<"="<<" ";
daan[i+1]=first_num+second_num;
break;
case 1:
cout<<i+1<<"
"<<first_num<<"-"<<second_num<<"="<<" "; 
daan[i+1]=first_num-second_num;
break;
case 2:
cout<<i+1<<""<<first_num<<"*"<<second_num<<"="<<" ";
daan[i+1]=first_num*second_num;
break;
case 3:
if(second_num!=0)
{
cout<<i+1<<"
"<<first_num<<"/"<<second_num<<"="<<" ";
}
else
{
i=i-1;
}
daan[i+1]=(float)first_numcond_num;
break;
}
if((i+1)%3==0)//三行一輸出
{
for(int c=0;c<=1;c++)
{
cout<<endl;
}
}
if((i+1)==n)//輸出數足夠後停止
{
cout<<endl;
}
}
for(int i=1;i<=n;i++)
{
cout<<"請作答:"<<endl;
cout<<i<<" ";
cin>>d;
if(d==daan[i])
{
cout<<"恭喜您,回答正確!"<<endl;
zq+=1;
cout<<endl;
}
else
{
cout<<"回答錯誤,正確答案為:"<<" "<<daan[i]<<endl;
cw+=1;
cout<<endl;
}
}
cout<<"回答正確的數量為:"<<" "<<zq<<" "<<endl;
cout<<"回答錯誤的數量為;"<<" "<<cw<<" "<<endl;
}
int main()
{
boom();
return 0;