团队作业--四则运算网页版

设计思路:

(1)结合之前的.java代码(之前的四则运算程序)实现网页化

(2)先利用最近web课上学的html语言实现首页(功能为对题目进行定制)

(3)在用户定制题目后把参数传给jsp文件

(4)jsp文件调用。java文件实现四则运算式的输出和答案校验

HuanYing.html

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>四则运算答题系统首页</title>
 6 
 7 <!-- 强制浏览器编码设为简体中文(GB2312),name为搜索引擎提供的关键字列表,Description用来告诉搜索引擎你的网站主要内容 -->
 8 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 9 <meta name="keywords" content="keyword1,keyword2,keyword3">
10 <meta name="description" content="this is my page">
11 <Meta name=Author Content=李营,1058584348@qq.com>
12 
13 </head>
14 <body background="1.jpg">
15 <h1 align="center">四则运算</h1>
16 <!-- 传递参数值给index.jsp处理 -->
17 <form action="index.jsp" method="post" action="My.jsp" method="post">
18 <!-- 互斥选择 -->
19 <center>
20 <br>请选择上限(分数没有上下限):
21 <select name="TopNumber">
22 <option value=20>20</option>
23 <option value=20>30</option>
24 <option value=20>50</option>
25 <option value=20>80</option>
26 <option value=20>100</option>
27 </select><br>
28 <br>请选择下限(分数没有上下限):
29 <select name="BaseNumber">
30 <option value=0>0</option>
31 <option value=1>1</option>
32 <option value=3>3</option>
33 <option value=5>5</option>
34 <option value=10>10</option>
35 </select><br>
36 <!-- 多项选择,在jsp中用数组保存 -->
37 <br>请在以下选项中打勾:
38    <input type="checkbox" name="function" value=1>有乘除
39    <input type="checkbox" name="function" value=2>无余数
40    <input type="checkbox" name="function" value=3>有括号
41 <br>
42    <br>
43    <br>
44    <input type="submit"  name="submit" value="确定">
45 </center>
46 </form>
47 <br><br><br><br><br><br><br><br><br><br><br>
48 <p align="right">作者:信1405-2 李营</p>
49 </body>
50 </html>

index.jsp

 1 <%@ page language="java" contentType="text/html; charset=utf-8"
 2 
 3     pageEncoding="utf-8"%>
 4 <%@ page import="SiZeYunSuan.*"%>
 5 <%
 6 String path = request.getContextPath();
 7 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 8 %>
 9 
10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
11 <html>
12   <head>
13     <base href="<%=basePath%>">
14     
15     <title>答题</title>
16     <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
17     <meta http-equiv="pragma" content="no-cache">
18     <meta http-equiv="cache-control" content="no-cache">
19     <meta http-equiv="expires" content="0">    
20     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
21     <meta http-equiv="description" content="This is my page">
22     <!--
23     <link rel="stylesheet" type="text/css" href="styles.css">
24     -->
25   </head>
26   
27   <body background="images/A2.jpg">
28 
29    <%
30    String[] s=new String[30];
31    float k[]=new float[30];
32    SiZeYunSuan a=new SiZeYunSuan();
33  
34    request.setCharacterEncoding("UTF-8");
35    String[] function = request.getParameterValues("function");
36    String TopNumber,BaseNumber;
37    TopNumber=request.getParameter("TopNumber");
38    BaseNumber=request.getParameter("BaseNumber");
39     a.SetValue(a.StrToNum(TopNumber),a.StrToNum(BaseNumber));
40    if(function!=null){
41    for(int i=0;i<function.length;i++){
42        if(function[i].equals("1"))
43        {
44            a.SetValue1(1);
45        }
46        if(function[i].equals("2"))
47        {
48            a.SetValue2(1);
49        }
50        if(function[i].equals("3"))
51        {
52            a.SetValue3(0);
53        }
54        }
55    }
56        
57   
58     %>
59    <form action="MyJsp.jsp" method="post">
60    <center>
61    <%
62      a.main();
63      float temp;
64      String[] se=new String[30];
65      for(int i=0;i<30;i++){
66      s[i]=a.cs(i);
67            se[i]="name";
68            se[i]=se[i]+i;
69      k[i]=a.css(i);
70      out.print("<tr>"+s[i]+"</tr>");
71      out.println("<br>");
72     
73      
74    %>   
75    <input type="text" name=<%=se[i] %>><br>
76    <%
77        } 
78         session.setAttribute( "v1",s);
79         session.setAttribute( "v2",k); 
80     %>
81     <br><input type="submit" name="submit" value="提交">
82     
83     <%
84     
85    
86     %>
87      </center>
88   </form>
89   
90   
91    
92     
93   </body>
94 </html>

