White box test example-2 answers from students

Source: Internet
Author: User

Original article, copyright belongs to Hu Tian Fa (hutianfa@163.com) All, reprint please indicate the source:
Http://blog.csdn.net/aidisheng/archive/2008/09/02/2868712.aspx

 

In the course of teaching, it was not a good habit that many students thought it was very easy to see this requirement and immediately began to write code. If your first instinct is the same, you may wish to see the end of the article with patience.

Thoughts of most students:

1. First, create a main function. The first thing of the main function is to prompt the user to enter the three sides of the triangle and then obtain the user's input (assuming that the user's input is an integer ), it is written in C language. This step is basically not a problem (printf and scanf). But if you want to write it in Java, many students will encounter problems immediately, java5.0 and earlier versions are not easy to obtain users' input.

Comments:The program created in this way can only test all business logic manually, and the program can only be a DOS interface version. If you want to use a graphical interface for input, you have to write all the code.

2. The business processing process is shown in a flowchart as follows:

 

 

3. C language code:

  1. # Include <stdio. h>
  2. Void main ()
  3. {
  4. Int A, B, C;
  5. Printf ("Please enter three INTEGER :");
  6. Scanf ("% d", & A, & B, & C );
  7. If (0 <A & A <200 & 0 <B & B <200 & 0 <C & C <200)
  8. {
  9. If (a + B> C & A + C> B & C + B>)
  10. {
  11. If (A = B & B = C & A = C) // a judgment can be omitted here.
  12. {
  13. Printf ("1 is an equilateral triangle ");
  14. }
  15. Else
  16. {
  17. If (A = B | B = c | A = C)
  18. {
  19. Printf ("2 is an isosceles triangle ");
  20. }
  21. Else
  22. {
  23. If (A * A + B * B = C * c | A * A + C * c = B * B | B * B + C * c = *)
  24. {
  25. Printf ("3 is a right triangle ");
  26. }
  27. Else
  28. {
  29. Printf ("4 is a normal triangle ");
  30. }
  31. }
  32. }
  33. }
  34. Else
  35. {
  36. Printf ("5 cannot form a triangle ");
  37. }
  38. }
  39. Else
  40. {
  41. Printf ("6 some sides do not meet the limit ");
  42. }
  43. }

Comments: The program created in this way can only test all business logic manually, and this program can only be a DOS interface version. If you want to use a web or graphical interface for input, you have to write all the code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.