Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

COMPUTER PROGRAMMING REVIEWER

Programming Language - is a vocabulary and set of grammatical rules for instructing a


computer or computing device to perform specific tasks. Examples: as BASIC, C, C++, COBOL,
Java, FORTRAN, Ada, and Pascal.
- is a vocabulary and a set of grammatical rules for instructing a
computer system to perform any specific task.

Classification of Programming Languages (Levels/Generation)


o Machine Level Language - It’s the lowest level and named as first generation of
programming language. Machine level language consist only two condition i.e. either true
(1) or false (0); this type of language known as binary language.
o Assembly Level Language - It’s a middle level and named as second generation
programming language. It contains the same instruction as machine level language, but
the instructions and the variables have specific name or called commands instead of
being just binary numbers. It also uses symbols to describe field of instructions. One
statement per instruction such as: register allocation, call, stack, timer, jump, loop etc.
o High-Level Language - High level language is the upper level language and also known
as third generation programming language. It does consider as high level because, which
language comes under this category are closer to human languages. Hence this is highly
understood programming language by human. There have many examples of high level
languages such as, FORTRAN, Pascal, C, C++, JAVA, ADA, COBOL, LISP, Prolog etc.
(1950s, first high level programming language)

Algorithm - is a set of well-defined instructions in sequence to solve the problem.


Examples of Algorithm
Write an algorithm to add two numbers entered by user.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
Write an algorithm to find the largest among three different numbers entered by user.
Step 1: Start
Step 2: Declare variables a, b and c.
Step 3: Read variables a, b and c.
Step 4: If a>b
If a>c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
Write an algorithm to find all roots of a quadratic equation ax2+bx+c=0.
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
D←b2-4ac
Step 4: If D≥0
r1←(-b+√D)/2a
r2←(-b-√D)/2a
Display r1 and r2 as roots.
Else
Calculate real part and imaginary part
rp←b/2a
ip←√(-D)/2a
Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop
Write an algorithm to find the factorial of a number entered by user.
Step 1: Start
Step 2: Declare variables n,factorial and i.
Step 3: Initialize variables
factorial←1
i←1
Step 4: Read value of n
Step 5: Repeat the steps until i=n
5.1: factorial←factorial*i
5.2: i←i+1
Step 6: Display factorial
Step 7: Stop
Write an algorithm to check whether a number entered by user is prime or not.
Step 1: Start
Step 2: Declare variables n,i,flag.
Step 3: Initialize variables
flag←1
i←2
Step 4: Read n from user.
Step 5: Repeat the steps until i>(n/2)
5.1 If remainder of n÷i equals 0
flag←0
Go to step 6
5.2 i←i+1
Step 6: If flag=0
Display n is not prime
else
Display n is prime
Step 7: Stop
Write an algorithm to find the Fibonacci series till term≤1000.
Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term←0 second_term←1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term≤1000
5.1: temp←second_term
5.2: second_term←second_term+first term
5.3: first_term←temp
5.4: Display second_term
Step 6: Stop

Algorithm is not the computer code. Algorithm are just the instructions which gives clear idea to
your idea to write the computer code.

Flowchart - is a diagrammatic representation of an algorithm. Flowchart are very helpful in


writing program and explaining program to others.
o Flow line (Arrow) – connecting symbol
o Terminal (Oblong) – to start and end
o Input/output (Rhombus) – input and output operation
o Processing (Rectangle) – Arithmetic operations and data manipulations
o Decision (Diamond) – Two alternates, true or false
o On-page connector (Circle) – join different flowline
o Off-page connector (Inverted Pentagon) – connect flowchart on different page
o Predefined Process/function (Rectangles) – represent a group of statements

Difference between source, executable, and object file


o Source file is the human understandable form.
o Object file is the intermediate form between source and executable. Object file is the file
output by the compiler or assembler. Usually this contains the source code converted to a
machine language or an intermediate language.
o Executable file is the machine understandable form. Executable file is the final output,
which can be understood by the machine. The object code is linked and placed into a
special format which can be understood by the machine (or to be specific, understood by
the operating system). The executable file formats are platform dependent.
Python - Python refers to the Python programming language (with syntax rules for writing what
is considered valid Python code) and the Python interpreter software that reads source code
(written in the Python language) and performs its instructions.
- The Name Python comes from the surreal British comedy group Monty Python, not
from the snake. Python programmers are affectionately called Pythonistas, and both Monty
Python and serpentine references usually pepper Python tutorials and documentation.

Expression is the most basic kind of programming instructions in the language. For example, 2
+ 2.
Expressions are consisting of values. For example, 2. Also operators. For example, +.

Exponent (**)
Modulus/remainder (%)
Integer division/floored quotient (//)
Division (/)
Multiplication (*)
Subtraction (-)
Addition (+)
*** Follows PEMDAS ***

Data types
o Integers – 2,1,-1
o Floating-point numbers - -1.25,0.75,1.5
o Strings – ‘a’,’aa’,’aaa’

String Concatenation and Replication


o ‘Alice’+’Bob’ = 'AliceBob’
o ‘Alice’*5 = ‘AliceAliceAliceAliceAlice’

Storing values - A variable is like a box in the computer’s memory where you can store a single
value.

Programs
Note: stored values are always in string.

Operators
Equal to (==)
Not equal to (!=)
Less than (<)
Greater than (>)
Less than or equal to (<=)
Greater than or equal to (>=)

Blocks of Codes
If statements - The most common type of flow control statement is the if statement. An if
statement’s clause (that is, the block following the if statement) will execute if the statement’s
condition is True.
Else statements - An if clause can optionally be followed by an else statement. The else clause
is executed only when the if statement’s condition is False.
Elif statements - While only one of the if or else clauses will execute, you may have a case
where you want one of many possible clauses to execute. The elif statement is an “else if”
statement that always follows an if or another elif statement.
While loop statements - You can make a block of code execute over and over again with a
while statement. The code in a while clause will be executed as long as the while statement’s
condition is True.

Break statements - There is a shortcut to getting the program execution to break out of a while
loop’s clause early. If the execution reaches a break statement, it immediately exits the while
loop’s clause. In code, a break statement simply contains the break keyword.
Continue statements - Like break statements, continue statements are used inside loops. When
the program execution reaches a continue statement, the program execution immediately jumps
back to the start of the loop and reevaluates the loop’s condition. (This is also what happens
when the execution reaches the end of the loop.)

You might also like