MyJsp.jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="gb2312" contentType="text/html; charset=gb2312"%>
 2 <%@ page import="SiZeYunSuan.*"%>
 3 <%
 4 String path = request.getContextPath();
 5 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 6 %>
 7 
 8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 9 <html>
10   <head>
11     <base href="<%=basePath%>">
12     
13     <title>结果</title>
14     
15     <meta http-equiv="pragma" content="no-cache">
16     <meta http-equiv="cache-control" content="no-cache">
17     <meta http-equiv="expires" content="0">    
18     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
19     <meta http-equiv="description" content="This is my page">
20     <!--
21     <link rel="stylesheet" type="text/css" href="styles.css">
22     -->
23 
24   </head>
25   
26  <body background="1.jpg">
27   <% request.setCharacterEncoding("UTF-8");%>
28   <center>
29   <%
30 
31     
32     String[] name=new String[30];
33     String[] sum=new String[30];
34     SiZeYunSuan a=new SiZeYunSuan();
35     float sum1[]=new float[30];
36     int right=0;
37     String[] s= (String[])session.getAttribute("v1");
38     float[] k=(float[])session.getAttribute("v2");
39   
40     for(int i=0;i<30;i++)
41         sum1[i]=0;
42     for(int i=0;i<30;i++){
43         name[i]="name";
44         name[i]=name[i]+i;
45         
46         sum[i]=request.getParameter(name[i]);
47         //sum[i]=request.getParameterValues(name[i])";
48         out.print(s[i]);
49         out.print("<tr>"+sum[i]+"</tr>");
50         if(sum[i]=="")
51            out.print("未回答!");
52         else{
53             if(((int)(k[i]*100))%100!=0)
54                sum1[i]=a.StrToFloat1(sum[i]);
55             else
56                sum1[i]=a.StrToFloat(sum[i]);
57             if(Math.abs(sum1[i]*100-k[i]*100)<4){
58                out.print(" 回答正确!");
59                right++;
60             }
61             else
62                out.print(" 回答错误,正确答案是: "+k[i]);
63         }   
64         
65          out.println("<br>");
66     }
67     out.print("总共做对 "+right+" 题,正确率为:"+(right/30.0)*100+" %");
68   %><br>
69    <input type="button" value="返回首页" onClick="window.location.href='HuanYing.html'">
70    <input type="button" value="关闭" onClick="window.close();">
71     </center>
72   </body>
73 </html>

