zoukankan      html  css  js  c++  java
  • 结对开发-四则运算四

    一、题目及要求

    详细要求:
    1、 生成的题目中计算过程不能产生负数,也就是说算术表达式中如果存在形如e1 − e2的子表达式,那么e1 ≥ e2。
    2、生成的题目中如果存在形如e1 ÷ e2的子表达式,那么其结果应是真分数。

    3、每道题目中出现的运算符个数不超过3个,括号不限。

    4、程序一次运行生成的题目不能重复,即任何两道题目不能通过有限次交换+和×左右的算术表达式变换为同一道题目。
    例如,23 + 45 = 和45 + 23 = 是重复的题目,6 × 8 = 和8 × 6 = 也是重复的题目。
    3+(2+1)和1+2+3这两个题目是重复的,由于+是左结合的,1+2+3等价于(1+2)+3,也就是3+(1+2),也就是3+(2+1)。但是1+2+3和3+2+1是不重复的两道题,因为1+2+3等价于(1+2)+3,而3+2+1等价于(3+2)+1,它们之间不能通过有限次交换变成同一个题目。

    5、把程序变成一个网页程序或智能手机程序, 用户通过设定参数,就可以得到各种题目,并可实现在线答题并评判。

    二、源程序代码

    index.html

    复制代码
    <!DOCTYPE html>
    <!--
        Licensed to the Apache Software Foundation (ASF) under one
        or more contributor license agreements.  See the NOTICE file
        distributed with this work for additional information
        regarding copyright ownership.  The ASF licenses this file
        to you under the Apache License, Version 2.0 (the
        "License"); you may not use this file except in compliance
        with the License.  You may obtain a copy of the License at
    
        http://www.apache.org/licenses/LICENSE-2.0
    
        Unless required by applicable law or agreed to in writing,
        software distributed under the License is distributed on an
        "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
         KIND, either express or implied.  See the License for the
        specific language governing permissions and limitations
        under the License.
    -->
    <html>
        <head>
            <!--
            Customize this policy to fit your own app's needs. For more guidance, see:
                https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
            Some notes:
                * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
                * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
                * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                    * Enable inline JS: add 'unsafe-inline' to default-src
            -->
           <link rel=stylesheet type="text/css" href="color.css">
          <title>四则运算</title>
    </style>
    <!--最佳化屏幕宽度-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <!--引用jQuery Mobile函数库 应用ThemeRoller制作的样式-->
    <link rel="stylesheet" href="themes/mythheme.min.css" />
    <link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    
    
        </head>
        <body>           
    <div data-role="page" data-title="小学四则运算" id="first" data-theme="a">
            <div data-role="header">
                <h1>小学四则运算</h1>
            </div>
    <div data-role="content" id="content">
              <ul>
           <a href="login.htm" rel="external">登录</a>
           <a href="#" rel="external">注销</a>
           <a href="formula.htm" rel="external">数学公式</a>
           <a href="advice.htm" rel="external">意见反馈</a>
           </ul>
        
        <h4>打好基础,数学高分更容易</h4>
    <div class="content">
        <div class="nav">
            <span>请输入题目的数量:</span><input type="text" id="shu">
            <button type='button' class="btn btn-success" onclick="play_allE()">开始生成题目</button><br> <span id="textE" ></span><span id="text2E"></span>
            <div data-role="footer">
                <h4>版权所有 侵版必究</h4>
            </div>
     </body>
     <script>
    function GetRandomNumE(Min,Max)
        {   
            var Range = Max - Min;   
            var Rand = Math.random();   
            return(Min + Math.round(Rand * Range));   
        }
        function max_numE(x,y) {
            var t;
            while (y) {
                t = x%y;
                x = y;
                y = t;
            }
            return x;
        }
        function fenshuE(a,b,p) {
            if (p==1) {
                if (a>b) {
                    return a+"/"+b;
                }else if(a<b){
                    return a+"/"+b;
                }else {
                    return 1;
                }
            }else {
                var x=a/p;
                var y=b/p;
                if(y==1){
                    return x;
                }else{
                    return x+"/"+y;
                }
            }
        }
        function f_countE(a,b,c,d) {
                var Arr = ["+","-","*","/"];  
                var n = GetRandomNumE(0,3);
                switch(Arr[n]){
                    case "+":{
                    var sum_x=(a*d)+(b*c);
                    var sum_y=b*d;
                    max_x=max_numE(sum_x,sum_y);
                    max_y=max_numE(sum_x,sum_y);
                    var N=fenshuE(sum_x,sum_y,max_x);
                    return a+"/"+b+"+"+c+"/"+d+"="+N;
                    break;
                    }
                    case "-":{
                    var sum_x=(a*d)-(b*c);
                        while (sum_x<0) {
                            var a = GetRandomNumE(1,30);    
                            var b = GetRandomNumE(1,30);
                            var c = GetRandomNumE(1,30);    
                            var d = GetRandomNumE(1,30);
                            var sum_x=(a*d)-(b*c);
                        }
                    var sum_y=b*d;
                    max_x=max_numE(sum_x,sum_y);
                    max_y=max_numE(sum_x,sum_y);
                    var N=fenshuE(sum_x,sum_y,max_x);
                    return a+"/"+b+"-"+c+"/"+d+"="+N;
                    break;
                    }
                    case "*":{
                    var sum_x=a*c;
                    var sum_y=b*d;
                    max_x=max_numE(sum_x,sum_y);
                    max_y=max_numE(sum_x,sum_y);
                    var N=fenshuE(sum_x,sum_y,max_x);
                    return a+"/"+b+"*"+c+"/"+d+"="+N;
                    break;
                    }
                    case "/":{
                    var sum_x=a*d;
                    var sum_y=b*c;
                    max_x=max_numE(sum_x,sum_y);
                    max_y=max_numE(sum_x,sum_y);
                    var N=fenshuE(sum_x,sum_y,max_x);
                    return a+"/"+b+"÷"+c+"/"+d+"="+N;
                    break;
                    }
                }
        }
        function countE(a,b){
                var Arr = ["+","-","*","/"];  
                var n = GetRandomNumE(0,3);
                switch(Arr[n]){
                    case "+":{
                    var sum=a+b;
                    return a+"+"+b+"="+sum;
                    break;
                    }
                    case "-":{
                    var sum=a-b;
                    while(sum<0){
                        var a = GetRandomNumE(1,30);
                        var b = GetRandomNumE(1,30);
                        var sum=a-b;
                    }
                    return a+"-"+b+"="+sum;
                    break;
                    }
                    case "*":{
                    var sum=a*b;
                    return a+"*"+b+"="+sum;
                    break;
                    }
                    case "/":{
                    var sum=a/b;
                    while(a%b!==0){
                        var max_x=max_numE(a,b);
                        var N=fenshuE(a,b,max_x);
                        return a+"÷"+b+"="+N;
                    }
                    return a+"÷"+b+"="+sum;
                    break;
                    }
                }
        }
        function pl_fE() {
            var son_a = GetRandomNumE(1,30);    
            var par_b = GetRandomNumE(1,30);
            var son_c = GetRandomNumE(1,30);    
            var par_d = GetRandomNumE(1,30);
            var suma=f_countE(son_a,par_b,son_c,par_d);
            return suma;
        }
        function plE() {
                var a = GetRandomNumE(1,30);   
                var b = GetRandomNumE(1,30);
                var sumb=countE(a,b);
                return sumb;
        }
        function play_allE() {
                document.getElementById("textE").innerHTML=null;
                document.getElementById("text2E").innerHTML=null;
                var S=document.getElementById("shu").value;
                for (i = 1; i <=S; i++) {
                    var a = GetRandomNumE(0,1);
                     document.getElementById("textE").innerHTML+=("<br>"+""+i+"题:");
                    switch (a) {
                        case 0:
                                                  
                            var A=plE();
                            var strs = A.split("=");
                            document.getElementById("textE").innerHTML+=(strs[0]+"="+"<br>");
                            document.getElementById("text2E").innerHTML+=("<br>"+""+i+"题答案:"+strs[1]+"<br>");
                            break;
                        case 1:
                                            
                            var B=pl_fE();
                            var strs = B.split("=");
                            document.getElementById("textE").innerHTML+=(strs[0]+"="+"<br>");
                            document.getElementById("text2E").innerHTML+=("<br>"+""+i+"题答案:"+strs[1]+"<br>");
                            break;
                    }
                }
        }
     </script>
    </html>
    复制代码

    三、运行结果截图

    五、项目计划日志

    日期&&任务

    听课 编写程序 阅读相关书籍 网上查找资料   日总计
    周一 100   30 30 160
    周二   120 30 30 180
    周三   30 30 10 70
    周四 100 20  30   150
    周五   120   30 30 180
    周六   145 30 10 85
    周日   200 30     
    周总计 200 635 210 110

    1155

    时间记录日志

    3/28

    日期 开始时间 结束时间 中断时间 净时间 活动 备注
    3/28 14:00 15:50 10 100 听课 软件工程上课
      21:04 21:  34 0 30 阅读书籍 《构建之法》
      22:10 22: 40 30 网上查找资料  查阅安卓相关资料
     3/29  18:00  18:30  0  30  阅读书籍 《构建之法》 
      19:00 21:30 20 120 编写程序 结对开发- 安卓APP
      22:  15 22:  45 30 网上查找资料  查阅安卓相关资料
    3/30 19:  25 20: 00 5 30 编写程序 结对开发- 安卓APP
      22:00 22: 30 0 30 阅读书籍 《构建之法》
      22:40 22: 50 0 10 查找资料  查阅安卓相关资料
    3/31 14:00 15:  50 10 100 上课 软件工程上课
      18:26 18: 50 20 编写程序 结对开发- 联通版
       22:00  22:30  0  30  阅读书籍  《构建之法》
    4/1 14:  00 16:  20 20 120  编写程序 结对开发- 安卓APP
      11:23 12: 00 7 30 网上查找资料  查阅安卓相关资料
       21:00  21:30  0  30  阅读书籍  《构建之法》
    4/2 7: 00   7: 30 0 30 阅读书籍 阅读《构建之法》
      10: 00 13: 00 35 145 编写程序 结对开发- 安卓APP
      9:   45   9: 55  0 10 网上查找资料  查阅安卓相关资料
    4/3 8:20 12:  00 20 200 编写程序 结对开发-联通版
      15: 23 16: 00 7 30 阅读书籍 阅读《构建之法》
  • 相关阅读:
    Path类
    C#集合
    阿里巴巴2013年实习生笔试题B
    阿里巴巴2013年实习生笔试题A
    腾讯2014年校园招聘笔试试题
    腾讯技术类校园招聘笔试试题
    腾讯2013年实习生笔试题
    腾讯2012年实习生笔试题
    hdu1505
    hdu1506
  • 原文地址:https://www.cnblogs.com/qizhonh/p/5360940.html
Copyright © 2011-2022 走看看