Unit 1 PPS
Unit 1 PPS
1. Introduction to Programming,
2. Introduction to components of a computer system
3. Algorithm
4. Representation of Algorithm: Flowchart, Pseudo code and Source code with examples.
Ans Programming is the implementation of logic to simplify specified computing operations and functionality.
Ans A Computer system includes the computer along with software and hardware that are necessary to
operate a computer. The word computer comes from the word "compute" which means to calculate.
A computer may be defined as an electronic device, which can store and manipulate data and provide
result according to instructions fed by the user. A computer does this by performing arithmeti c and
logical operation at an enormous speed.
Ans The five classic components of a computer are briefly described below.
A computer system consists of both hardware and information stored on hardware. Information stored on
computer hardware is often called software. The hardware components of a computer system are the
electronic and mechanical parts. The software components of a computer system are the data and the
computer programs.
Processor (CPU)
Memory
Input devices
Output devices
The processor is an electronic device about a one-inch square, covered in plastic. Inside the square is an
even smaller square of silicon containing millions of tiny electrical parts. A processor may contain 100
million transistors. It does the fundamental computing within the system, and directly or indirectly
controls all the other components. The processor is sometimes called the Central Processing Unit or CPU.
A particular computer will have a particular type of processor, such as a Pentium chip or a SPARC chip.
Memory
A memory is just like a human brain. It is used to store data and instructions. Computer memory is the
storage space in the computer, where data is to be processed and instructions required for processing are
stored. The memory is divided into large number of small parts called cells. Each location or cell has a
unique address, which varies from zero to memory size minus one. For example, if the computer has 64k
words, then this memory unit has 64 * 1024 = 65536 memory locations. The address of these locations varies
from 0 to 65535.
i) Cache Memory
iii)Secondary Memory
i) Cache Memory: Cache memory is a very high-speed semiconductor memory which can speed
up the CPU. It acts as a buffer between the CPU and the main memory. It is used to hold those
parts of data and program, which are most frequently used by the CPU. The parts of data and
programs are transferred from the disk to cache memory by the operating system, from where the
CPU can access them.
Advantages
It stores the program that can be executed within a short period of time.
Disadvantages
Primary memory holds only those data and instructions on which the computer is currently
working. It has a limited capacity and data is lost when power is switched off. It is generally made
up of semiconductor device. These memories are not as fast as registers. The data and instruction
This type of memory is also known as external memory or non-volatile. It is slower than the main
memory. These are used for storing data/information permanently. CPU directly does not access
these memories, instead they are accessed via input-output routines. The contents of secondary
memories are first transferred to the main memory, and then the CPU can access it. For example,
disk, CD-ROM, DVD, etc.
Input Devices
These components help users enter data and commands into a computer system. Data can be in
the form of numbers, words, actions, commands, etc. The main function of input devices is to
direct commands and data into computers. Computers then use their CPU to process this data and
produce output. Some input devices are:
Keyboard
Mouse
Microphone
Bar code reader
Graphics tablet
Output Devices
The final component of a computer system is the output unit. After processing of data, it is
converted into a format which humans can understand. After conversion, the output units displays
this data to users. Thus, output units basically reproduce the data formatted by the computer for
users’ benefit. . Some output devices are:
Monitor
Printer
Speaker
Ans
Ans A program written in high-level language is called as source code. To convert the source code into machine
code, translators are needed. A translator takes a program written in source language as input and converts
it into a program in target language as output. It also detects and reports the error during translation.
• Translating the high-level language program input into an equivalent machine language program.
• Providing diagnostic messages wherever the programmer violates specification of the high-level
language program.
Compiler
Compiler is a translator, which is used to convert programs in high-level language to low-level
language. It translates the entire program and also reports the errors in source program
encountered during the translation.
Assembler
Assembler is a translator, which is used to translate the assembly language code into machine
language code.
Ans Algorithm : Algorithm is the set of steps written in human understanding language for representation of
logic for a specified task or operation. Algorithm is not the computer code. Algorithm are just the
instructions, which gives clear idea to write the computer code.
Algorithm helps programmers to write their logic of solving particular problem/program on the paper,
verify and correct if needed. Also it lets programmers to make their solution effective an efficient. Simple
tasks like algebraic operations (E.g. Addition, subtraction, multiplication, division etc) are easy and may
not need algorithms but complicated problem/task solving needs algorithms to be written before writing
its actual program solution.
Examples :
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
Step 1:
Start
Step 2:
Declare variables num1, num2, num3, avg and sum.
Step 3:
Read values num1, num2 and num3.
Step 4:
Add num1, num2 and num3 and assign the result to sum.
Sum ← num1 + num2 + num3
Step 5: avg ← sum/3
Step 6: Display avg
Step 7: Stop
Step 1: start
Step 2: declare p-amnt, n-years, r, intrst
Step 3: read p-amnt, n-years, r
Step 4: intrst = ((p*n*r)/100)
Step 5: display intrst
Step 6: End
Step 1: start
Step 2: declare km, mtr, cm, mm
Step 3: read km
Step 4: mtr=km*1000
Step 5: cm=km*100000
Step 6: mm=km* 1000000
Step 7: display km, mtr, cm ,mm
Step 8: End
Write an algorithm to calculate net salary of an employee with the help of specifications given below.
(HRA=20 % of basic, DA=50% of basic, ta = 5% of basic, lncm-tax=10% of gross).
Step 1: start
Step 2: declare basic, hra=l, da=l, ta=l, it=l, gross=O, netsal=0
Step 3: read basic
Step 4: hra= basic*0.2
Step 5: da= basic *0.5
Step 6: ta- basic*0.05
Step 7: gross = basic + hra + da + ta
Step 1: start
Step 2: declare num
Step 3: if mnn>0
Display "Number is positive"
else
Display "Number is Negative"
Step 4: End
Step 1: start
Step 2: declare num
Step 3: if mod (num, 2) = 1
Display "Number is Odd"
else
Display "Number is Even"
Step 4: End
Step 1: start
Step 2: declare a, b
Step 3: if a>b
Display "First number is greater"
else
Display "Second number is greater"
Step 4: End
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
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
Step 1:
start
Step 2:
declare percentage
Step 3:
read percentage
Step 4:
if percentage<40
Display "Result is fail"
elseif percentage >=40 and percentage<50
Display "Result is Pass Class"
elseif percentages 50 and percentage< 60
Display "Result is second class"
elseif percentage>=60 and percentage<70
Display "Result is First class"
elseif percentage>=70 and percentage<80
Display "Result is Distinction"
elseif percentage>=80 and percentage<=100
Display "Result is MERIT"
Step 5: End
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
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
Step 1: Start
Ans Flowchart : Flowcharts are pictorial representation of logic. In algorithms, we depict logic step-by-step in
the form of statements. Flowcharts uses certain symbols to represent the logic. Because of diagrammatic
form of flowcharts, the programmers can easily read them and problem solving becomes easy.
Flowcharts are usually drawn using some standard symbols as illustrated below.
(a) All necessary requirements should be listed out logically in order to draw an appropriate flowchart.
(b) There should be no ambiguity in understanding the flowchart, i.e., the flowchart should be clear, neat
and easy to follow.
(e) The number of flow line used along with the terminal symbol must be one.
(f) From a process symbol, only one flow line should come out.
(g) For a decision symbol only one flow line should enter, but in the case of leaving of the flow lines this
number can be two to more, one for each possible answer.
(h) Whenever a flowchart becomes complex it is better to use connector symbols as a substitute for flow
lines.
Advantages of Flowcharts :
3. Proper Debugging: Flowcharts are very efficient in detecting, locating, and removing program bugs
(mistakes).
Limitations of Flowcharts :
1. Laborious for Complex problem: Flowchart drawing for complex problem is very time-consuming
and laborious process.
2. Tedious Task in Modification: When any change or modification is required in program logic, the
flowchart may need to be redrawn completely.
Draw a flow to calculate net salary of an employee with the help of specifications given below.
(HRA=20 % of basic, DA=50% of basic, ta = 5% of basic, lncm-tax=10% of gross).
Draw a flow to find the largest among three different numbers entered by user.
Ans Pseudocode is an informal way of writing a program. It is not exactly a computer program. It represents
the algorithm of the program in natural language and mathematical notations. Usually, there is no
particular code syntax to write a pseudocode. Therefore, there is no strict syntax as a usual programming
language. It uses simple English language.
Examples :
SumOfTwoNumbers()
Begin
Set sum=0;
Read: num1, num2;
Set sum = num1+num2;
Print sum;
End
Ans