Skip to content

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

This question's explanation and your answers so far.

問73
頻出度★★★

表のセルA1~C2に値が入力されている。表の値をCSV形式で出力した結果はどれか。ここで,レコード間の区切りは改行コード“CR”を使用するものとする。

ABC
1月1月2月
2売上高500600
出典 平成23年度 特別試験 ITパスポート試験 問73
解説

問 73

  • ア

    正解 The correct answer is ア. CSV stands for Comma Separated Values, and just as the name says, it is a text-format way of representing data that uses a comma at the boundary between one item and the next. The correspondence used when converting a table into CSV is best understood in two steps. First, one row of the table becomes one record (one line of data) exactly as it is. Second, within that record, the value of each cell lined up from left to right becomes one field, and the fields are separated from one another by commas. A line break is then placed at the boundary between one record and the next. In this question, the stem states explicitly that the newline code “CR” is used for that line break. Now apply this rule to the table in the figure. The table has 2 rows and 3 columns. Row 1 is A1 = Month, B1 = January, C1 = February, so the first record is Month,January,February. The record ends here, so CR is placed. Row 2 is A2 = Sales, B2 = 500, C2 = 600, so the second record is Sales,500,600, and CR is added at its end as well. The numbers 500 and 600 are lined up just as they are, the same as strings, with no special quotation marks attached. Putting all of this together gives Month,January,February CR Sales,500,600 CR, which matches the content of ア exactly. Note also that the 1 and 2 along the left edge of the table and the A, B, and C along the top are row numbers and column numbers indicating cell positions, not values entered into the table, so they are not included in the output. Therefore the correct answer is ア.

  • Incorrectイ

    The fact that the separator is a comma is correct for CSV, but outputting the rows and columns swapped is the mistake. イ is Month,Sales CR January,500 CR February,600 CR, which treats column A of the table (Month, Sales) as the first record, column B (January, 500) as the second record, and column C (February, 600) as the third record — in other words, output with the vertical and horizontal axes transposed. CSV is a format that writes out the rows of the table in order as records just as they are, so a table of 2 rows and 3 columns should produce 2 records of 3 fields each. イ instead has 3 records of 2 fields each and fails to reproduce the arrangement of the original table, so it is wrong.

  • Incorrectウ

    The correspondence between rows and records (row 1 as the first record, row 2 as the second record) is correct, but using a slash instead of a comma as the field separator is the mistake. ウ is Month/January/February CR Sales/500/600 CR. CSV means Comma Separated Values — that is, comma-separated — and this is the very definition of the format, so something with the separator changed to a different symbol cannot be called CSV. For reference, a format that uses the tab character as the separator is called TSV (Tab Separated Values) and is distinguished from CSV.

  • Incorrectエ

    This is a choice in which both the separator and the ordering are wrong. エ is Month/Sales CR January/500 CR February/600 CR, which, like ウ, separates the items with slashes rather than commas, and, like イ, outputs the table with its rows and columns swapped. It does not satisfy the comma separation that CSV requires, and it also fails to reproduce the 2-row, 3-column structure of the original table, so it is wrong on two counts.

ここがポイント
  • The definition of CSV (Comma Separated Values) — a text format that lays out table-form data with the items (fields) separated from one another by commas and the records (rows) separated from one another by line breaks. As a general-purpose data-exchange format that does not depend on any particular software, it is widely used for input and output in spreadsheet software and databases. It is distinguished from TSV, which uses tabs as the separator.
  • The rule for converting a table into CSV — one row of the table becomes one record as it is, and the cell values of that row are joined with commas from left to right to form one line of data. The rows and columns must not be swapped. In addition, the row numbers and column headings (A, B, C and 1, 2) are markers showing cell positions, not values that were entered, so they are not included in the output.
用語

Your answers