• Home
  • Article
  • Bug detection drill (1) "Let's find a bug": Tsuneo Yamaura's "Kumikomi" story (101) (page 1/4)

Bug detection drill (1) "Let's find a bug": Tsuneo Yamaura's "Kumikomi" story (101) (page 1/4)

※写真はイメージです

 When I was a student, I went to a 5 -story ultra -large bookstore, but about 20 books related to computers.If the bookshelf with a width of 1m is one step, it has fit enough.The interest in the information processing at that time was incredibly low, and the book corner of "Intelligence Spy Activities" was lined with "Information Processing Engineers" for examinations, saying, "Computers are still before dawn.I remember being sad.

 Nowadays, it has become commonplace that computers books are lined up on the entire shelf, even in small bookstores.The most common is a practical book in programming languages such as C and C ++.Some books contain grammar and simple coding, and some have a collection of problems such as "fill the appropriate command language in a blank line."

 What I always wonder is, "Why is there a collection of coding questions, but why is there a collection of debugs?"The specifications of the program written in a few lines and the corresponding source code are presented about 20 to 100 lines, and there is no problem collection of specifications and source code bugs.This is the first installment of such a "bug detection drill" series.

 Bugs are lurking in all software developments, and engineers need the ability to quickly detect bugs.The new series aims to have a bug problem with the aim of improving the bug detection ability of engineers and have readers find them.

 The main trend is to present the specifications and programs with bugs.The reader should be a reviewer and find a bug.If you continue to solve the problem, you will feel the smell of the bug, "There is a bug around here."Also, there may be bugs that I may not have assumed in the problem (bugs are not only in the source code but also in specifications).

 If the author is not intended, we will add restrictions in advance.Ignore that part even if there is a problem.At the end of the column, we present the expected answer example and self -scoring sheet.Check your score yourself.The score was decided by my own discretion and prejudice, so don't worry about the score and try it as easy as an elementary school arithmetic drill.

 This time, I will give two questions.Question 1 is as follows.

Question 1: Specifications in list 1-1, list 1-2, and programs in list 1-3.Make sure the restrictions on list 1-4 are complied and the bugs are detected.There is no one bug.

Specifications: This program is a program that shows the average score from the score of the five people's language test and displays it on the console.

 The average score of the score of the Japanese language for five is calculated by an integer type (int type).See Listing 1-2 for the data to be used.The average point is to be displayed on the console with an integer type (int type).

リスト1-1:平均値を求めるプログラムの仕様
生徒国語の点数
A70
B83
C100
D33
E89
リスト1-2 国語の点数データ
#include int main() {int i;int avg;int num[5] = {70, 83, 100, 33, 89};for (i = 0; i < 4; i++) {avg += num[i];}avg /= 5;printf("平均 = %d\n",avg);return 0;}
リスト1-3 平均値を求めるプログラム

( *) The variables used are all integer type, and the score data for 5 people (variable NUM [5]) shall be hard coding.

リスト1-4 制限事項

 Listing 1-1 is a specification that finds the average value and calculates using the data of list 1-2.Listing 1-3 is a program described in C language based on 1-1 and 1-2.The data of the scoring is hard -coded (good child should not imitate).First, look at the specifications and programs for 3 minutes.You will notice something strange.

問題1の解答1|2|3|4次のページへ

Copyright © ITmedia, Inc.All Rights Reserved.