SiZeYunSuan.java

  1 package SiZeYunSuan;
  2 
  3 import java.util.*;
  4 public class SiZeYunSuan {
  5         static int MAX=100;
  6         static String formula = "";         //当前算式
  7         static String[] buffer = new String[MAX];     //缓冲区数组
  8         static int TopNumber;          //上限
  9         static int BaseNumber;         //下限
 10         static int IsMulDlvExist;      //是否有乘除
 11         static int Amount;             //操作数的个数
 12         static int BracketNum;         //括号个数
 13         static int[] LBraket = new int[2];         //左括号的位置
 14         static int[] RBraket = new int[2];         //右括号的位置
 15         static int IsNeg;              //是否有负数
 16         static int IsRem;              //是否有余数
 17         static int IsBra;              //是否有括号
 18         static int IsRep;              //是否重复
 19         static float[] Result= new float[MAX];      //正确结果数组
 20         static char lastOp;            //记录上个运算符是否为除号
 21         
 22         //优先级数组
 23         static char[][] prior = {
 24             { '>', '>', '<', '<', '<', '>', '>' },
 25             { '>', '>', '<', '<', '<', '>', '>' },
 26             { '>', '>', '>', '>', '<', '>', '>' },
 27             { '>', '>', '>', '>', '<', '>', '>' },
 28             { '<', '<', '<', '<', '<', '=', ' ' },
 29             { '>', '>', '>', '>', ' ', '>', '>' },
 30             { '<', '<', '<', '<', '<', ' ', '=' }
 31         };
 32         
 33         //将操作符转化为优先级数组的下标
 34         static int Change(String Oper)
 35         {
 36             switch (Oper.charAt(0))
 37             {
 38                 case '+': return 0;
 39                 case '-': return 1; 
 40                 case '*': return 2; 
 41                 case '/': return 3; 
 42                 case '(': return 4; 
 43                 case ')': return 5;
 44                 case '=': return 6; 
 45                 default:  return 6; 
 46             }
 47         }
 48         static int Change(char Oper)
 49         {
 50             switch (Oper)
 51             {
 52                 case '+': return 0;
 53                 case '-': return 1; 
 54                 case '*': return 2; 
 55                 case '/': return 3; 
 56                 case '(': return 4; 
 57                 case ')': return 5;
 58                 case '=': return 6; 
 59                 default:  return 6; 
 60             }
 61         }
 62         static //返回优先级的大小
 63         char Precede(char Oper, char ch)
 64         {
 65             return prior[Change(Oper)][Change(ch)];
 66         }
 67         
 68         //计算两个数的结果
 69         static float Operate(float first, char oper1, float second)
 70         {
 71             switch (oper1)
 72             {
 73             case '+':
 74             {
 75                         return (first + second);
 76             }
 77             case '-':
 78             {
 79                 if (first-second<0)
 80                 {
 81                     IsRep = 1;
 82                     return 0;
 83                 }
 84                         return (first - second);                    
 85             }
 86             case '*':
 87             {
 88                         return (first * second);                    
 89             }
 90             case '/':
 91             {
 92                         if (second == 0)
 93                         {
 94                             IsRep = 1;
 95                             return 0;
 96                         }
 97                         return (first / second);
 98             }
 99             default:  return 0; 
100             }
101         }
102         
103         //数字的个数
104         static void NumberAmount()
105         {
106             Amount = 2 + (int)((Math.random())*3);
107         }
108         
109         //加左括号   随机选择在第几个数字前面加括号
110         static void AddLbracket(){
111             for (int j = 0; j < 2; j++)
112                 LBraket[j] = 0;
113             if (Amount == 2)
114             {
115                 BracketNum = 0;
116             }
117             if (Amount == 3){
118                 BracketNum = (int)((Math.random())*2);
119             }
120             if (Amount > 3)
121             {
122                 BracketNum = (int)((Math.random())*3);
123             }
124             for (int i = 0; i < BracketNum; i++){
125                 LBraket[i] = 1 + (int)((Math.random())*(Amount - 2));
126             }
127         }
128         //加右括号
129         static void AddRbracket(){
130             for (int j = 0; j < 2; j++)
131                 RBraket[j] = 0;
132             int choose;
133             int trance;
134             if (BracketNum == 1){
135                 RBraket[0] = LBraket[0] + 1 +(int)((Math.random())* (Amount - LBraket[0]));
136             }
137             if (BracketNum == 2)
138 
139             {
140                 //把最左边的左括号放在第一个数组中
141                 if (LBraket[0] < LBraket[1])
142                 {
143                     trance = LBraket[0];
144                     LBraket[0] = LBraket[1];
145                     LBraket[1] = trance;
146                 }
147                 //当两个左括号之间相差有点远时有2中右括号添加方法
148                 if (LBraket[0] - LBraket[1]>2){
149                     choose = (int)((Math.random())*2);
150                     if (choose == 0){
151                         RBraket[0] = LBraket[0] + 1 + (int)((Math.random())*(Amount - LBraket[0]));
152                         RBraket[1] = LBraket[0] + 1 + (int)((Math.random())*(Amount - LBraket[0]));
153                     }
154                     if (choose == 1)
155                     {
156                         RBraket[0] = LBraket[0] + 1 + (int)((Math.random())*(Amount - LBraket[0]));
157                         RBraket[1] = LBraket[1] + 1 + (int)((Math.random())*(LBraket[0] - 2));
158                     }
159                 }
160                 else
161                 {
162                     RBraket[0] = LBraket[0] + 1 + (int)((Math.random())*(Amount - LBraket[0]));
163                     RBraket[1] = LBraket[0] + 1 + (int)((Math.random())*(Amount - LBraket[0]));
164                     if (LBraket[0] == LBraket[1] && RBraket[0] == RBraket[1]){
165                         LBraket[0] = LBraket[1] = 0;
166                         RBraket[0] = RBraket[1] = 0;
167                         BracketNum = 0;
168 
169                     }
170                     if (LBraket[1] == 1 && (RBraket[0] == Amount || RBraket[1] == Amount))
171                     {
172                         LBraket[0] = LBraket[1] = 0;
173                         RBraket[0] = RBraket[1] = 0;
174                         BracketNum = 0;
175                     }
176 
177                 }
178             }
179         }
180         
181         //随机产生最简真分数
182         static void Score(){
183             int Left, Right;
184             Left = BaseNumber + (int)((Math.random())*(TopNumber - BaseNumber + 1));
185             Right = BaseNumber + (int)((Math.random())*(TopNumber - BaseNumber + 1));
186             while (Left >= Right || Left == 0)
187             {
188                 Left = BaseNumber + (int)((Math.random())*(TopNumber - BaseNumber + 1));
189                 Right = BaseNumber + (int)((Math.random())*(TopNumber - BaseNumber + 1));
190             }
191             int max = 1;
192             //求最大公约数
193             for (int i = 2; i <= Left; i++)
194             {
195                 if (Left%i == 0 && Right%i == 0)
196                 {
197                     max = i;
198                 }
199             }
200             if (max > 1)
201             {
202                 Left /= max;
203                 Right /= max;
204             }
205             formula += "(" + Left + "/" + Right + ")";
206         }
207         
208         //随机生成操作符
209         static void Operater()
210         {
211             int choose;
212             char op='+';
213             if (IsMulDlvExist == 1)
214                 choose = 1 + (int)((Math.random())* 4);
215             else
216                 choose = 1 + (int)((Math.random())*2);
217 
218             switch (choose)
219             {
220                 case 1:{op = '+'; lastOp = '+'; break; }
221                 case 2:{op = '-';  lastOp = '-'; break; }
222                 case 3:{op = '*';  lastOp = '*'; break; }
223                 case 4:
224                 {
225                           //防止连续除法产生运算误区
226                           op = '/';
227                           if (lastOp == '/')
228                               IsRep = 1;
229                           else
230                               lastOp = '/';
231                           break;
232                 }
233             }
234             formula += op;
235         }
236         
237         //随机生成整数
238         static void Integer(){
239             int num;
240             num = BaseNumber + (int)((Math.random())*(TopNumber - BaseNumber + 1));
241             formula += num;
242         }
243         //创建算式
244         static void CreateNumber(){
245             for (int k = 1; k <= Amount; k++)
246             {
247 
248                 for (int i = 0; i < 2; i++){
249                     if (LBraket[i] == k)
250                         formula += "(";
251                 }
252 
253                 int cho;
254                 cho = (int)((Math.random())*2);
255                 if (cho == 0)
256                 {
257                     Integer();
258                 }
259                 else
260                     Score();
261                 for (int j = 0; j < 2; j++){
262                     if ((RBraket[j] == k) && RBraket[j] != 0)
263                         formula += ")";
264                 }
265                 if (k == Amount)
266                     formula += "=";
267                 else
268                     Operater();
269             }
270         }
271         //检查是否重复及判断括号是否添加正确
272         static int Repeat(int time){
273             buffer[time] = formula;
274             int juege = 0;
275             int trance;
276             for (int i = 0; i < time; i++)
277             {
278                 if (buffer[i] == buffer[time])
279                 {
280                     juege = 1;
281                     break;
282                 }
283             }
284             if (IsBra != 1)
285             {
286                 if (BracketNum == 1)
287                 {
288                     if (LBraket[0] == 1 && RBraket[0] == Amount)
289                         juege = 1;
290                 }
291                 if (BracketNum == 2)
292                 {
293                     if (RBraket[0] < RBraket[1])
294                     {
295                         trance = RBraket[0];
296                         RBraket[0] = RBraket[1];
297                         RBraket[1] = trance;
298                     }
299                     if (LBraket[1] == 1 && RBraket[0] == Amount&&LBraket[0] < RBraket[1])
300                         juege = 1;
301                 }
302             }
303             return juege;
304         }
305         static float EvaluateExpression(){
306             //Stack OPTR=new Stack();
307             //Stack OPND=new Stack();
308             float[] OPND=new float[MAX];
309             char[] OPTR =new char[MAX];
310             int Ntop=0;
311             int Ctop=0;
312             //InitOperStack(OPTR);
313             //OPTR.push("=");
314             OPTR[Ctop++]='=';
315             //PushOper(OPTR, '=');
316             //InitNumStack(OPND);
317             int count = 0;
318             float Num = 0, first, second;
319             char oper1;
320             char bracket1;
321             while (true)
322             {
323                 Num = 0;
324                 //读取数字
325                 while (formula.charAt(count) >= '0'&&formula.charAt(count) <= '9')
326                 {
327                     if (formula.charAt(count) == '0')
328                     {
329                         if (count == 0)
330                             //OPND.push(new Float(0));
331                             OPND[Ntop++]=0;
332                         if (count != 0 && !(formula.charAt(count-1) >= '0'&&formula.charAt(count-1) <= '9'))
333                             //OPND.push(new Float(0));
334                             OPND[Ntop++]=0;
335                     }
336                         
337                     Num = Num * 10;
338                     Num = Num + formula.charAt(count) - 48;
339                     count++;
340                     
341                 }
342                 if (Num > 0)
343                 {
344                     //OPND.push(new Float(Num));
345                     //PushNum(OPND, Num);
346                     OPND[Ntop++]=Num;
347                 }
348                 if (formula.charAt(count) == '='&&OPTR[Ctop-1] == '=')
349                 {
350                     break;
351                 }
352                 //判断运算符优先级
353                 
354                 switch (Precede(OPTR[Ctop-1], formula.charAt(count)))
355                 {
356                     case '<':
357                     {
358                         //OPTR.push(formula.charAt(count));
359                         OPTR[Ctop++]=formula.charAt(count);
360                             //PushOper(OPTR, formula.str()[count]);
361                             count++;
362                             break;
363                     }
364                     case '>':
365                     {
366                             //PopOper(OPTR, oper1);
367                         //oper1=(char) OPTR.pop();
368                         oper1=OPTR[--Ctop];
369                             //PopNum(OPND, second);
370                         //second=(float) OPND.pop();
371                         second=OPND[--Ntop];
372                             //PopNum(OPND, first);
373                         //first=(float)OPND.pop();
374                         first=OPND[--Ntop];
375                             //PushNum(OPND, Operate(first, oper1, second));
376                         //OPND.push(Operate(first, oper1, second));
377                         OPND[Ntop++]=Operate(first, oper1, second);
378                             break;
379                     }
380                     case '=':
381                     {
382                                 //PopOper(OPTR, bracket1);
383                         //bracket1=(char) OPTR.pop();
384                         bracket1=OPTR[--Ctop];
385                                 count++;
386                     }
387                 }
388             }
389             return OPND[Ntop-1];
390         }
391         
392         public static void SetValue(int IsMulDlvExist1,int IsRem1,int IsBra1,int TopNumber1,int BaseNumber1)
393         {
394             IsMulDlvExist=0;
395             BaseNumber=0;
396             TopNumber=10;
397             IsNeg=0;
398             IsRem=0;
399             IsBra=1;
400             
401             
402             
403             IsMulDlvExist=IsMulDlvExist1;
404             TopNumber=TopNumber1;
405             BaseNumber=BaseNumber1;
406             IsRem=IsRem1;
407             IsBra=IsBra1;
408         }
409         public static void SetValue1(int IMDE)
410         {
411             IsMulDlvExist=IMDE;
412         }
413         public static void SetValue2(int Rem)
414         {
415             IsRem=Rem;
416         }
417         public static void SetValue3(int Bra)
418         {
419             IsBra=Bra;
420         }
421         public static void SetValue(int TopNumber1,int BaseNumber1){
422             IsMulDlvExist=0;
423             BaseNumber=0;
424             TopNumber=10;
425             IsNeg=0;
426             IsRem=0;
427             IsBra=1;
428             TopNumber=TopNumber1;
429             BaseNumber=BaseNumber1;
430             
431         }
432         
433         public static int StrToNum(String x)
434         {
435               int num=0;
436                for(int i=0;i<x.length();i++)
437                {
438                        num=num*10+x.charAt(i)-48;
439                }
440                return num;
441         }
442         public static float StrToFloat(String x)
443         {
444             float num=0;
445             int doat=0;
446             int mi=-1;
447             for(int i=0;i<x.length();i++)
448             {
449                 if(x.charAt(i)=='.')
450                 {
451                     doat=1;
452                     continue;
453                 }
454                 if(doat==1)
455                 {
456                     num=(float) (num+(x.charAt(i)-48)*Math.pow(10,mi));
457                     mi--;
458                 }else{
459                     num=num*10+x.charAt(i)-48;
460                 }
461             }
462             return num;
463         
464         }
465         public static float StrToFloat1(String x)
466         {
467             float first=0;
468             float second=0;
469             int point=0;
470             for(int i=0;i<x.length();i++)
471             {
472                 if(x.charAt(i)=='/')
473                 {
474                     point=1;
475                     continue;
476                 }
477                 if(point==1)
478                 {
479                     second=second*10+x.charAt(i)-48;
480                 }else
481                 {
482                     first=first*10+x.charAt(i)-48;
483                 }
484             }
485             return (first/second);
486         }
487         static int ma()
488         {
489             int OutChoose = 0;
490             int truenum = 0;
491             int choose;
492             boolean flag = true;                       
493             int range = 0;
494             
495             //IsMulDlvExist=1;
496             //BaseNumber=0;
497             //TopNumber=10;
498             //IsNeg=0;
499             //IsRem=0;
500             //IsBra=0;
501             
502             
503             /*cout << "            欢迎来到四则运算答题系统!" << endl;
504             cout << "说明:\n\t初级只有加减法无括号无负数无余数(默认数值范围0-5)\n\t中级有乘除有括号无负数无余数(默认范围0-20)\n\t高级有乘除有括号有负数有余数(默认范围0-100)" << endl;
505             while (flag)
506             {
507                 cout << "现在有初级,中级,高级,三种关卡,你要挑战哪一关?" << endl;
508                 cout << "1.初级  2.中级  3.高级     请选择:";
509                 cin >> choose;
510                 switch (choose)
511                 {
512                 case 1:
513                 {
514                           cout << "是否打印试卷?0、否  1、是  请选择 : ";
515                           cin >> OutChoose;
516                           cout << "是否需要数值重设范围?0、否  1、是  请选择 : ";
517                           cin >> range;
518                           IsMulDlvExist = 0;
519                           BaseNumber = 0;
520                           TopNumber = 5;
521                           if (range == 1){
522                               cout << "请输入下限(正数):";
523                               cin >> BaseNumber;
524                               cout << "请输入上限(正数):";
525                               cin >> TopNumber;
526                           }
527                           IsNeg = 1;
528                           IsRem = 1;
529                           IsBra = 1;
530                           flag = false;
531                           break;
532                 }
533                 case 2:
534                 {
535                           cout << "是否打印试卷?0、否  1、是  请选择 : ";
536                           cin >> OutChoose;
537                           cout << "是否需要数值重设范围?0、否  1、是  请选择 : ";
538                           cin >> range;
539                           IsMulDlvExist = 1;
540                           BaseNumber = 0;
541                           TopNumber = 20;
542                           if (range == 1){
543                               cout << "请输入下限(正数):";
544                               cin >> BaseNumber;
545                               cout << "请输入上限(正数):";
546                               cin >> TopNumber;
547                           }
548                           IsNeg = 1;
549                           IsRem = 1;
550                           IsBra = 0;
551                           flag = false;
552                           break;
553                 }
554                 case 3:
555                 {
556                           cout << "是否打印试卷?0、否  1、是  请选择 : ";
557                           cin >> OutChoose;
558                           cout << "是否需要数值重设范围?0、否  1、是  请选择 : ";
559                           cin >> range;
560                           IsMulDlvExist = 1;
561                           BaseNumber = 0;
562                           TopNumber = 100;
563                           if (range == 1){
564                               cout << "请输入下限(正数):";
565                               cin >> BaseNumber;
566                               cout << "请输入上限(正数):";
567                               cin >> TopNumber;
568                           }
569                           IsNeg = 0;
570                           IsRem = 0;
571                           IsBra = 0;
572                           flag = false;
573                           break;
574                 }
575                 default:
576                 {
577                            cout << "输入有误,请重新选择:" << endl;
578                            flag = true;
579                            break;
580                 }
581                 }
582 
583             }
584             */
585 
586 
587             //float sum = 0;
588             for (int i = 0; i < 30; i++)
589             {
590                 lastOp = '+';
591                 IsRep = 0;
592                 NumberAmount();
593                 if (IsBra == 0)
594                 {
595                     AddLbracket();
596                     AddRbracket();
597                 }
598                 CreateNumber();
599                 Result[i] = EvaluateExpression();                    
600                 while (Repeat(i) == 1 || IsRep == 1 || (IsNeg == 1 && (Result[i] < 0 || Result[i] == -0)) || (IsRem == 1 && ((int)(Result[i]*10000))%10000!=0))
601                 {
602 
603                     IsRep = 0;
604                     lastOp = '+';
605                     formula="";
606                     NumberAmount();
607                     if (IsBra == 0)
608                     {
609                         AddLbracket();
610                         AddRbracket();
611                     }
612                     CreateNumber();
613                     Result[i] = EvaluateExpression();                    
614                 }
615                 buffer[i]=formula;
616                 formula="";
617             }
618 
619             return 0;
620         }
621         public static float css(int number){
622             return Result[number];
623         }
624         public static String cs(int number){
625             return buffer[number];
626         }
627     public static void main()
628     {
629         int a;
630         a=ma();
631         for (int i = 0; i < 30; i++)
632         {
633             System.out.println(buffer[i]+Result[i]);
634         }
635         
636     }
637 }

结果截图:

 

 

转载于:https://www.cnblogs.com/liying123/p/5374720.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值