Skip to content

令和7年度 ITパスポート試験 問99

This question's explanation and your answers so far.

問99
頻出度★★☆

関数 calculateAmountOfPrize は,業務改善の効果における改善額と短縮期間を,それぞれ improvement と period で受け取り,賞金額を戻り値とする。改善額が20万円で短縮期間が3日の業務改善と,改善額が5万円で短縮期間が14日の業務改善があった。この二つの賞金額の合計は何円か。ここで,改善額と短縮期間の値はそれぞれ0以上とする。 〔プログラム〕 ○整数型: calculateAmountOfPrize(整数型: improvement, // 改善額(円) 整数型: period) // 短縮期間(日) 整数型: prize // 賞金額(円) if (improvement が 100000 より小さい) if (period が 7 より小さい) prize ← 500 else prize ← 1000 endif else if (period が 7 より小さい) prize ← 2000 else prize ← 5000 endif endif return prize

出典 令和7年度 ITパスポート試験 問99
解説

問 99

  • Incorrectア

    1,000 yen is merely the prize amount of the second case alone (improvement amount 50,000 yen, shortened period 14 days). It forgets to add the 2000 yen of the first case (improvement amount 200,000 yen, shortened period 3 days), so it is not the total of the two.

  • Incorrectイ

    1,500 yen is obtained by misjudging the first case as 500 yen and adding it to the 1000 yen of the second case, giving 500+1000=1500. The improvement amount of the first case, 200,000 yen, does not satisfy «less than 100000» and should go to the else side, so the correct value is 2000 yen rather than 500 yen; this is an error of getting the outer decision backwards.

  • ウ

    正解 The program is a function with four branches in total: the outer if divides improvement (the improvement amount) at 100,000 yen, and the inner if divides period (the shortened period) at 7 days. For the first case the improvement amount is 200,000 yen (=200000), which does not satisfy «less than 100000», so it goes to the else side; the shortened period of 3 days satisfies «less than 7», so prize←2000, that is 2000 yen. For the second case the improvement amount is 50,000 yen (=50000), which satisfies «less than 100000», so it goes to the first if side; the shortened period of 14 days does not satisfy «less than 7», so it goes to else and prize←1000, that is 1000 yen. Therefore the total of the two prize amounts is 2000+1000=3000 yen, and the correct answer is ウ (3,000).

  • Incorrectエ

    5,500 yen is obtained by misjudging the first case as the maximum amount of 5000 yen and the second case as 500 yen, then adding them to give 5000+500=5500. The first case's shortened period of 3 days satisfies «less than 7», so it should be 2000 yen; the second case's shortened period of 14 days does not satisfy it, so it should be 1000 yen; this is an error of getting the inner decision backwards.

ここがポイント
  • For the nested if-else selection structure, trace it line by line in the order «outer condition (whether the improvement amount is less than 100000) → inner condition (whether the shortened period is less than 7)», and identify the one correct return value out of the four branches.
  • «Less than (<)» is a strict inequality that does not include equality, and its else side means «greater than or equal to». The key to answering correctly is not to mistake the boundary values exactly equal to 100000 or 7, nor the direction of the inequality.
用語

Your answers