Operators, strings and subroutines
도입됨
13:08
프로그래밍
Here is a short program. It reads five test marks and prints the total. The five marks are eight, nine, seven, six and ten, so the total should be forty. Watch…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| program/ˈprəʊɡræm/ | A set of instructions specifying operations for a computer to carry out. |
| values/ˈvæljuːz/ | |
| operators/ˈɒpəreɪtəz/ | 연산자 |
| strings/strɪŋz/ | LENGTH, SUBSTRING , UCASE, LCASE. |
| code/kəʊd/ | |
| comments/ˈkɒments/ | Explanatory text in source code or markup that does not execute as a program instruction. |
| Arithmetic/əˈrɪθmətɪk/ | |
| power/ˈpaʊə/ | |
| library routines/ˈlaɪbrəri ruːˈtiːnz/ | Reusable functions or procedures supplied in a collection for programs to call. |
| remainder/rɪˈmeɪndə/ | For integer division here, the amount left after taking whole groups of the divisor. |
| Relational/rɪˈleɪʃənl/ | |
| Boolean/ˈbuːlɪən/ | A logical value that is either true or false. |
| Logical/ˈlɒdʒɪkl/ | |
| characters/ˈkærɪktəz/ | A text unit such as a letter, digit, punctuation mark or other symbol. |
| LENGTH/leŋθ/ | |
| SUBSTRING/ˈsʌbstrɪŋ/ | |
| UCASE | |
| LCASE | |
| procedure/prəˈsiːdʒə/ | 절차 |
| function/ˈfʌŋkʃn/ | 함수 |
| RETURN/rɪˈtɜːn/ | |
| parameter/pəˈræmɪtə/ | 매개변수 |
| local variable/ˈləʊkl ˈveərɪəbl/ | 로컬 변수 |
| subroutine/ˈsʌbruːtiːn/ | |
| global/ˈɡləʊbl/ | 전역 |
| CALL/kɔːl/ |
프로그램의 도구들
- 프로그램은 **연산자(operators)**를 사용하여 값을 조합하고 **문자열(strings)**과 작업합니다.
- 코드 반복을 피하기 위해 **절(subroutines/procedures)**과 **함수(functions)**를 사용합니다.
- 좋은 네이밍과 주석은 프로그램을 **유지보수 가능(maintainable)**하게 만듭니다.
연산자(Operators)
- 산술(Arithmetic):
+ - * /,^(제곱),MOD(나머지),DIV(정수 부분). 예:17 MOD 5 = 2,17 DIV 5 = 3. - 관계(Relational) (부울리안(Boolean) 반환):
= < <= > >= <>(불일치). - 논리(Logical):
AND(모두 참),OR(최소 하나 참),NOT(반전).

A pre-condition (WHILE) loop tests before the body, so it may run zero times; a post-condition (REPEAT) loop tests after, so it runs at least once.

What is 17 MOD 5?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
MOD gives the remainder: 17 ÷ 5 = 3 remainder 2.
What is 17 DIV 5?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
DIV gives the whole-number part: 17 ÷ 5 = 3 (remainder discarded).
문자열 처리(String handling)
- 문자열은 문자로 구성됩니다. 유용한 연산:
- LENGTH(문자 수), SUBSTRING(부분), UCASE(대문자), LCASE(소문자).
name ← "Computer"
OUTPUT LENGTH(name) // 8
OUTPUT SUBSTRING(name, 1, 4) // "Comp"

변수는 값이 변경 가능한 이름이 붙은 저장 공간입니다
SUBSTRING: take part of a string
The first character is at position 1. SUBSTRING(Word, Start, Length) takes Length characters beginning at Start — drag the two handles and read the call it builds.
What does LENGTH("Computer") return?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
"Computer" has 8 characters.
Match each operator or string function to what it gives.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
MOD/DIV split a division into remainder and quotient; LENGTH and SUBSTRING work on strings.
절, 함수 및 좋은 스타일
- **절(procedure)은 작업을 수행하며(
CALL**로 실행); **함수(function)**는 값을 반환(return)합니다. - **파라미터(parameter)**는 전달되는 값입니다(최대 3개까지).
- 로컬 변수는 서브루틴 내부에서만 존재하므로(안전함);글로벌 변수는 어디에서나 접근 가능합니다.
- 라이브러리 루틴(library routines):
MOD,DIV,ROUND,RANDOM. - 유지보수 가능한(maintainable) 프로그램은 의미 있는 명명(meaningful names), 주석(comments), 그리고 서브루틴을 사용합니다.

기본 데이터 타입: 정수(integer), 실수(real), 문자(char), 문자열(string), 부울리안(boolean)
A local variable:
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Locals are safer because other parts of the program cannot change them by mistake.
A function returns a value (used in an expression) while a procedure just performs a task, and a local variable can only be used inside the subroutine where it is declared.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Functions return values; locals keep variables safe inside their own subroutine — both make code easier to maintain.
이 카드는 새로 추가되어 번역이 준비될 때까지 영어로 표시됩니다.
Worked example: minutes to hours
A film lasts 135 minutes. Use DIV and MOD to calculate its length in hours and minutes, then write a function that returns 返回 the whole number of hours.
DIV(135, 60)= 2 (the whole number of hours) andMOD(135, 60)= 15 (the remainder), so the film is 2 hours 15 minutes.- As a function with a parameter, it returns a value to the program that called 调用 it:
FUNCTION Hours(Mins : INTEGER) RETURNS INTEGER
RETURN DIV(Mins, 60)
ENDFUNCTION

What is 23 MOD 4?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
23 = 5 × 4 + 3, so the remainder is 3.
Name ← "Shanghai". What does SUBSTRING(Name, 1, 5) return?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
It takes 5 characters starting at position 1.
이해했습니다
MOD= 나머지,DIV= 정수 부분; 논리AND/OR/NOT- 문자열: LENGTH, SUBSTRING, UCASE, LCASE
- **절(procedure)**은 작업을 수행하고, **함수(function)**는 값을 반환하며, **파라미터(parameters)**는 값을 전달합니다
- 로컬(local) 변수가 글로벌(global) 변수보다 안전합니다; 유지보수 가능 = 의미 있는 명명 + 주석 + 서브루틴
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.