Showing posts with label Programming Language. Show all posts
Showing posts with label Programming Language. Show all posts

Tuesday, October 15, 2019

Lesson 6 : ARRAY

An array is a collection of value or items stored in a memory location in a contagious way. The idea is to store multiple values or data of the same type together or close to each other using an offset to the base value to make it easier to calculate.

Think about the idea of an array as a staircase where your friends are standing on each step from you who is standing on the first step as the base value of the array. Now imagine the view if you look at it from the top of them.

Another example is a shoe rack where it is only one shoe rack but holds more than one shoes, or a lunch box which has divisions and is capable of storing different types of food.

In programming, an array is used as a data structure, see example below:

Memory Address
201
202
203
204
205
206
207
208
209
Value
and
is
or
it
if
lie
shy
go
born
Index/Offset
0
1
2
3
4
5
6
7
8

The indexing method of the array is based on the programming language used. Example there are programming languages which allows the programmer to start at index 1 or negative index like -1 but most commonly used index as a base of an offset is positive zero (0).

Example:

arr[10] = arr is the name of the variable and the number inside the bracket is the length of the array or the number of offset an array could have. In this example we have [10] so the total number of offset is 10 or 0,1,2,3,4,5,6,7,8,9


Memory Address
201
202
203
204
205
206
207
208
209
210
Value
and
is
or
it
if
lie
shy
go
born
gym
Index/Offset
0
1
2
3
4
5
6
7
8
9

so if I say arr[8] I am referring to value “born”

How to initialize an array variable

Example:

Java/C/C++

int[] arr = new int[10]; = this one is created without default value but with default length
int arr = {0,1,2,3,4,5,6,7,8,9}; = this one is created with default value and length

VB.Net
Dim arr(0 to 9) as Integer = this one is created without default value but with default length
Dim arr as Integer = {0,1,2,3,4,5,6,7,8,9} = this one is created with default value and length

To add a value on an offset simply access the offset number

arr[5] = “sample value”;

To update the value of an offset simply access the offset number

arr[5] = “new value”;

or arr[5] = “”; to remove the value

To retrieve or display a value from a specific offset or index of an array you can do the following:

Example:

C Programming Language
     Printf(“The value of index 5 is: %s”,arr[5]);



C++ Programming Language
     Cout<<“The value of index 5 is: %s”,arr[5]
Java Programming Language
     System.out.print(“The value of index 5 is: ”+arr[5]);

VB.net
     Console.Writeline(“The value of index 5 is: ” & arr[5])

Download PDF File

Monday, October 14, 2019

Lesson 5 : FOR LOOP and DO WHILE LOOP/WHILE LOOP

In computer programming, there are certain times when you have to iterate through a series of values and perform a task in each value. This case could be addressed using a looping statement which will continue to execute a command until the condition returns false.

There are several types of looping statement in computer programming like:
  1. For Loop
  2. For Each
  3. Do While
  4. While
  5. Do Until
But in this lesson, we will only use For Loop and Do While because another looping statement will become easier to understand once you’ve learned how to use the two most common looping algorithms.

FOR LOOP
This looping statement has three important parts or parameters necessary for operation.
  • Initialization
  • Condition
  • Increment/Decrement
Initialization = this refers to the initialization of value to the pilot variable.

Example: For (int a=0;)

Condition = this refers to the condition to meet before the execution of the following commands will stop.

Example: For (int a=0;a<10;)

Increment = this refers to the third parameter of For Loop necessary to meet the condition. For example, if our condition is for variable A to reach the value of 10 then we have to increment the value of variable A from 0

Example: For (int a=0;a<10;a++) 

This example means that as long as the value of variable A is less than 10 it will continue to execute the commands and increment the value of variable A. In the same manner, if the condition is to reach a lower value from higher then instead of incrementing the value of variable A we will decrease its value using a—command

Example: For (int a=10;a>0;a--) from value 10 we will reduce the value to zero each time the for loop executes.

Example in C/C++/Java

For(int a=0;a<5;a++){
     System.out.println(“Hello World”);
}

Example in VB.Net

For int a=0 to 5
     Console.WriteLine (“Hello World”)
next

Output:

Hello World
Hello World
Hello World
Hello World
Hello World

Explain:

System.out.println(“Hello World”); = this line of code will be executed 5 times because the value of variable A starts from ZERO, so the count will be 0, 1, 2, 3, 4. It will stop at 4 because the next value 5 is no longer less than to number 5 but equal.

