跳到正文

个人记录

IGCSE Computer Science 小记

tiger2008约 11 分钟
原文
文章信息与版本

文章信息

收录
2026年2月3日
更新
2026年2月3日
篇幅
约 11 分钟

版本

  1. v2当前
  2. v1

闲着无聊就更新(

上次更新时间: 2023.10.162023.10.16

Computer Science

Algorithm

Introduction

计算机:program→instruction→problemprogram→instruction→problem

Algorithm{InputOutputUnambiguityFinitenessEffectivenessLanguage IndependentAlgorithm\begin{cases}Input\\Output\\Unambiguity\\Finiteness\\Effectiveness\\Language\ Independent\end{cases}

Program Development Life Cycle

Abstracted things I\mathrm{I}

Decomposition\mathbf{Decomposition} is used to split the program into subprogramsis\ used\ to\ split\ the\ program\ into\ subprograms

Structure Diagram

CalculatorInputProcessOutput⏞Input a,bfind maximum in a,bOutput ans\begin{matrix}Calculator\\\overbrace{Input\qquad\qquad\qquad\qquad Process\qquad\qquad\qquad\qquad Output}\\Input\ a,b\qquad\qquad find\ maximum\ in\ a,b\qquad\qquad Output\ ans\end{matrix}

Input:Input: The number you enter in the computer.The\ number\ you\ enter\ in\ the\ computer.

Process:Process: Use algorithm to achieve some goals.Use\ algorithm\ to\ achieve\ some\ goals.

OutputOutput The number computer tell you after the algorithm.The\ number\ computer\ tell\ you\ after\ the\ algorithm.

3 main aspects of Algorithm

Algorithm{Sequencing−orderSelection−choiceIteration−repectAlgorithm\begin{cases}Sequencing-order\\Selection-choice\\Iteration-repect\end{cases}

Flow chart

Abstracted things II\mathrm{II}

For example:JavaFor\ example: Java

代码
Math mathObject=new Math(...)

Algorithm{Declare:Math mathObjectInstantiate:new Math(...)Initialize:Math mathObject=new Math(...)Algorithm\begin{cases}Declare:Math\ mathObject\\Instantiate:new\ Math(...)\\Initialize:Math\ mathObject=new\ Math(...)\end{cases}

Pseudocode solution

Pseudocode:A method of representing an algorithm using simple works and mathematical operators.Pseudocode: A\ method\ of\ representing\ an\ algorithm\ using\ simple\ works\ and\ mathematical\ operators.

  • DECLAREDECLARE

When you want to use a variable, you need to declare it first.When\ you\ want\ to\ use\ a\ variable,\ you\ need\ to\ declare\ it\ first.

代码
DECLARE n:INTEGER // int
DECLARE n:STRING // string
DECLARE n:BOOLEAN // bool
DECLARE n:REAL // float
  • INPUT & OUTPUTINPUT\ \&\ OUTPUT

INPUT is used for data entry.INPUT\ is\ used\ for\ data\ entry.

OUTPUT is used to display a string or a variable.OUTPUT\ is\ used\ to\ display\ a\ string\ or\ a\ variable.

代码
INPUT n
OUTPUT n
OUTPUT "I AK IOI"
  • Assigning a ValueAssigning\ a\ Value

Values are assigned to a variable using the ←operator.Values\ are\ assigned\ to\ a\ variable\ using\ the\ ← operator.

The value on the right of the ←operator is assigned to the left.The\ value\ on\ the\ right\ of\ the\ ← operator\ is\ assigned\ to\ the\ left.

Mathematical expressions can be used on the right side of the ←operator.Mathematical\ expressions\ can\ be\ used\ on\ the\ right\ side\ of\ the\ ← operator.

代码
Name <- "Mike"
Age <- 32
Gender <- "M"
Salary <- 6000
Expense <- 1145
Saving <- Salary-Expense
  • IF...THEN...ELSE...ENDIFIF...THEN...ELSE...ENDIF

Start withStart\ with IF followed by a conditional statement.followed\ by\ a\ conditional\ statement.

Indent 2 spaces forIndent\ 2\ spaces\ for THEN.

Indent 2 more spaces to show which commands are part of theIndent\ 2\ more\ spaces\ to\ show\ which\ commands\ are\ part\ of\ the THEN block.block.

Return to the indentation of theReturn\ to\ the\ indentation\ of\ the THEN keyword and usekeyword\ and\ use ELSE if needif\ need

In theIn\ the ELSE case, indent 2 spaces to show which commands are part of thecase,\ indent\ 2\ spaces\ to\ show\ which\ commands\ are\ part\ of\ the THEN block.block.

Return to the indentation for theReturn\ to\ the\ indentation\ for\ the IF keyword and thekeyword\ and\ the ENDIF at the end of the code.at\ the\ end\ of\ the\ code.

代码
IF Age>=10
  THEN
    OUTPUT "Eligible"
  ELSE
    OUTPUT "Ineligibe"
ENDIF
  • CASE OF...ENDCASECASE\ OF...ENDCASE

Start withStart\ with CASE OF followed by the name of a variable previously declared.followed\ by\ the\ name\ of\ a\ variable\ previously\ declared.

Indent 3 spaces and give one potential value for the variable followed by a colon and then the first statementIndent\ 3\ spaces\ and\ give\ one\ potential\ value\ for\ the\ variable\ followed\ by\ a\ colon\ and\ then\ the\ first\ statement

for that condition.for\ that\ condition.

Subsequent statements for that condition should follow the indentation of the first statement.Subsequent\ statements\ for\ that\ condition\ should\ follow\ the\ indentation\ of\ the\ first\ statement.

Return to the indentation for the first potential value and list another potential value followed by a colonReturn\ to\ the\ indentation\ for\ the\ first\ potential\ value\ and\ list\ another\ potential\ value\ followed\ by\ a\ colon

and the first statement for that condition.and\ the\ first\ statement\ for\ that\ condition.

Repeat until all potential values have been listed.Repeat\ until\ all\ potential\ values\ have\ been\ listed.

For all other values theFor\ all\ other\ values\ the OTHERWISE keyword can be used in the same way as the potential value.keyword\ can\ be\ used\ in\ the\ same\ way\ as\ the\ potential\ value.

Return to the indentation of theReturn\ to\ the\ indentation\ of\ the CASE OF keyword and putkeyword\ and\ put ENDCASE to show the end of the selection.to\ show\ the\ end\ of\ the\ selection.

代码
CASE OF Symbol
   '+' : OUTPUT a + b
   '-' : OUTPUT a - b
   '*' : OUTPUT a * b
   '/' : OUTPUT a / b
   OTHERWISE : OUTPUT "No Valid Symbol..."
ENDCASE

然后我不想写了

接着存储代码吧

T1

写一个伪代码,记录50个骰子投两边的总和的数量。

代码
DECLARE rand1:INTEGER
DECLARE arr:ARRAY[1:12] OF INTEGER
FOR i<-1 TO 50
   rand1<-INT(RAND(1)*6+1)+INT(RAND(1)*6+1)
   arr[rand1]<-arr[rand1]+1
NEXT i
DECLARE str:STRING
FOR i<-2 TO 12
   str<-""
   str<-str&i&":"
   FOR j<-1 TO arr[i]
      str<-str&"X"
   NEXT j
   PRINT str
NEXT i

上课学习array随便写的代码

代码
DECLARE name:ARRAY[1:13] OF STRING
DECLARE exams:ARRAY[1:13,1:7] OF REAL
DECLARE average:ARRAY[1:13] OF REAL
FUNCTION getnumber() RETURNS REAL
   DECLARE randomnumber:REAL
   randomnumber<-RAND(10000)
   randomnumber<-INT(randomnumber)
   randomnumber<-randomnumber/100
   RETURN randomnumber
ENDFUNCTION
PROCEDURE findaverage()
   DECLARE sum:REAL
   FOR i<-1 TO 13
      sum<-0.00
      FOR j<-1 TO 7
         sum<-sum+exams[i,j]
      NEXT j
      sum<-sum/7
      average[i]<-INT(sum*100)/100.0
   NEXT i
ENDPROCEDURE
PROCEDURE print()
   DECLARE string1:STRING
   FOR i<-1 TO 13
      string1<-name[i]
      FOR j<-LENGTH(string1) TO 6
         string1<-string1&" "
      NEXT j
      FOR j<-1 TO 7
         string1<-string1&exams[i,j]&" "
         FOR k<-LENGTH(string1) TO (6*(j+1))
            string1<-string1&" "
         NEXT k
      NEXT j
      string1<-string1&"    average score:"&average[i]
      OUTPUT string1
   NEXT i
ENDPROCEDURE
FOR i<-1 TO 13
   INPUT name[i]
   FOR j<-1 TO 7
      exams[i,j]<-getnumber()
   NEXT j
NEXT i
CALL findaverage()
CALL print()
原文