


Software Engineering Pairing Assignment 02, Software Engineering Pairing 02_PHP Tutorial
Jul 12, 2016 am 08:55 AMSoftware Engineering Pairing Assignment 02, Software Engineering Pairing 02
1. Design Idea:
I used php to implement the main functions of this task. By default, addition and subtraction must be included.
First, create the index.php file and create a form in the HTML statement. The content of the form includes the number of questions and the maximum and minimum values. , and some other options.
Then, create the rubric.php file, submit the form information to this file, and call the passed value when implementing the four arithmetic operations methods. The method of implementing the four arithmetic operations is similar to the method used when using Java several times before. The code has been modified and optimized. Put the questions and answers into the question.txt and answer.txt files respectively for later use.
Third, create submitAnswer.php, acceptAnswer.php, deleteAnswer.php and judgeAnswer.php files are used to submit answers online, receive answers, delete answers and judge answers respectively. The submitted answers are placed in the answer1.txt file. The answers are judged by comparing answer.txt and The content in the answer1.txt file is enough.
2. Source program code

41
43 44 72
"; 410 $d[$i]=$b[$i]."n "; 411 $e[$i]=$r->r1."n"; 412 fwrite($question,$d[$i]); 413 fwrite($answer,$e[$i]); 414 } 415 fclose($question); 416 fclose($answer); 417 }418 419 /* Addition, subtraction and multiplication of two numbers */ 420 if(($num1==2) && ($mul=='t') && ($ div=='f')) 421 { 422 $question = fopen("question.txt", "w"); 423 $answer= fopen("answer.txt", "w"); 424 for($i=0;$i<$num;$i ) 425 { 426 $j=0; 427 $bool=true; 428 $b[$i]= addSubMul($min, $max, $num1, $r); 429 while(($r->r1)<0) //When the result is When negative, re-random 430 { 431 $b[$i]= addSubMul($min, $max, $num1, $r); 432 } 433 while(($bool) && ($i!=0))//Avoid duplication 434 { 435 while($b[$i]==$b[ $j]) 436 { 437 $b[$i]= addSubMul($min, $max, $num1, $r); 438 while(($r->r1)<0)//The result is negative , re-write the question 439 { 440 $b[$i]= addSubMul($min, $max, $num1, $r); 441 } 442 $j=0; 443 } 444 $j ; 445 if($j==$i) 446 { 447 $bool=false; 448 } 449 } 450 echo "( ".($i 1)." )??".$b[ $i]."
"; 451 $d[$i]=$b[$i]."n "; 452 $e[$i]=$r->r1."n"; 453 fwrite($question,$d[$i]); 454 fwrite($answer,$e[$i]); 455 } 456 fclose($question); 457 fclose($answer); 458 }459 460 /* Addition, subtraction and division of two numbers */ 461 if(($num1==2) && ($mul=='f') && ($ div=='t')) 462 { 463 $question = fopen("question.txt", "w"); 464 $answer= fopen("answer.txt", "w"); 465 for($i=0;$i<$num;$i ) 466 { 467 $j=0; 468 $bool=true; 469 $b[$i]= addSubDiv($min, $max, $num1, $r); 470 while(($r->r1)<0) //When the result is When negative, re-random 471 { 472 $b[$i]= addSubDiv($min, $max, $num1, $r); 473 } 474 while(($bool) && ($i!=0))//Avoid duplication 475 { 476 while($b[$i]==$b[ $j]) 477 { 478 $b[$i]= addSubDiv($min, $max, $num1, $r); 479 while(($r->r1)<0)//The result is negative , re-write the question 480 { 481 $b[$i]= addSubDiv($min, $max, $num1, $r); 482 } 483 $j=0; 484 } 485 $j ; 486 if($j==$i) 487 { 488 $bool=false; 489 } 490 } 491 echo "( ".($i 1)." )??".$b[ $i]."
"; 492 $d[$i]=$b[$i]."n "; 493 $e[$i]=$r->r1."n"; 494 fwrite($question,$d[$i]); 495 fwrite($answer,$e[$i]); 496 } 497 fclose($question); 498 fclose($answer); 499 }500 501 /* Addition, subtraction, multiplication and division of two numbers */ 502 if(($num1==2) && ($mul=='t') && ($ div=='t')) 503 { 504 $question = fopen("question.txt", "w"); 505 $answer= fopen("answer.txt", "w"); 506 for($i=0;$i<$num;$i ) 507 { 508 $j=0; 509 $bool=true; 510 $b[$i]= addSubMulDiv($min, $max, $num1, $r); 511 while(($r->r1)<0)//The result is negative , re-write the question 512 { 513 $b[$i]= addSubMulDiv($min, $max, $num1, $r); 514 } 515 while(($bool) && ($i!=0))//Judgment of duplication 516 { 517 while($b[$i]==$b[ $j]) 518 { 519 $b[$i]= addSubMulDiv($min, $max, $num1, $r); 520 while(($r->r1)<0)//The result is negative , re-write the question 521 { 522 $b[$i]= addSubMulDiv($min, $max, $num1, $r); 523 } 524 $j=0; 525 } 526 $j ; 527 if($j==$i) 528 { 529 $bool=false; 530 } 531 } 532 echo "( ".($i 1)." )??".$b[ $i]."
"; 533 $d[$i]=$b[$i]."n "; 534 $e[$i]=$r->r1."n"; 535 fwrite($question,$d[$i]); 536 fwrite($answer,$e[$i]); 537 } 538 fclose($question); 539 fclose($answer); 540 }541 542 /* Addition and subtraction of three numbers */ 543 if(($num1==3) && ($mul=='f') && ($ div=='f')) 544 { 545 $question = fopen("question.txt", "w"); 546 $answer= fopen("answer.txt", "w"); 547 for($i=0;$i<$num;$i ) 548 { 549 $j=0; 550 $bool=true; 551 $b[$i]= addSub($min, $max, $num1, $r); 552 while(($r->r1)<0)//The result is negative , re-write the question 553 { 554 $b[$i]= addSub($min, $max, $num1, $r); 555 } 556 while(($bool) && ($i!=0))//Judgment of duplication 557 { 558 while($b[$i]==$b[ $j]) 559 { 560 $b[$i]= addSub($min, $max, $num1, $r); 561 while(($r->r1)<0)//The result is negative , re-write the question 562 { 563 $b[$i]= addSub($min, $max, $num1, $r); 564 } 565 $j=0; 566 } 567 $j ; 568 if($j==$i) 569 { 570 $bool=false; 571 } 572 } 573 echo "( ".($i 1)." )??".$b[ $i]."
"; 574 $d[$i]=$b[$i]."n "; 575 $e[$i]=$r->r1."n"; 576 fwrite($question,$d[$i]); 577 fwrite($answer,$e[$i]); 578 } 579 fclose($question); 580 fclose($answer); 581 }582 583 /* Addition, subtraction and multiplication of three numbers */ 584 if(($num1==3) && ($mul=='t') && ($ div=='f')) 585 { 586 $question = fopen("question.txt", "w"); 587 $answer= fopen("answer.txt", "w"); 588 for($i=0;$i<$num;$i ) 589 { 590 $j=0; 591 $bool=true; 592 $b[$i]= addSubMul($min, $max, $num1, $r); 593 while(($r->r1)<0)//The result is negative , re-write the question 594 { 595 $b[$i]= addSubMul($min, $max, $num1, $r); 596 } 597 while(($bool) && ($i!=0))//Judgment of duplication 598 { 599 while($b[$i]==$b[ $j]) 600 { 601 $b[$i]= addSubMul($min, $max, $num1, $r); 602 while(($r->r1)<0)//The result is negative , re-write the question 603 { 604 $b[$i]= addSubMul($min, $max, $num1, $r); 605 } 606 $j=0; 607 } 608 $j ; 609 if($j==$i) 610 { 611 $bool=false; 612 } 613 } 614 echo "( ".($i 1)." )??".$b[ $i]."
"; 615 $d[$i]=$b[$i]."n "; 616 $e[$i]=$r->r1."n"; 617 fwrite($question,$d[$i]); 618 fwrite($answer,$e[$i]); 619 } 620 fclose($question); 621 fclose($answer); 622 }623 624 /* Addition, subtraction and division of three numbers */ 625 if(($num1==3) && ($mul=='f') && ($ div=='t')) 626 { 627 $question = fopen("question.txt", "w"); 628 $answer= fopen("answer.txt", "w"); 629 for($i=0;$i<$num;$i ) 630 { 631 $j=0; 632 $bool=true; 633 $b[$i]= addSubDiv($min, $max, $num1, $r); 634 while(($r->r1)<0)//The result is negative , re-write the question 635 { 636 $b[$i]= addSubDiv($min, $max, $num1, $r); 637 } 638 while(($bool) && ($i!=0))//Judgment of duplication 639 { 640 while($b[$i]==$b[ $j]) 641 { 642 $b[$i]= addSubDiv($min, $max, $num1, $r); 643 while(($r->r1)<0)//The result is negative , re-write the question 644 { 645 $b[$i]= addSubDiv($min, $max, $num1, $r); 646 } 647 $j=0; 648 } 649 $j ; 650 if($j==$i) 651 { 652 $bool=false; 653 } 654 } 655 echo "( ".($i 1)." )??".$b[ $i]."
"; 656 $d[$i]=$b[$i]."n "; 657 $e[$i]=$r->r1."n"; 658 fwrite($question,$d[$i]); 659 fwrite($answer,$e[$i]); 660 } 661 fclose($question); 662 fclose($answer); 663 }664 665 /* Addition, subtraction, multiplication and division of three numbers */ 666 if(($num1==3) && ($mul=='t') && ($ div=='t')) 667 { 668 $question = fopen("question.txt", "w"); 669 $answer= fopen("answer.txt", "w"); 670 for($i=0;$i<$num;$i ) 671 { 672 $j=0; 673 $bool=true; 674 $b[$i]= addSubMulDiv($min, $max, $num1, $r); 675 while(($r->r1)<0)//The result is negative , re-write the question 676 { 677 $b[$i]= addSubMulDiv($min, $max, $num1, $r); 678 } 679 while(($bool) && ($i!=0))//Judgment of duplication 680 { 681 while($b[$i]==$b[ $j]) 682 { 683 $b[$i]= addSubMulDiv($min, $max, $num1, $r); 684 while(($r->r1)<0)//The result is negative , re-write the question 685 { 686 $b[$i]= addSubMulDiv($min, $max, $num1, $r); 687 } 688 $j=0; 689 } 690 $j ; 691 if($j==$i) 692 { 693 $bool=false; 694 } 695 } 696 echo "( ".($i 1)." )??".$b[ $i]."
"; 697 $d[$i]=$b[$i]."n "; 698 $e[$i]=$r->r1."n"; 699 fwrite($question,$d[$i]); 700 fwrite($answer,$e[$i]); 701 } 702 fclose($question); 703 fclose($answer); 704 } 705 706 /* Addition and subtraction of four numbers */ 707 if(($num1==4) && ($mul=='f') && ($ div=='f')) 708 { 709 $question = fopen("question.txt", "w"); 710 $answer= fopen("answer.txt", "w"); 711 for($i=0;$i<$num;$i ) 712 { 713 $j=0; 714 $bool=true;

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach
