Docsity

Programming Fundamentals: Algorithms, Pseudocode, and Data Types, Study notes of Computer science

Partial preview of the text

Download Programming Fundamentals: Algorithms, Pseudocode, and Data Types and more Study notes Computer science in PDF only on Docsity!

AQA

AS Level

Computer Science Paper 1

Programming

basics

Unit 1 Fundamentals of programming

Objectives

  • (^) Define what is meant by an algorithm and pseudocode
  • (^) Learn how and when different data types are used
  • (^) Learn the basic arithmetic operations available in a typical programming language
  • (^) Become familiar with basic string handling operations
  • (^) Distinguish between variables and constants
  • (^) Write pseudocode solutions to simple problems

Unit 1 Fundamentals of programming Problem: calculate paint required

  • (^) What inputs would you need?
  • (^) What decisions does the painter need to make?
  • (^) Think out the sequence of instructions, starting with Input the dimensions of the room
  • (^) Use statements like Input, Calculate, Output, Add, Subtract, Multiply
  • (^) Or maths symbols like +, - , * (multiply)

Unit 1 Fundamentals of programming Worksheet 1

  • (^) Complete Task 1 of the Worksheet

Unit 1 Fundamentals of programming Pseudocode statements

  • (^) Assignment statements can be written using an = sign or a 
  • (^) The symbols +, - , *, / , ** (exponentiation) are used for common arithmetic operations miles  currentMileage – previousMileage count  count + 1
  • (^) Output and input statement are written OUTPUT “Enter current mileage” currentMileage  USERINPUT Or, currentMileage  USERINPUT(“Enter current mileage”)

Unit 1 Fundamentals of programming Pseudocode statements

  • (^) What do the following statements do?
    1. OUTPUT “Enter a number”
    2. number USERINPUT
    3. number  number + 1
    4. OUTPUT “The number is : ” + number

Unit 1 Fundamentals of programming Pseudocode

  • (^) What is the purpose of pseudocode?
  • (^) What guidelines would you suggest for writing clear, understandable pseudocode? number  0 OUTPUT “Enter a number” number  USERINPUT IF number > 4 THEN OUTPUT “Greater than 4” ELSE OUTPUT “4 or less” ENDIF

Unit 1 Fundamentals of programming Variables and assignment

  • (^) An identifier is a name, e.g. Score , that points to a memory location
  • (^) Assignment is assigning a value to the memory location
  • (^) In this example Score is assigned the value of 0
  • (^) In the next line, 1 is added to Score and the result is again assigned to Score Start Score  0 Score  Score + 1 End

Unit 1 Fundamentals of programming Data types

  • (^) What happens if the character “9” is assigned to an integer variable?
  • (^) What are the allowable values of a Boolean data type? 1. Dim wholeNumber As Integer = 5 2. Dim height As Decimal = 1. 3. Dim name As String = "Bob" 4. Dim choice As Char = "a" 5. Dim validData As Boolean = False

Unit 1 Fundamentals of programming Variables and Constants

  • (^) The value of a variable can be changed while the program is running
  • (^) To change the value of a constant, you have to change it in the source code and then recompile
  • (^) A constant cannot be the target of an assignment Dim name as String = “Robert” Const VAT as Single = 17. Console.WriteLine(“VAT is: “ & VAT) Name = “Hazel” Console.WriteLine(“Name is: “ & name) VAT = 20 ‘this will cause an error

Unit 1 Fundamentals of programming Worksheet 1

  • (^) Complete the questions in Task 2 of the Worksheet

Unit 1 Fundamentals of programming The % and // operators

  • (^) In Python the operator % (mod) is used to find the remainder in integer division
  • (^) // (div) returns the integer part of the division x = 17 % 3 sets x = 2 y = 17 // 3 sets y = 5

Unit 1 Fundamentals of programming String handling functions

  • (^) Programming languages have a number of built-in string handling functions or methods
  • (^) For example: name  “Robert” x  len(name) x  name.len returns the length of string name x  name.find (“be”) determines if “be” occurs in string name (returns the position of the first character in the string, 0 if not found)

Unit 1 Fundamentals of programming String handling functions

  • (^) What would the following return? (Assume the index starts at 0) name  “John” x  len(name) x  name.find (“be”) x  name.find (“oh”)