🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

01_Handout_1(2).pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

ITJH2401 INTRODUCTION TO PROGRAMMING The fundamental programming concepts form the foundation upon which all software development is built. These concepts are universa...

ITJH2401 INTRODUCTION TO PROGRAMMING The fundamental programming concepts form the foundation upon which all software development is built. These concepts are universal across programming languages and frameworks. Irrespective of the programming language we choose to learn, the basic programming concepts are similar across languages. Algorithms Algorithms are step-by-step procedures designed to solve specific problems and perform tasks efficiently in the realm of computer science and mathematics. These powerful sets of instructions form the backbone of modern technology and govern everything from web searches to artificial intelligence. How Algorithms Work: Input - Algorithms take input data, which can be in various formats, such as numbers, text, or images. Processing - The algorithm processes the input data through a series of logical and mathematical operations, manipulating and transforming it as needed. Output - After the processing is complete, the algorithm produces an output, which could be a result, a decision, or some other meaningful information. Efficiency - A key aspect of algorithms is their efficiency, aiming to accomplish tasks quickly and with minimal resources. Optimization - Algorithm designers constantly seek ways to optimize their algorithms, making them faster and more reliable. Implementation - Algorithms are implemented in various programming languages, enabling computers to execute them and produce desired outcomes. A programming algorithm is a procedure or formula used for solving a problem. It is based on conducting a sequence of specified actions in which these actions describe how to do something. An algorithm works by following a procedure made up of inputs. Once it has followed all the inputs, it will see a result, also known as output. Example: Find the largest number among the three. Declare variables a, b, and c. If a > b If a > c Display a is the largest number. Else Display c is the largest number. Else If b > c 01 Handout 1 *Property of STI  [email protected] Page 1 of 5 ITJH2401 Display b is the largest number. Else Display c is the greatest number. Stop Syntax Every programming language has its syntax, and we must learn the fundamental syntax of the language we are learning. Syntax refers to the set of rules defining a language’s structure. In programming, syntax is similar to grammar in human languages. It consists of a set of rules that specify the correct combination of symbols, keywords, and punctuation needed to write a program that a computer can execute. For example, let us see the syntax to print a simple Welcome to programming! #This is a comment print("Welcome to programming!”) If the syntax of a language is not followed, the compiler or interpreter will not understand the code. Compilers convert programming languages into binary code that computers can understand. If the syntax is incorrect, the code will not compile. Interpreters execute programming at runtime. The incorrect syntax will cause the code to fail. Basic Syntax Components 1. Statements - Each statement performs a specific action, such as assigning a value to a variable or printing information to the screen. 2. Expressions - These are combinations of variables, operators, and values that produce a result. For example, in the expression 3 + 4, the result is 7. 3. Blocks - These are groups of statements that are treated as a single unit. Blocks are often enclosed by curly braces {} or are indented, depending on the programming language. 01 Handout 1 *Property of STI  [email protected] Page 2 of 5 ITJH2401 Variables Variables are containers for storing data values and are memory locations for data types. Variables are created using a declaration or keyword that varies across languages. This step is crucial because it sets aside memory space for the variable and specifies what kind of data the variable will hold. Although in pseudocode, we do not strictly adhere to language-specific syntax, the concept can be illustrated as follows: Declare variableName Declare is the keyword used to declare a variable. variableName is the placeholder for the name of the variable. For example: Declare name Declare color Declare money Declare grade Variable declaration is the process of defining a variable's name and, often, its data type. This informs the compiler or interpreter about the variable's existence and its intended use. Variables can hold values of any data type supported by the programming language. This value may change during program execution. For example: // Declare a string variable string name; string color; // Declare an integer variable int money; // Declare a float variable float grade; Scope Variable scope defines the context in which a variable can be accessed. Scopes can be local, global, or block - level: Local Scope: Variables declared within a function or block. Global Scope: Variables declared outside any function or block. Block Scope: Variables declared within a block, accessible only within that block. 01 Handout 1 *Property of STI  [email protected] Page 3 of 5 ITJH2401 Once a variable is declared, you can assign a value to it. This involves setting the variable to hold specific data. This can be done using an assignment operator (commonly represented as “=” in most languages). variableName = value variableName is the name of the previously declared variable. value is the data you want to store inside the declared variable. For example: name = “Rudeus” color = “Scarlet money = 748787587 grade = 92.8 Combined Declaration and Assignment In many programming scenarios, you might declare and assign a value to a variable in a single step. Declare variableName = value For example: Declare name = “Rudeus” Declare color = “Scarlet” Declare money = 7848787587 Declare grade = 92.8 Data Types Data types are the classification of data based on the type of value they hold and the operations that can be performed on them. Different programming languages have different data types, but the core concepts are generally the same. Here are some common data types: Integer - It represents whole numbers without a decimal point. Example: int age = 23 Float (or Double) - It represents real numbers with a decimal point. Example: 01 Handout 1 *Property of STI  [email protected] Page 4 of 5 ITJH2401 float temperature = 36.8 Boolean - It represents the values true and false. When working with the boolean data type, it is helpful to keep in mind that sometimes a boolean value is also represented as 0 (for false) and 1 (for true). Example: bool isCooked = true Character - It is used to store a single letter, digit, punctuation mark, symbol, or blank space. Example: char code = ‘F’ String - It is a sequence of characters and the most commonly used data type to store text. Additionally, a string can also include digits and symbols; however, it is always treated as text. Example: string menu =”Chicken Adobo” Array - Also known as a list, an array is a data type that stores a number of elements in a specific order and is a collection of elements of the same data type. Arrays will be 0-based and declared with the keyword array. Example: array mealMenu mealMenu = “Chicken Adobo” mealMenu = “Sinigang” mealMenu = “Menudo” print(mealMenu) Result: Chicken Adobo References: Gagniuc, P. A. (2023). An introduction to programming languages: Simultaneous learning in multiple coding environments. Springer. Hour of Code - What will you create? (n.d.). Code.org. https://hourofcode.com/us Perugini, S. (2021). Programming Languages: Concepts and implementation. Jones & Bartlett Learning. Scratch - imagine, program, share. (n.d.). https://scratch.mit.edu/ Wassberg, J. (2020). Computer programming for absolute beginners: Learn essential computer science concepts and coding techniques to kick-start your programming career. Packt Publishing Ltd. 01 Handout 1 *Property of STI  [email protected] Page 5 of 5

Use Quizgecko on...
Browser
Browser