Skip to content

平成23年度 特別試験 ITパスポート試験 問94

This question's explanation and your answers so far.

問94
頻出度★★★

Q社のRさんは,チケット販売システムの開発で使用する関数のプログラミングとテストを実施しようとしている。この関数は,大人と子供のチケットの購入希望枚数を基に,合計金額の計算を行う。大人のチケットは3,000円,子供のチケットは1,000円である。一度に購入できる大人と子供のチケットの最高枚数は,それぞれ20枚までであり,関数はこの購入条件を満たしているかどうかをチェックする。また,合計で20枚以上購入する場合,割引処理を行う。関数の仕様と処理内容は次のとおりである。 〔関数の仕様〕 関数に渡される引数  J:大人のチケットの購入希望枚数,K:子供のチケットの購入希望枚数  (J,Kは0以上の整数) 関数の戻り値  L:合計金額 (Lは整数) 〔処理内容〕 (1) 購入希望枚数を基に,購入条件を満たしているかどうかを判定する。購入条件を満たしていない場合,合計金額に−1を代入する。 (2) 購入条件を満たしている場合,引数を基に次のとおりに合計金額の計算を行う。   合計金額 = 大人のチケットの購入希望枚数×3,000+子供のチケットの購入希望枚数×1,000 (3) チケットを合計で20枚以上購入した場合は,合計金額から1割を割り引く。 関数のテストを行うために,条件のすべての組合せと処理を整理したものを表1に示す。表1のb,cに入れる適切な字句の組合せはどれか。 表1 条件のすべての組合せと処理

①②③④⑤⑥⑦⑧
条件Jが0以上20以下YYNNYYNN
条件Kが0以上20以下YYYYNNNN
条件J+Kが20より小さいYNYNYNYN
処理合計金額を求めるXX
処理合計金額を1割引とする-b
処理合計金額に−1を代入する--c

注記1 網掛けの部分は,表示していない。 注記2 Yは条件に該当し,Nは条件に該当しない。Xは処理を実行し,-は処理を実行しない。例えば①の場合,三つの条件に対する結果が,Y,Y,Yとなったとき,合計金額を求める処理が実行されることを示す。

出典 平成23年度 特別試験 ITパスポート試験 問94
解説

問 94

  • ア

    正解 The correct answer is ア (b:X, c:X). Table 1 is a decision table: the condition section in the upper half lists all Y/N combinations of the three conditions (2 to the 3rd power = 8 patterns) as columns ① to ⑧, and the processing section in the lower half shows the processing to be executed in each column with X (execute) / - (do not execute). First, find b. The columns where condition 1 “J is between 0 and 20 inclusive” and condition 2 “K is between 0 and 20 inclusive” are both Y — that is, where both arguments are within the normal range — are only ① and ②, and the only difference between them is whether condition 3 “J+K is less than 20” is Y or N. In ①, Calculate the total amount = X, 10% discount = -, Assign −1 = -; and ② is the same as ① in that Calculate the total amount = X and Assign −1 = -. If b were -, then ① and ② would have exactly the same processing, and condition 3 would become a meaningless condition that changes nothing in the result. Furthermore, the processing “Apply a 10% discount to the total amount” would not be executed in either ① or ② (from ③ onward are the abnormal cases where J or K is out of range), so there would be no point in deliberately listing it as a processing row in the decision table. Therefore b = X, and the specification of this function can be read as: when both J and K are within the normal range and J+K is 20 or more (a bulk purchase), the total amount is given a 10% discount. Next, find c. In column ④, condition 1 = N, meaning J is outside the range of 0 to 20 inclusive, so this is a case with an invalid argument. “Assign −1 to the total amount” is error handling that notifies the caller with the abnormal value −1 that the calculation could not be performed normally, and indeed it is - in ① and ②, where both arguments are normal. If it were not executed in ④, which is out of range, the action of returning an abnormal value would never take effect anywhere, and an invalid argument would simply be overlooked. Therefore c = X. The combination b = X, c = X is ア.

  • Incorrectイ

    b:X is correct, but c:- is wrong. In column ④, “J is between 0 and 20 inclusive” = N, so this is an abnormal case in which the argument J falls outside the valid range. If “Assign −1 to the total amount” is not executed here (-), then no processing at all would be executed in ④, and even when an invalid argument is passed, the processing would end without telling the caller anything. Assigning −1 is error handling for returning an abnormal value that indicates the calculation is impossible, and it is precisely in the columns where the argument is out of range that it should be executed, so c must be X.

  • Incorrectウ

    c:X is correct, but b:- is wrong. The only columns where condition 1 and condition 2 are both Y (both J and K within the normal range) are ① and ②, and if b is filled in as -, the processing in ① and ② becomes completely identical: Calculate the total amount = X, 10% discount = -, Assign −1 = -. Condition 3 “J+K is less than 20” would then become a redundant condition with no influence on the result, which contradicts the premise of a decision table that organizes all combinations for testing. In addition, the processing “Apply a 10% discount to the total amount” would not be executed in any of the normal-case columns among ① to ⑧, so there would be no meaning in providing that processing row. Therefore b is X.

  • Incorrectエ

    Both b:- and c:- are wrong; this option stacks the errors of イ and ウ together. Filling in b as - makes the processing of ① and ② identical, so condition 3 loses its meaning and the 10% discount processing is never executed even once. Filling in c as - means the abnormal value −1 is not set in column ④, where the argument J is out of range, so the error cannot be detected. In a decision table, the principle is that every condition listed should produce a difference in processing in some column and every processing listed should be executed in some column, and this option violates both.

ここがポイント
  • How to read a decision table — the condition section in the upper part enumerates all combinations of Y (the condition is met) / N (the condition is not met) for the conditions, and the processing section in the lower part shows the processing to be executed in each column with X (execute) / - (do not execute). If there are n conditions, there are 2 to the n-th power columns; this question has 3 conditions, so there are 8 columns, ① to ⑧. Because it organizes the correspondence between condition combinations and processing without omission or duplication, it is used for checking specifications and for designing test cases in black-box testing.
  • The logic for filling in the blanks — in a decision table, the principle is that a condition that is listed should produce a difference in processing in some column, and processing that is listed should be executed in some column. A way of filling in the blanks that makes the processing of two columns differing only in a condition value (① and ②) completely identical would render that condition redundant, and is therefore wrong. Also, for a column that falls outside the argument range check (between 0 and 20 inclusive), the standard approach is to execute the processing that returns an abnormal value indicating the calculation is impossible (here, −1).
用語

Your answers