Notions of Problem Solving and Coding
Notions of Problem Solving and Coding
CODING
Lesson 1:
- Analyze the problem: Identify the values for length and width
- Step 3: Plan a solution
- Brainstorm possible solutions: Use the formula for area
- Evaluate and select the best solution: Use the formula with the given values
- Step 4: Implement the solution
- Plug in the values: Area = 6 cm x 4 cm
- Calculate the area: Area = 24 cm^2
- Step 5: Test and evaluate the solution
- Test with different values: Try length = 3 cm and width = 5 cm
- Evaluate the results: Area = 15 cm^2 (correct!)
Computational Thinking
Definition: The process of breaking down complex problems into smaller, manageable
parts to solve them efficiently.
Concepts:
Decomposition: Breaking down problems into smaller sub problems
Pattern recognition: Identifying patterns and relationships in data
LESSON 3: Solving problems 2
Example problem: Find the sum of all multiples of 3 from 1 to 20.
Step 1: Decompose the problem
- Break down the problem: Identify multiples of 3, add them up
- Identify the pattern: Multiples of 3 increase by 3 (3, 6, 9, ...)
Step 2: Recognize the pattern
- Identify the next multiple of 3: 18 (last multiple of 3 in the range)
- Use the pattern to find the sum: 3 + 6 + 9 + 12 + 15 + 18 = 63
Abstraction: Focusing on essential features while ignoring nonessential details
Example problem: Write a program to greet a user. Step 1: Focus on
essential features
- Identify the essential feature: Greeting the user
- Ignore non-essential details: User's name, location, etc.
Step 2: Write the program
- Use a block programming environment (e.g. Scratch)
- Create a sprite that says "Hello, World!"
Writing Programs in Block Programming Environments
- Example: Write a program to move a sprite across the screen.
- Step 1: Drag and drop blocks to create the program
- Step 2: Test and evaluate the program
- Step 3: Refine the program as needed
Program Development
Definition: Program development is the process of designing, creating, testing,
and maintaining software programs. Program development helps solve real-world
problems and create innovative solutions.
Lesson 7: Flowcharts
A flowchart is A graphical representation of an algorithm using symbols and
arrows.
Flowchart symbols:
1. Rectangle (Process): Represents a step or action in the algorithm,
such as a calculation or data manipulation.
Flowchart rules:
Solution:
1. Input n
2. Initialize sum = 0
3. For I = 1 to n
4. sum = sum + i
5. Output sum
1. Input a and b
2. If a > b then
3. Output a
4. Else
5. Output b
2. Initialize factorial = 1
3. For I = 1 to n
4. factorial = factorial x i
5. Output factorial
2. If n = 1 then
3. Output 0
4. Else if n = 2 then
5. Output 1
6. Else
- Decompose problems into smaller parts and design solutions for each.
- Example: Design a solution for the grade management system using
structured diagrams and pseudocodes
Lesson 9: Types of programming language
Differences between an Algorithm and a Program
A computer program is a set of instructions written in a programming
language that tells the computer what to do in order to solve a problem. In other
words, it is an algorithm expressed in a programming language.
Programming Languages
A programming language is a set of words, symbols and rules for writing
computer programs. A programming language is determined by its syntax (rules
guiding the formulations of the program statement) and semantics (it describes the
meaning of the program statement i.e. it is the vocabulary of the language).
Two categories of programming languages exist: low-level languages and high-
level languages.
1. Machine Language:
It is the computer’s language. It is the language the computer understands.
Machine language instructions are written in binary (a series of 0s and 1s), and are
directly executable by the computer (processor). Each machine language statement
corresponds to one machine action. Machine language is the first generation of
programming languages.
2. Assembly Language:
It is a low-level language that uses words or symbolic codes called mnemonic
codes to represent machine language instructions. Assembly language is the
second generation of programming languages. ADD, LOAD, and STORE are
known as mnemonics.
Advantages of low-level languages
1. Programs are not as easy to write and understand when compared to high
level languages
2. Programs are tied to specific computer hardware and can’t be reused on
another kind of computer.
2. High Level Languages
A high-level language is a language that is closer to human language.It
allows a programmer to write programs without having to understand the inner
workings of the computer. High-level languages are the third generation of
programming languages. Examples of high-level languages are C, BASIC
(Beginners All-purpose Symbolic Instruction Code), Pascal, Java, FORTRAN
(FORmular TRANslation), C++, COBOL (COmmon Business Oriental Language
), etc.
Fast in execution
he object/executable code produced by a compiler can be distributed or
executed without having the compiler present.
The object program can be used whenever required without the need of
recompilation.
Disadvantages of a Compiler
Debugging a program is much harder. Therefore, not so good at
finding errors
When an error is found, the whole program has to be re-compiled
though compilation process is so fast.
Interpreter
An interpreter is a computer program that translates and executes instructions
written in a high-level language into machine language instructions one line at a
time. If a program performs a section code 1000 times, then the section is
translated into machine code 1000 times since each line is interpreted and then
executed. Types of interpreters: BASIC, Lisp, Logo, etc.
Advantages of an Interpreter
Good at locating errors in programs since interpretation is done line by
line.
Debugging is easier since the interpreter stops when it encounters an
error.
If an error is corrected, there is no need to retranslate the whole
program.
Disadvantages of an Interpreter
3. Run-time Error
Run-time error is an error that occurs when a program is being executed. For
example, a run-time error may occur if division by 0 is attempted. A run-time
error may cause the program to stop execution.
4. Debugging
An error in a computer program is known as a bug and debugging is the
process of finding and removing bugs. Syntax errors and semantic errors are bugs.
A debugger is the software tool (or person) used for this purpose.
Key Words and Operators
1. Key Words
Any high-level language has its own set of predefined words which are
used to write programs. Each of these words has a specific meaning, and cannot
be used for any other purpose within the programming language IDE. These
words are known as key words or reserved words. Therefor A reserved word is a
key word in a programming language that has a specific meaning and cannot be
used for any other purpose. E.g. If, Else, For, To and goto.
2. Operators
Operators are used to perform various operations on data. They may be
arithmetic, relational or logical. Arithmetic operators are +, -, *, %, ++ and -- and
/. Relational operators include <, >, ==, <=, >= and !=. Logic operators are NOT
(!), AND (&&) and OR (||).
Evaluation
Lesson 13: Declarative instructions
Basic data types in a programming language
1. Integers (int): they are Whole numbers, either positive, negative, or
zero. Examples are: 1, 2, 3, -4, 0. They are used for counting, indexing, and
calculations
2. Floating-point numbers (float): They are Decimal numbers, either
positive, negative, or zero. Examples are: 3.14, -0.5, 0.0. They are used for
calculations requiring decimal precision.
3. Characters (char): These are Single characters, either letters, digits,
or special characters. Examples are: 'a', 'B', '1', '@'. They are used for text
processing and input/output operations.
Variables:
Names given to memory locations storing data
Declared using the syntax: `type variable_name;`
Examples:
Constants: