Table of Contents

Graph

Comp Sci 1

Algorithms have a control structure.

There are 3 kinds of control structures:

How to write control structure:

Review stuff I wrote in Notepad

modules:

e.g say we have a module that calculates wace then module that calculates time elapsed and another module that calculate tax

you use pseudocode for this!

main module: lets call it salary in this module we need the name of person, employer, branch of work { call calculate wage call cdalculate overtime call calculate tasx {

benefit of this is that you can call functions multiple times, so that you can repeatedly do specific tasks

ANOTHER BENEFIT is that MULTIPLE PROGRAMERS can work on SEPARATE PROGRAMS!!!!!

you have people working on specific module, and then one person working on the main moduile

this allows MORE ORGANISATION

INSIDE THE MODULE:

MAIN IDEA:

Advantages vs Disadvantages:

TO SEE THESE MODULES: We use a "structure chart"

you see main module in block, then you have it connected to other blocks arrow connected to circle, indicates input/output flow

WHAT IS THE OPPOSITE TO VARIABLE:

a Constant!!! A 'variable' that DOESN'T CHANGE

constants could be created before a program

e.g. anyone paying over 100 gets 5% discount

this 5% is now a constant

constants and variables use different types of DATA TYPES

COMPLEX DATA TYPES:

BINARY:

source code: code created in a PROGRAMMING LANGUAGE, i.e. something a human could understand

once the source code is done, it is converted to machine code.

BUT there is a code IN BETWEEN the machine and source code

this code is for virtual machines, and is called BYTE CODE.

e.g. convert 32 to binary 32/2 = 16 -> 0 16/2 = 8 -> 0 8/2 = 4 -> 0 4/2 = 2 -> 0 2/2 = 1 -> 0 1/2 ->1

therefore 32 in binary is 100000 (start from the end)

FIRST QUESTION OF THE TEST:

sequence:

selection:

repetition:

REMEMBER THE SYMBOLS!!!!!!!!!!

also, ERRORS!!! Types of Errors:

Runtime: the program works, but doesn't work as intended, so its essentially a logic error. but in this case, you dont have time to stop it, and you produce a crash. e.g. you get an infinite loop. Logic: you put in an incorrect logic?/function? Syntax: when you don't type it right, the program WILL NOT WORK. - depending on the type of program, the programming language will identify errors differently.

2 types of ways: Compiler and interpreter

BOTH CONVERT SOURCE CODE TO MACHINE CODE

compiler is much faster, as its not going line by line. HOWEVER, AS IT DOES IT ALL AT THE SAME TIME, IT CANT IDENTIFY WHERE OR WHAT THE ERROR IS.

for interpreters, as its going line by line, it will tell you where errors are, which line they are, and what type.

THEY CANNOT IDENTIFY LOGIC ERRORS, AND GENERALLY CANNOT FIND RUNTIME ERRORS (unless it just straight up crashes)

HOW TO IDENTIFY LOGIC ERRORS:

there are two types of trace tables: