• 算式在线答题


    设计思路:随机两个两位数,再随机产生一个+-*/符号,连接两个数。将正确答案存和答案比较,用来判断正误。

    代码:

     1 #include<iostream.h>
     2 #include<stdlib.h>
     3 #include<time.h>
     4 void boom()
     5 {
     6 float x,y;
     7 int a,b; 
     8 int first_num,second_num;
     9 srand(time(NULL));
    10 int n;
    11 float k;
    12 float d;
    13 float daan[100];
    14 int zq=0;
    15 int cw=0;
    16 cout<<"输入题目数量:"<<endl;
    17 cin>>n; 
    18 for(int i=0;i<n;i++)
    19 {
    20 
    21 a=rand()%4;
    22 first_num=rand()%100;
    23 second_num=rand()%100;
    24 a=rand()%4;
    25 switch(a)
    26 {
    27 case 0:
    28 cout<<i+1<<""<<first_num<<"+"<<second_num<<"="<<" ";
    29 daan[i+1]=first_num+second_num;
    30 break;
    31 case 1:
    32 cout<<i+1<<""<<first_num<<"*"<<second_num<<"="<<" "; 
    33 daan[i+1]=first_num*second_num;
    34 break;
    35 case 2:
    36     if(first_num>second_num)
    37     {cout<<i+1<<""<<first_num<<"-"<<second_num<<"="<<" ";
    38 daan[i+1]=first_num-second_num;
    39     }
    40     else{
    41         i=i-1;
    42     }
    43     daan[i+1]=first_num-second_num;
    44 break;
    45 case 3:
    46 
    47     if(y!=0&&first_num>second_num&&first_num%second_num==0)
    48 {
    49 cout<<i+1<<""<<first_num<<"/"<<second_num<<"="<<" ";
    50 }
    51 else
    52 {
    53 i=i-1;
    54 }
    55 daan[i+1]=first_num/second_num;
    56 break;
    57 }
    58 if((i+1)%3==0)
    59 {
    60 for(int c=0;c<=1;c++)
    61 {
    62 cout<<endl;
    63 }
    64 }
    65 if((i+1)==n)
    66 {
    67 cout<<endl;
    68 }
    69 }
    70 for(i=1;i<=n;i++)
    71 {
    72 cout<<"请答题:"<<endl;
    73 cout<<i<<"";
    74 cin>>d;
    75 if(d==daan[i])
    76 {
    77 cout<<"回答正确!"<<endl;
    78 cout<<endl;
    79 zq=zq+1;
    80 }
    81 else
    82 {
    83 cout<<"回答错误,正确答案为:"<<" "<<daan[i]<<endl;
    84 cout<<endl;
    85 cw=cw+1;
    86 }
    87 }
    88 k=(float)zq/n;
    89 cout<<"答对数为:"<<" "<<zq<<""<<endl;
    90 cout<<"答错数为:"<<" "<<cw<<""<<endl;
    91 cout<<"正确率为:"<<" "<<k<<endl;
    92 }
    93 int main()
    94 {
    95 boom(); 
    96 main();
    97 return 0;
    98 }

    项目计划总结:

    运行截图

    团队皂片:

  • 相关阅读:
    05-3. 六度空间 (PAT)
    05-2. Saving James Bond
    05-1. List Components (PAT)
    04-3. Huffman Codes (PAT)
    04-2. File Transfer (PAT)
    04-1. Root of AVL Tree (PAT)
    03-3. Tree Traversals Again (PAT)
    03-2. List Leaves (PAT)
    03-1. 二分法求多项式单根(PAT)
    CDH Namenode自动切换(active-standby)
  • 原文地址:https://www.cnblogs.com/4EY4EVER/p/9926126.html
Copyright © 2020-2023  润新知