RadarURL

논문
2012.09.09 08:45

Pseudo Code 작성법

조회 수 5632 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

Introduction

Pseudo code (or Structured English) is used to specify program logic in a (somewhat) English like manner, that aims to be independent of any particular programming language. This simplifies program development by separating it into two main parts, logic design and coding. The use of pseudo code allows the programmer to focus on the logic of the program rather than implementation details such as how data is displayed Once the logic is developed, coding becomes the translation of the pseudo code into the required programming language.

Sequence

Assignment

Format

variable = expression

Examples

total = 0
y = x * x + z / 4 - 1
name = "Joan Smith"
validLength = True

Input

Format

Input variable, variable, ...

Examples

Input custName
Input distance, speed

Display

Format

Display value, value, ...

Examples

Display "Hello World"
Display totalPrice, taxPayable
Display "Customer Number: ", custNum, "Name: ", custName

Selection

If-Else

Format

IF condition THEN
   statement

   statement
   ...
ENDIF
 

IF condition THEN
   statement

   statement
   ...
ELSE
   statement

   statement
   ...
ENDIF
 

IF condition THEN
   statements

ELSE
   IF condition THEN
       statements

   ELSE
       IF condition THEN
           statements

       ELSE
          statements

       ENDIF
   ENDIF
ENDIF
 

IF condition THEN
   statements

ELSE IF condition THEN
   statements
ELSE IF condition THEN
   statements

ELSE
   statements

ENDIF

Note: the Else part is optional. Use it where required by the logic.

Examples

IF lineNumber > 50 THEN
   Display ""
   Display "Student Number", "Student Name"
   lineNumber = 0

ENDIF
 

IF monthNumber >= 1 AND monthNumber <= 12 THEN
   Display "valid month"

ELSE
   Display "invalid month"

   Display "Month must be between 1 and 12"
ENDIF
 

IF mark >= 80 THEN
   grade = "A"

   comment = "Excellent"
ELSE
   IF mark >= 70 THEN
       grade = "B"

   ELSE
       IF mark >= 60 THEN
           grade = "C"

       ELSE
           IF mark >= 50 THEN
               grade = "D"

           ELSE
               grade = "N"
               comment = "Poor"
           ENDIF
       ENDIF
   ENDIF
ENDIF
 

IF mark >= 80 THEN
   grade = "A"

   comment = "Excellent"
ELSE IF mark >= 70 THEN
   grade = "B"
ELSE IF mark >= 60 THEN
   grade = "C"

ELSE IF mark >= 50 THEN
   grade = "D"
ELSE
   grade = "N"
   comment = "Poor"
ENDIF

Iteration (Repetition)

For

Format

FOR counter = start-value to end-value DO
   statement
   statement
   ...
ENDFOR

Example

FOR x = 1 to 10 DO
   xSquared = x * x
   Display x, xSquared
ENDFOR

While

Format

WHILE condition DO
   statement
   statement
   ...
ENDWHILE

Example

count = 1
WHILE count <= 10 DO
   Display count
   Add 1 to count
ENDWHILE

Programs

Format

program-name()
   statement

   statement
   ...
STOP

Example

addTwoNumbers()
   Input number1, number2
   sum = number1 + number2
   Display sum
STOP 

Subprograms: Subroutines and Functions

Subroutines

Subroutines are also called procedures or void methods. Subroutines do not return a value.

Format - subroutine calls

subroutine-name()
subroutine-name(parameter, parameter, ...)

Examples - subroutine calls in a program

demoProgram()
    ...
   displayTenStars()

   displayAverage(count, total)
STOP

Format - subroutine declarations

subroutine-name()
   statement
   statement
   ...
EXIT

subroutine-name(parameter, parameter, ...)
   statement
   statement
   ...
EXIT

Examples - subroutine declarations

displayTenStars()
   FOR numStars = 1 to 10 DO
       Display "*"
   ENDFOR
   Display ""
EXIT

displayAverage(count, total)
   IF count > 0 THEN
       average = total / count
       Display average
   ELSE
       Display "Error, nothing to average"
   ENDIF
EXIT

Functions

Functions are also called non-void methods. Functions return a single value.

Format - function calls

function-name()
function-name(parameter, parameter, ...)

Examples - function calls in a program

demoProgram()
    ...
   month = inputMonth()

   IF oddNumber(month) THEN
       ...

   ENDIF
   volume = 4 /3 * PI * cube(radius)
   max = maximumNumber(a, b)
STOP

Format - function declarations

The following are called functions. They return a single value.

function-name()
   statement
   statement
   ...
RETURN with value

function-name(parameter, parameter, ...)
   statement
   statement
   ...
RETURN with value

Examples - function declarations

inputMonth()
   Input monthNumber
   WHILE monthNumber < 1 OR monthNumber > 12 DO
       Display "Error invalid month number"
       Input monthNumber
   ENDWHILE
RETURN with monthNumber

oddNumber(num)
   oddNumber = false
   IF num modulus 2 = 0 THEN
       oddNumber = true
   ENDIF
RETURN with oddNumber

cube(number)
   cube = number * number * number
RETURN with cube

maximumNumber (number1, number2)
   IF number1 >= number2 THEN
       maximumNumber = number1
   ELSE
       maximumNumber = number2
   ENDIF
RETURN with maximumNumber

Keywords

The following words have a special meaning in Pseudo Code (in this subject) and should only be used for the purposes described above.

AND, DO, ELSE, ENDIF, ENDFOR, ENDWHILE, EXIT, FOR, IF, NOT, OR, RETURN, STOP, THEN, TO, WHILE.

Other statements: Display, Input
Operators:  =, +, -, *, /, (), <, <=, >, >=, []

 

출처 : http://hackereyes.tistory.com/entry/%ED%8E%8C-Pseudo-Code-%EC%9E%91%EC%84%B1%EB%B2%95

?

공부 게시판

공부에 도움되는 글을 올려주세요.

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 [공지] 공부 게시판 입니다. 처누 2003.08.18 928098
69 논문 전수데이터를 생성하는 빠른 콤비나토리얼 프로그램 (Fast Combinatorial Programs Generating Total Data) file JaeSoo 2015.07.15 642
68 논문 스코퍼스(Scopus) 지수 JaeSoo 2014.10.21 857
67 논문 [논문] Ubiquitous-City Integrated Authentication System (UCIAS) - Jae-Soo Jang, Hyung-Min Lim, Journal of Intelligent Manufacturing(JIM), February 2014, 장재수 file JaeSoo 2014.02.21 2028
66 논문 [논문] 다중링크를 이용한 다양한 크기의 데이터 전송 (Data transmission of various size that use multiplex link) - 장재수,학위논문(석사), 숭실대학교 대학원 : 컴퓨터학과(일원) 컴퓨터통신 2003. 12 file JaeSoo 2014.01.25 2850
65 논문 [논문] 조합과 순열 생성 알고리즘의 개선(Enhancement of Combination and Permutation Generation Algorithms) - 장재수,학위논문(박사), 숭실대학교 대학원 : 컴퓨터학과(일원) 컴퓨터통신 2013. 8 file JaeSoo 2014.01.25 2591
64 논문 제 논문에 실린 감사의 글입니다 JaeSoo 2013.06.12 7191
63 논문 박사학위논문을 끝내고 감사하는 마음의 글 JaeSoo 2013.06.12 5913
62 논문 로그(Log)에 대하여.. JaeSoo 2013.06.10 3639
61 논문 Excel 엑셀, 상용 로그, 자연 로그(LOG) 구하기 계산 함수; Common, Natural Logarithm JaeSoo 2013.06.10 6921
60 논문 논문 투고 과정 file JaeSoo 2013.06.07 4814
59 논문 수리과학 영어논문 작성법 file JaeSoo 2013.06.07 5216
58 논문 논문 작성과 형식 - 1.10 퇴고와 기타사항 JaeSoo 2013.05.19 4827
57 논문 논문 작성과 형식 - 1.8 표와 그림 JaeSoo 2013.05.19 5730
56 논문 논문 작성과 형식 - 1.9 주와 참고문헌의 처리 JaeSoo 2013.05.19 4388
55 논문 논문 작성과 형식 - 1.7 인용과 인증 JaeSoo 2013.05.19 4657
54 논문 논문 작성과 형식 - 1.6 논문 작성시 문장의 형식 JaeSoo 2013.05.19 6227
53 논문 논문 작성과 형식 - 1.5 논문의 내용 전개 JaeSoo 2013.05.19 4905
52 논문 논문 작성과 형식 - 1.4 논문의 내용구성 JaeSoo 2013.05.19 5151
51 논문 논문 작성과 형식 - 1.3 논문의 작성의 개요 JaeSoo 2013.05.19 5185
50 논문 논문 작성과 형식 - 1.2 학술논문의 형식 JaeSoo 2013.05.19 6538
Board Pagination Prev 1 2 3 4 Next
/ 4


즐겨찾기 (가족)

JAESOO's HOMEPAGE


YOUNGAE's HOMEPAGE


장여은 홈페이지


장여희 홈페이지


장여원 홈페이지


즐겨찾기 (업무)

알리카페 홀릭

숭실대 컴퓨터 통신연구실 (서창진)

말레이시아 KL Sentral 한국인 GuestHouse


즐겨찾기 (취미)

어드민아이디

유에코 사랑회

아스가르드 좋은사람/나쁜사람

JServer.kr

제이서버 메타블로그

재수 티스토리


즐겨찾기 (강의, 커뮤니티)

재수 강의 홈페이지


한소리


VTMODE.COM


숭실대 인공지능학과


숭실대 통신연구실


베너