Intermediate Programming Concepts (PDF)

Summary

This document provides an introduction to intermediate programming concepts and explains flowcharts, variables, and data types. It covers various programming concepts essential for learning and understanding how different data types and variables work.

Full Transcript

# FLOWCHART Let's start with flowcharts. Flowcharts are structured step by step plans for software, apps, or systems that are graphically illustrated. They contain symbols that represent unique functions. Below is a simple example of a flowchart that adds two numbers. ## Flow Chart Flow Chart: a...

# FLOWCHART Let's start with flowcharts. Flowcharts are structured step by step plans for software, apps, or systems that are graphically illustrated. They contain symbols that represent unique functions. Below is a simple example of a flowchart that adds two numbers. ## Flow Chart Flow Chart: adding two numbers. * START * INPUT NUM1 * INPUT NUM2 * SUM = NUM1 + NUM2 * DISPLAY SUM * END # FLOWCHART SYMBOLS These are some of the symbols of flowcharts: * **TERMINAL:** Start and end point of a flow chart. * **INPUT/OUTPUT:** Represents Input and output of the data. * **PROCESS:** Represents operation being perform. * **ARROW:** Represents the direction of the process flow. * **DECISION:** Represents a choice. # Display Method: The 'print method' in programming takes information or data and 'shows' it on the 'screen or console'. This is useful, especially for checking the logic of your code. Another term for this is the 'display method' or 'output'. The code below is a simple program called 'Hello, World!'. It demonstrates how the display method works. ```c++ #include <iostream> using namespace std; int main() { cout << "Hello World" << endl; return 0; } ``` * **`#include <iostream>`:** Means that we are going to include the `<iostream>` header file' because it provides functionality to input and output. * **`using namespace std;`:** This means that the compiler will use the 'std'. This can help us to simplify our coding if we are going to write a simple short code. * **`int main() {}`:** This is the 'main function'. 'main' is a special function name, and 'int' means that our function should return an integer. The 'parenthesis' are where we would place our parameters (which we will discuss later). Inside the 'curly braces' is where we type the block of code that we want the function to execute. * **`cout << "Hello World" << endl;`:** 'cout' means character output. 'Hello World' is a string literal that will be displayed and 'endl' is use for new/next line. Don't forget the 'semi-colon (;)' after each statement to stop. * **`return 0;`:** Remember that our main function is defined as int main(). This means we need to 'return an integer' at the end of our function. We use 'return 0;' to indicate that the program has executed successfully. # Data Types: 'Data types' specify the 'kind of data' that will be used or stored inside a variable. This will also determine the value and the kinds of operations that can be performed. * **Characters (char):** Represents a single character. Example: a, b, c, $, ?, ```c++ char SingleCharacter = 'A'; ``` * **String (string):** Represents a string of characters, basically a word, words or phrases. Example: Hello?, Hello World. ```c++ string WordPhrase= "Hello World"; ``` * **Integers (int):** indicates a whole number, positive or negative. Example: -3, -2, -1, 0, 1, 2, 3 ```c++ int Number = 25; ``` * **Float (float):** Represent a number with a decimal value. Example: 1.3, 2.75, 3.140, 10.05 ```c++ float Pi = 3.14; ``` * **Double (double):** Represent a number with a long decimal value. Example: 7.43827487246837264 ```c++ double doubleData = 147.43483743333333; ``` * **Boolean (bool):** A data type that represent true or false value. ```c++ bool isTrue = true; ``` # Variables: 'Variables' are like labeled 'containers' in a program's memory, allowing you to store and manipulate data. A variable can hold different types of information, such as numbers, text etc.. ```c++ int age = 30; cout << "The person's age is: " < age << endl; ``` We create a variable called 'age' and assign the value '30' to it. These are some of the example of variable with different data types: ```c++ #include <iostream> using namespace std; int main() { string palayaw = "doji"; int edad = 24; char gender = 'M'; float timbang = 70.5; double tangkad = 89.473847638746384; bool ayStudent = false; cout << palayaw << endl; cout << edad << endl; cout <<< gender << endl; cout < timbang << endl; cout << tangkad << endl; cout << ayStudent << endl; // 1 = true //0 = false return 0; } ``` # Variable Declaration, Initialization & Assigning: These are different ways of creating ang managing variables, these 'three' are some of the primary ways that are essential to learn as a beginner. * **Declaration:** This is where you declare a variable without necessarily assigning a value. ```c++ int age; // Declaration ``` * **Assigning:** This is when you lately give a value to a declared variable. ```c++ int age; // Declaration int age = 20; // Assigning A Value ``` * **Initialization:** This is when you declare a variable and assign a value to it at the sametime. ```c++ int age = 20; // Initialization ``` # Concatenation This is the process of 'combining 2 or more strings' together. ```c++ #include <iostream> using namespace std; int main( string firstName = "dloji"; string lastName = "creates"; cout << firstName + " " + lastName << endl; return 0; } // output: doji creates ``` # Append: Is another way of combining. This is when you 'add an element to the end of a container'. We can also use this for concatenation. ```c++ #include <iostream> using namespace std; int main( string firstName = "doji"; string lastName = "creates"; string fullName = firstName.append(lastName); cout << fullName << endl; return 0; } // output: dojicreates ``` # ARITHMETIC OPERATORS These operators are used to perform 'mathematical calculations'. Operators: + - \* / % * **Addition:** + ```c++ int sum = 4 + 3; // result is 7 ``` * **Subtraction:** - ```c++ int difference=12-6; // result is 6 ``` * **Multiplication:** \* ```c++ int product = 9\*9; // result is 81 ``` * **Division:** / ```c++ int quotient = 15/3; // result is 5 ``` * **Modulus:** % ```c++ int remainder = 10% 3; // result is 1 ``` # COMPARISON OPERATORS # RELATIONAL OPERATORS These operators are used to 'compare two values' then return a boolean result. Operators: ==, !=, >, <, >=, <=, * **Equal to:** == ```c++ int equalTo = 5 == 10; //False, 5 is not equal to 10 int equalTo = 8 == 8; // True 8 is equal to 8. ``` * **Not Equal to:** != ```c++ int notEqualTo = 5 != 10; //True, 5 is not equal to 10 int notEqualTo = 4 != 4; //False, 4 is equal to 4 ``` * **Greaterthan:** > ```c++ int greater Than =5> 10; // False, 5 is not greater than 10 int greater Than = 10 > 5; // True, 10 is greater than 5. ``` * **Greaterthan or Equal to:** >= ```c++ int GTET = 5 >= 10; //False, 5 is not greater than or equal to 10 int GTET = 10 >= 5; //True, 10 is greater than 5 int GTET = 10 >= 10; //True, 10 is not greater than 10, but they are equal ``` * **Lessthan:** < ```c++ int lessThan = 5 <10; //True, 5 is less than 10 int lessThan = 10 < 5; // False, 10 is not lessthan 5 ``` * **Lessthan or Equal to : >=** ```c++ int LTET = 5 <= 10; // True, 5 is less than to 10 int LTET = 10 <= 5; // False, 10 is not less than or equal to 5 int LTET = 5 <= 5; // True, 5 is not less than to 5 but they are equal ``` # LOGICAL OPERATORS These operators are used to perform logical operations. Operators: AND (&&), OR (II), NOT (!) * **AND:** This logical operator will 'return TRUE' if both operands are true. If either of the operands is false, it will 'return FALSE.' ```c++ #include <iostream> using namespace std; int main() { bool coffee = true; bool milk = true; bool given = coffee && milk; cout << given << endl; return 0; } //result: TRUE bool coffee = false; bool milk = true; bool given = coffee && milk; //result: FALSE ``` * **OR:** This logical operator will 'return TRUE' if at least one of the operands is true. If both operands are False, then it will 'return FALSE'. ```c++ #include <iostream> using namespace std; int main() { bool coffee = true; bool milk = false; bool given = coffee || milk; cout << given << endl; return 0; } //result: TRUE bool coffee = false; bool milk = false; bool given = coffee || milk; //result: FALSE ``` * **NOT:** This logical operator will 'return the opposite Boolean value'. If operand is true, it will return false. If operand is false, it will return true. ```c++ #include <iostream> using namespace std; int main() { bool coffee = true; bool milk = false; cout << !coffee << endl; cout << !milk << endl; return 0; } // result: // false // true ```

Use Quizgecko on...
Browser
Browser