a++ = it will increment the value of variable A from value zero to 5.
Do While

Just like For Loop, this algorithm will execute a command repeatedly until a condition returns False.
There are three important parts necessary in order to complete the algorithm:

  1. Start
  2. Increment/Decrement
  3. Condition

Start = this is where the program starts to execute the command and it is represented by the word “DO” and an open curly brace.

Example: Do{

Increment = like For Loop, do while needs to increment of decrement the value of the pilot variable to meet the condition. It is usually located inside the curly brace.

Example: Do { A++; }

Condition = like For Loop, do while uses Boolean Expression to determine if it still has to execute the commands or exit the algorithm. This usually located enclosed in a parenthesis of while as a parameter.

Example: }While(A<5);

Example C/C++/Java:

Int A; //variable declaration
A = 0; //variable initializaton
Do{ //start
     System.out.println(“Hello World”); //statement
     A++; //increment or could be decrement depending on the condition
}While(A<5) //condition


Example VB.Net:
       Dim A as integer
     A = 0
     While A<5
          Console.WriteLine(“HelloWorld”)
     End While


Output

Hello World
Hello World
Hello World
Hello World
Hello World

Download PDF File

Lesson 4 : IF ELSE STATEMENT and SWITCH CASE STATEMENT

Even before computers, humans already created a program which affects outcome like programming a student’s mind about their grades, how they could pass or fail. in this lesson, we will talk about conditioning a program, a software how it will produce an output or outcome base on the given input.

Example: If a student always attends classes the student will pass the school year or else he will fail.

The statement above presents a condition about how a student could pass or fail a class and in the same manner and principle, we could create a simple statement that will determine the output of a program in computer programming.

There are two types of a conditional statement in computer programming which will use ternary operators where the first operand is a Boolean expression, and the second and third operand values.
  1. IF ELSE STATEMENT
  2. SWITCH CASE STATEMENT
An operator will compare a given value to a specific value or constant. When a condition meet the program will execute a command or perform a task for an output display or value to return.

List of Operators (Boolean Expressions)
  • > Greater Than
  • < Less Than
  • = or == Equal To
  • != or <> Not Equal To
  • <= Less Than or Equal To
  • >= Greater Than or Equal To
Basic Mathematical Operators
  • + Addition
  • - Subtraction
  • / Division
  • * Multiplication
In a conditional statement, we will use the Boolean expression

Example:

5 > 3

Where 5 is the second operand or the left operand and a value, 3 is the third operand and also a value while > or greater than is the first operand or a Boolean expression.

Example (IF ELSE STATEMENT):

C/C++/Java

If (attendance_count = 180) {
     remarks = "Pass";
}Else{
     remarks = "Fail";
}

VB.Net

If attendance_count = 180 then
     remarks = ""Pass";
Else
     remarks = "Fail";
End If

Explanation:

