PROGRAMMING CONCEPTS
By Joshpal Sahota
INTRODUCTION• In this presentation I will be explaining the very basics of programming
and will include the following programming concepts in my presentation:
SELECTION ITERATION DATA STRUCTURE FUNCTIONS, PARAMETERS AND/OR RETURN VALUES
TUTORIAL LESSON – PART 1 (SELECTION)
IF ELSE STATEMENTS• An if statements can be used conjunctively with if else statements. • When the Boolean expression of an if statement is false, the if else
statement will be executed.• Else if statements are incredibly useful when testing a number of
conditions.• Else statements are use when none of the other conditions are true.
TUTORIAL LESSON – PART 1 (SELECTION)
TUTORIAL LESSON – PART 1 (SELECTION CONTINUED)
SWITCH STATEMENTS• These are very similar to if statements, only it has many more conditions.• Switch statements tend to run faster than if statements.• They can be used with any numerical data type for example, char and int
but not with text data types such as string.
TUTORIAL LESSON – PART 1 (SELECTION CONTINUED)
TUTORIAL LESSON – PART 2 (ITERATION)
• The ultimate use of a loop is to repeat a block of code and is one of the most useful tasks in programming.
• There are different types of loops, FOR loops are the most useful as they are an easy way of creating loops when the number of iterations are known.
TUTORIAL LESSON – PART 3(DATA STRUCTURE)
• When including structures we must use the struct keyword followed by the structure name.
• The curly brackets after struct will declare the things that are contained within the structure.
• Struct is only a definition for what the structure will look like and so you have to declare a structure in memory of the student type. We will call it stud.
• In order to access the structure name and the sub item a ‘.’ must be used between the two.
TUTORIAL LESSON – PART 3(DATA STRUCTURE CONTINUED)
• Arrays are a group of variables that uses one name instead of many. Individual variables are accessible by using a number.
• To declare an array you must include square brackets after the name of the array.
• The square brackets must include a number of variables/elements which are included within the array.
• The number of arrays start from 0 (not 1) and can be displayed below the declaration of the array.
TUTORIAL LESSON – PART 4• We use the code “#include <iostream>” which will allow us to print
words on the screen.• The code “using namespace std;” will allow you to enter lines of code
without having to write out the full code.• “int main()
{}”The curly brackets show where the main function starts and ends. Every program must include a main function and the word ‘int’ is to give an indication as to what the return value will be.
TUTORIAL LESSON – PART 4