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 928138
2474 웹서버,WAS [apache] HTTP/HTTPS 리다이렉트(Redirect/Rewrite) 하는 방법 new JaeSoo 2025.09.11 7
2473 웹서버,WAS http를 https로 리다이렉트하는 여러가지 방법 JaeSoo 2025.09.10 6
2472 웹서버,WAS SSL인증서 없이 HTTPS에서 HTTP로 되돌리기 JaeSoo 2025.09.10 8
2471 웹서버,WAS [SSL] win-acme, Let's encrypt로 무료 SSL 인증서 발급 JaeSoo 2025.09.10 6
2470 웹서버,WAS [SSL] Windows 10에서 Let's Encrypt로 SSL 인증서 무료 발급받기 JaeSoo 2025.09.10 6
2469 웹서버,WAS 무료로 https SSL/TLS 인증서를 발급받을 수 있는 인증 기관 JaeSoo 2025.09.10 6
2468 웹서버,WAS 아파치 서버에 https SSL 인증서 적용하는 방법 (apache httpd) JaeSoo 2025.09.10 6
2467 웹서버,WAS 아파치2(Apache2) SSL HTTPS 적용하기 JaeSoo 2025.09.10 6
2466 웹서버,WAS 아파치 웹서버에 멀티 도메인에 대한 80, 443 포트 설정하는 방법 file JaeSoo 2025.09.10 12
2465 소프트웨어 Google Photo 대신 Immich를 써보자 file JaeSoo 2025.08.07 141
2464 연애 남자 혹은 여자 진국 팁 JaeSoo 2025.07.24 122
2463 기타 MBTI검사 16가지 유형 “간단 명료”하게 정리! file JaeSoo 2025.07.01 145
2462 소프트웨어 [사진관리] PhotoPrism vs LibrePhoto 비교 소감 JaeSoo 2025.05.19 20
2461 네트워크 MDF실, TPS실, EPS실 이게 뭘까? file JaeSoo 2025.04.15 47
2460 업무 알아두면 좋은 직장인 용어 정리 file JaeSoo 2025.04.15 49
2459 건강 감기·독감·코로나19의 차이점, 신촌연세병원과 함께 알아봅시다. file JaeSoo 2025.01.08 35
2458 생활 집주인이 전세 보증금을 돌려주지 않을 때 JaeSoo 2024.11.29 26
2457 자동차 자전거 타이어 종류 및 추천 2편 (승차감 타이어, 국토종주!) JaeSoo 2024.10.15 53
2456 자동차 오도바이 센타 사장들은 어떤 브랜드를 싫어하고 좋아할까? [출처] 오도바이 센타 사장들은 어떤 브랜드를 싫어하고 좋아할까?|작성자 바이크신 file JaeSoo 2024.10.15 85
2455 윈도우즈 윈도우 자동 로그온 설정이 보이지 않을 때 조치사항 JaeSoo 2024.08.16 203
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 124 Next
/ 124


즐겨찾기 (가족)

JAESOO's HOMEPAGE


YOUNGAE's HOMEPAGE


장여은 홈페이지


장여희 홈페이지


장여원 홈페이지


즐겨찾기 (업무)

알리카페 홀릭

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

말레이시아 KL Sentral 한국인 GuestHouse


즐겨찾기 (취미)

어드민아이디

유에코 사랑회

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

JServer.kr

제이서버 메타블로그

재수 티스토리


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

재수 강의 홈페이지


한소리


VTMODE.COM


숭실대 인공지능학과


숭실대 통신연구실


베너