In the example above, If (attendance_count = 180) { or If attendance_count = 180 then this line will evaluate the value of variable attendance_count to see if it is equal to 180 which is the number of days or less than. In this case, if the value is 180, it will put a value “Pass” in variable remarks and “Fail” if it does not reach 180. So if this lines If (attendance_count = 180) { or If attendance_count = 180 then return True it performs the next line which is giving remarks of Pass and if it returns False it will perform the line after Else.

Example (SWITCH CASE STATEMENT):

C/C++/Java

Switch (Grades){
     case 95:
          remarks = “Excellent”;
     break;
     case 85:
          remarks = “Very Good”;
     break;
     case 75:
         remarks = “Pass”;
     break;
     case 74:
          remarks = “Failed”;
     break;
}

VB.Net

Select Grades
     case 95
          remarks = “Excellent”
     break
     case 85
          remarks = “Very Good”
     break
     case 75
          remarks = “Pass”
     break
     case 74
          remarks = “Failed”
     break
End Select

Explanation:

Just like IF ELSE STATEMENT, SWITCH CASE or SELECT CASE is a conditional algorithm using Boolean result to perform specific task. The process Is the program will read the value of variable Grades and compare it to different cases values like Switch Grades to case 1. It means that if the value of Grades variable is equal to 95 then variable remarks will be assign with a value “Excellent”, “Very Good” for 85, “Pass” for 75 and “Failed” for 74.

break; = this line of code will tell the program to execute until there only, it will break the operation without performing the next lines of codes.

Example Program in Java:

IF ELSE STATEMENT

public class BooleanExpression{
     public static void main(String[] args){
          //Start Declaration
          int Grade;
          String remarks;
          //End Declaration
          //Start Initialization
          Grade = 85;
          Remarks = “”;
         //End Initialization
         //Start If Else Condition
         If (Grade == 95){
             remarks = “Excellent”;
         }else if(Grade == 85){
             remarks = “Very Good”;
         }else if(Grade == 75){
           r emarks = “Pass”;
         }else if(Grade == 74){
            remarks = “Failed”;
         }
         //End Condition
     }
}


SWITCH CASE

public class BooleanExpression
     public static void main(String[] args){
          //Start Declaration
          int Grade; 
          String remarks;
          //End Declaration
          //Start Initialization
          Grade = 85;
          Remarks = “”;
          //End Initialization
          //Start Condition
          Switch (Grade){
               case 95:
                    remarks = “Excellent”;
               break;
               case 85:
                    remarks = “Very Good”; 
               break;
               case 75:
                    remarks = “Pass”; 
               break;
               case 74:
                    remarks = “Failed”; 
               break;
          }
          //End Condition
     }
}

Lesson 3: Data Types

In computer science and computer programming, a data type or simply type is an attribute of data which tells the compiler or interpreter how the programmer intends to use the data

List of Common Data types

Integer/Long
Float/Double
Char
String/Text
Boolean

Integer = An integer type value is a whole number representation in 32 bits, this means any variable in your program with integer type will not accept numbers with fractions like 1.1,1.2,3.8 but will only accepts numbers like 1,8,3,9,10,22.

Example Declarations:

C/C++ 
     int variablename;

Java 
     int variablename;

Visual Basic 
     Dim variablename as Integer

Long = Long variable type is a whole number representation just like Integer but in a 64 bits and will accept values bigger than Integer type.

Example Declarations:

C/C++ 
     long variablename;

Java 
     long variablename;

Visual Basic 
     Dim variablename as Long

Float and Double = This is real numbers representation. This will accept whole numbers and numbers with fractions as well.

Example Declarations:

C/C++ 
     float variablename; double variablename;

Java 
     float variablename; double variablename;

Visual Basic 
     Dim variablename as Double (Basic will only accepts Double)

Char = Char data type will accepts values like letters, a single character, this will not accepts word/s or a series of characters, a sentence.

Example Declarations:

C/C++ 
     char variablename;

Java 
     char variablename;

Visual Basic 
     Dim variablename as char

String/Text = Unlike char, this data type will accepts a series of characters, word/s, a sentence, even a paragraph.

Example Declarations:

C/C++ 
     char variablename[5]; //array of cahracters with length 5 or
     Char* variablename: //a char pointer

Java 
     String variablename;

Visaul Basic 
     Dim variablename as String

Boolean = A data type which only holds value of zero or one or a true/false.

Example Declarations:

C/C++ 
     bool variablename;

Java 
     boolean variablename;

Visual Basic 
     Dim variablename as Boolean

Download PDF File

Lesson 2 : Programming Skills

Any one could learn programming and become a skilled programmer, a person with programming skills are good at three aspects of this skill.

3 Pre-requisite to become a Skilled Programmer
  1. Problem Solving Skills
  2. Algorithmic Notation
  3. Programming Language
Problem Solving Skills

Programming does not require a deep or massive knowledge of mathematics but it is a plus for aspiring programmers. A problem solving skill is a type of skill which make a person able to develop a solution to given problem either mathematical or logical problems, numbered equations or intellectual scenarios and decision making.

Algorithmic Notation
  • Algorithm is a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.
  • An Algorithmic Notation is a set of functions, rules or process use to perform task to solve computing problems.
Algorithmic Notation can be presented into three parts:
  1. Problem Analysis using Input -> Process -> Output (IPO) model
  2. Flow Chart (with Simulation)
  3. Pseudo code
Problem Analysis

Using IPO model to analyze a problem. I represents the Given, P represents the Action to be taken and O represents the Outcome or Result.

Example

Problem:
Mario is ask to identify the minimum and maximum number from two given numbers 5 and 3.

Analysis:
I = Numbers 5 and 3
P = Compare two given numbers
O = Minimum and Maximum

Flowchart


Graphical representation of steps, it shows steps in a sequential order, and is widely used in presenting flow of algorithms, workflow or processes. Flowchart similarly looks like an Activity Diagram of UML but the main difference is that Activity Diagram behavior diagram that represents the workflow of stepwise activities of the system while a flowchart is a graphical diagram that represents the sequence of steps to solve a problem.

Symbols used in Flow Chart




Pseudo code

Pseudo code Is a notation resembling a simplified programming language, used in program design and very similar to a natural language or English language with a mixture of mathematical equations and symbols sometimes. Learning to write a good Pseudo code is closer to be able to write program codes in different programming languages

Example: In this example we will still use the previous problem and Flowchart

Step 1: Declare four integer variable

Say…
int A, int B, int Min, int Max

Step 2: Initialize A and B with numbers supplied by the user
Let A = ?
Let B = ?

Step 3: Compare the value A to B
Say…
If the value of A is greater than the value of B then
Assign the value of B to variable Min
Assign the value of A to variable Max
Else
Assign the value of A to variable Min
Assign the value of B to variable Max
End if
Step 4: Display output
Print Min and Max

Or we could do it this way…

Declare four integer variable A, B, Min and Max
Initialize variable A and B with user input
If the value of A is greater than the value of B then
Assign the value of B to variable Min
Assign the value of A to variable Max
Else
Assign the value of A to variable Min
Assign the value of B to variable Max
End if
Print Min and Max

Programming Languages

= A programming language is a vocabulary and set of grammatical rules equivalent to human language used for instructing a computer or computing device to perform specific tasks.
= A series of codes of instructions to control the operation of a computer or other machine.

Two Levels of Programming Languages

1. Low Level Programming Languages


This level of programming languages are closed to machine language or raw in nature and harder to read than high level programming languages.

Example: Assembly x86

SUB AX,AX
MOV ES,AX
SUB BH,BH
MOV BL,INT_NUMBER
SHL BX,1
SHL BX,1
MOV DI,ES:[BX]
MOV ES,ES:[BX+2]
ADD DI,4
LEA SI,TAG
MOV CX,TAG_LEN
2. High Level Programming Languages

This level of programming languages is much closer to human or natural language, usually English language and more readable than low level programming language examples are C, Java, Basic, Cobol, Fortran, Ruby, Python.

Example: Java

public class Welcome{
     public static void main(String[] args){
          System.out.println("HELLO WORLD!");
     }
}

When learning programming language, it is a prerequisite to learn what the important parts of a programming language are.
  1. Syntax
  2. Semantics
Syntax and Semantics are significant terms relating to any programming language. Syntax involves the set of permitted phrases of a language while semantics expresses the associated meaning of those phrases. In other words when relating to a natural language, Syntax is the grammar of a programming language while the semantic is the meaning or thought of the code or the syntax.

Learning how to program requires only to master one programming language as a beginner, then this will make anyone able to write codes using other programming language, you only need to understand the semantic one time for it is always applicable to different programming language but you need to learn different syntax to master different programming languages. It is like translating a Tagalog language to English terms.

Example:

Natural Language
Tgagalog : Ako ay Pilipino
English : I am a Filipino

Programming Language 

Java Programming Language JAVA 

If(A>B){
     Min = B;
     Max = A;
}Else{
     Min = A;
     Max = B;
}

Java Programming Language VB.net

If A>B then
     Min = B;
     Max = A;
Else
     Min = A;
     Max = B;
End if

Lesson 1 : What is Programming Languages

A programming language is a vocabulary and set of grammatical rules equivalent to human language used for instructing a computer or computing device to perform specific tasks. A program is a series of codes of instructions to control the operation of a computer or other machine.

Two Levels of Programming Languages 

1. Low Level Programming Languages

This level of programming languages is closed to machine language or raw in nature and harder to read than high level programming languages.

Example: Assembly Language

SUB AX,AX
MOV ES,AX
SUB BH,BH
MOV BL,INT_NUMBER
SHL BX,1
SHL BX,1
MOV DI,ES:[BX]
MOV ES,ES:[BX+2]
ADD DI,4
LEA SI,TAG
MOV CX,TAG_LEN


2. High Level Programming Languages


This level of programming languages is much closer to human or natural language, usually English language and more readable than low level programming language.

Example: C, Java, Basic, Cobol, Fortran, Ruby, Python
Code: (Java) 

public class Welcome{
     public static void main(String[] args){
          System.out.println("HELLO WORLD!");
     }
}


Download PDF File

A REVIEW ON CONNIE DABATE’S MURDER CASE: Fitbit One Wearable

T he Author   ROSITO D. ORQUESTA MSIT Student at Jose Rizal Memorial State University-Dapitan Campus OIC-ICT Dean, Eastern Mindanao College ...