Skip to content

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

This question's explanation and your answers so far.

問96
頻出度★★☆

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日券,2日券といった日数の異なる種類のチケットの金額計算に対応できるように,〔処理内容〕の(2)及び関数の仕様を変更し,引数にチケットの日数を表すMを追加した。Mには使用できる日数が入る。種類別のチケット金額を設定する配列をTP(M, N)とする。Nは大人の場合は1,子供の場合は2とする。配列の値は次のとおりである。引数がJ=10, K=20, M=2のときの合計金額は何円か。 なお,関数は,引数に応じてこの配列を参照し,チケット金額を決定する。 〔配列の値〕 TP(1, 1) = 3,000, TP(1, 2) = 1,000, TP(2, 1) = 4,000, TP(2, 2) = 1,500, TP(3, 1) = 5,000, TP(3, 2) = 2,000

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

問 96

※ Our check while writing this explanation could not fully confirm the published answer; scoring follows IPA's official key.

  • Incorrectア

    This ignores M=2 (the 2-day ticket), calculates with the 1-day prices TP(1, 1)=3,000 yen and TP(1, 2)=1,000 yen, and then applies the 10% discount: (3,000×10 + 1,000×20)×0.9 = 50,000×0.9 = 45,000 yen. The discount processing in (3) is applied correctly, but the meaning of the argument M was overlooked: M is the number of days that can be used, and it decides the first argument of the array TP(M, N), that is, which row to look up. As a result the TP(1, N) row was used. Since M=2, the row to use is TP(2, N).

  • Incorrectイ

    This misses both the row selection and the discount. It computes 3,000×10 + 1,000×20 = 50,000 yen with the 1-day prices and takes that directly as the answer. Since M=2 is specified, TP(2, 1)=4,000 yen and TP(2, 2)=1,500 yen must be used, and since J+K = 30 tickets, the 10% discount in (3) must also be applied. Two pieces of processing are missing, so it is wrong.

  • ウ

    正解 The correct answer is ウ, 63,000 yen. This question builds on the shared premise of sub-group B (questions 93 to 96). The shared [processing details] have three stages: (1) if the purchase conditions (0 to 20 tickets for both adults and children) are not met, assign −1 to the total amount; (2) if they are met, compute total amount = number of adult tickets × adult price + number of child tickets × child price; (3) if 20 or more tickets are purchased in total, take 10% off the total amount. This question changed only (2): instead of fixed prices (3,000 yen for an adult, 1,000 yen for a child), the price is looked up in the array TP(M, N). In other words, the purchase-condition check in (1) and the 10% discount in (3) are still in force. Now substitute J=10 (number of adult tickets), K=20 (number of child tickets), and M=2 (2-day ticket). First (1): both J=10 and K=20 are between 0 and 20, so the purchase conditions are met and the value does not become −1. Next (2): the row to refer to is the M=2 row, that is TP(2, 1)=4,000 yen (2-day, adult) and TP(2, 2)=1,500 yen (2-day, child). The total before the discount is 10×4,000 + 20×1,500 = 40,000 + 30,000 = 70,000 yen. Finally (3): the total number of tickets is J+K = 10+20 = 30, which is 20 or more, so the 10% discount applies: 70,000×0.9 = 63,000 yen. Whether you can carry out both steps — picking the M=2 row in the array lookup, and always running the unchanged 10% discount at the end — is the key point of this question.

  • Incorrectエ

    The array lookup is correct: TP(2, 1)=4,000 yen and TP(2, 2)=1,500 yen are taken from the M=2 row. However, 10×4,000 + 20×1,500 = 70,000 yen is the amount before the discount, and the 10% discount in (3) of the [processing details] has been forgotten. Only the price calculation in (2) was changed in this question, so the discount processing in (3) is still in force; since J+K = 30 tickets (20 or more), the 10% discount must be applied. The answer is 70,000×0.9 = 63,000 yen, and this is the easiest wrong answer to fall for.

ここがポイント
  • In a question that changes a specification, the rule of thumb is to separate what was changed from what was not. Here the only change is the price calculation in (2) of the [processing details] (fixed prices → a lookup in the array TP); the purchase-condition check in (1) and the 10% discount for 20 or more tickets in (3) remain in force just as they were. If you drop a piece of processing that was not changed, the calculation will not come out right.
  • When looking up the two-dimensional array TP(M, N), read the correspondence exactly: the first argument M is the number of days of the ticket (the row), and the second argument N is adult = 1 and child = 2 (the column). When M=2, use only the pair TP(2, 1) and TP(2, 2), and do not look up TP(1, *) or TP(3, *). If you mistake the order or the meaning of the arguments, you will pick up a completely different price.
用語

Your answers