IGCSE Computer Science 小记

· · 个人记录

闲着无聊就更新(

上次更新时间: 2023.10.16

Computer Science

Algorithm

Introduction

计算机:program→instruction→problem

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

Program Development Life Cycle

Abstracted things \mathrm{I}

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

Structure Diagram

\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:$ $The\ number\ you\ enter\ in\ the\ computer. Process:$ $Use\ algorithm\ to\ achieve\ some\ goals. Output$ $The\ number\ computer\ tell\ you\ after\ the\ algorithm.

3 main aspects of Algorithm

Algorithm\begin{cases}Sequencing-order\\Selection-choice\\Iteration-repect\end{cases}

Flow chart

Abstracted things \mathrm{II}

For\ example: Java
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. 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\ is\ used\ for\ data\ entry. OUTPUT\ is\ used\ to\ display\ a\ string\ or\ a\ variable.
INPUT n
OUTPUT n
OUTPUT "I AK IOI"
Values\ are\ assigned\ to\ a\ variable\ using\ the\ ← operator. 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.
Name <- "Mike"
Age <- 32
Gender <- "M"
Salary <- 6000
Expense <- 1145
Saving <- Salary-Expense           
Start\ with$ ```IF``` $followed\ by\ a\ conditional\ statement. $Indent\ 2\ more\ spaces\ to\ show\ which\ commands\ are\ part\ of\ the$ ```THEN``` $block. Return\ to\ the\ indentation\ of\ the$ ```THEN``` $keyword\ and\ use$ ```ELSE``` $if\ need In\ the$ ```ELSE``` $case,\ indent\ 2\ spaces\ to\ show\ which\ commands\ are\ part\ of\ the$ ```THEN``` $block. Return\ to\ the\ indentation\ for\ the$ ```IF``` $keyword\ and\ the$ ```ENDIF``` $at\ the\ end\ of\ the\ code.
IF Age>=10
  THEN
    OUTPUT "Eligible"
  ELSE
    OUTPUT "Ineligibe"
ENDIF
Start\ with$ ```CASE OF``` $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\ statement for\ that\ condition. 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\ colon and\ the\ first\ statement\ for\ that\ condition. Repeat\ until\ all\ potential\ values\ have\ been\ listed. For\ all\ other\ values\ the$ ```OTHERWISE``` $keyword\ can\ be\ used\ in\ the\ same\ way\ as\ the\ potential\ value. Return\ to\ the\ indentation\ of\ the$ ```CASE OF``` $keyword\ and\ put$ ```ENDCASE``` $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()