2023.3.27 CS笔记

(a) (i) Write pseudocode to declare the record structure for type Employee.

DECALRE AEmp: Employee
AEmp.EmployeeNumber <----12345
AEmp.Name<---- "Mark"
#给数组中的某一个字段赋值

(ii) A 1D array Staff containing 500 elements will be used to store the employee records.
Write pseudocode to declare the Staff array

DECLARE Staff: ARRAY[0:499] OF Employee

(b) There may be more records in the array than there are employees in the company. In this
case, some records of the array will be unused.

  • Unused array elements can be recognized when processing the elements in the array,
  • Unused EmployeeRecord may contain unexpected data

(ii) Give one way of indicating an unused record in the Staff array.

-1 is used as the EmployeeNumber of each unused record in the array.
(用于区分有效和无效内容)

即有效内容的值一定大于1,当数组中的500个记录被创建时,缺省值默认为-1。
在Python中,可以先生成一个空数组,使用 .append 添加新的记录
在C语言中,默认的缺省值为 0

(c) A procedure Absentees() will output the EmployeeNumber and the Name of all employees
who have an Attendance value of 90.00 or less.
Write pseudocode for the procedure Absentees().
Assume that the Staff array is global.

PROCEDURE Absentees()
DECLARE i:INTEGER
  FOR i <--0 to 499
    IF Staff[i] EmployeeNumber<>-1 AND Staff [i].Attendance <=90.00 THEN #在最新的MS中Then不需要换行
      PRINT Staff[i] EmployeeNumber.Staff[i].Name
    ENDIF
  NEXT
ENDPROCEDURE

6 (a) The factorial of a number is the product of all the integers from 1 to that number.
For example:
factorial of 5 is given by 1 × 2 × 3 × 4 × 5 = 120
factorial of 7 is given by 1 × 2 × 3 × 4 × 5 × 6 × 7 = 5040
factorial of 1 = 1
Note: factorial of 0 = 1
A function Factorial() will:
• be called with an integer number as a parameter
• calculate and return the factorial of the number
• return −1 if the number is negative.
Write pseudocode for the function Factorial().

FUNCTION Factorial(ThisNum : INTEGER) RETURNS INTEGER
  DECLARE Value : INTEGER
    IF ThisNum < 0 THEN
      Value <-- -1
    ELSE
      Value <-- 1
      WHILE ThisNum <> 0
        Value <-- Value * ThisNum
        ThisNum <-- ThisNum – 1
      ENDWHILE
    ENDIF
    RETURN Value
ENDFUNCTION

Marks as follows to Max 6:
 1 Function heading and ending including parameter and return value
 2 Declaration and initialisation (to 1) of local Integer Value for result
 3 Check for illegal value (< 0)
 4 (Conditional) loop while ThisNum not zero // loop for ThisNum iterations
 5 Attempt to form answer by successive multiplication
 6 Completely correct MP5
 7 Return INTEGER value correctly in both cases: ThisNum < 0 and >= 0
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