15 กันยายน 2556

..# condition #..

..# condition #..


Easy   P.292 /1
Assume you want to create a program that displays the message “Highest honors” when a student’s test score is 90 or above. When the test score is 70 through 89, the program should displays the message “Good job”. For all other test score, the program should displays the message “Retake the test”. Write the pseudocode for this program’s selection structure.
Answer
          if (score >= 90)
                         display “Highest honors”
                    else
                         if (score >=70)
                              display “Good job”
                    else
                              display “Retake the test”
                    end if
                         end if


Middle   P.292 /2
Write the C++ code that corresponds to the pseudocode you wrote in Question 1. The student’s score is stored in an int variable named score.
Answer          int score = 80;  // ประกาศและกำหนดค่าตัวแปร score
                   if (score >= 90) {  // เงื่อนไขที่ถ้า score มากกว่าหรือเท่ากับ 90
                        println("Highest honors");  // ปริ๊น Highest honors
                   }
                   else
                        if (score >= 70) {  // เงื่อนไขที่ถ้าไม่ใช่แล้ว score มากกว่าหรือเท่ากับ 70
                             println ("Good job");  // ปริ๊น Good job
                        }
                   else {  // เงื่อนไขที่ถ้า score น้อยกว่า 70
                        println ("Retake the test");  // ปริ๊น Retake the test
                    } // end if
                  

Hard   P.309 /1
Write the C++ if statement that compares the contents of the quantiry variable to the number 10. If the  quantity variable contains a number that id equal to 10, display the string “Equal”. If the quantity variable contains a number that is greater than 10, display string “Over 10”. If the quantity variable contains a number that is less than 10, display the string “Not over 10”.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น