0% found this document useful (0 votes)
30 views17 pages

Unit 1 PPS

The document discusses the introduction to programming and components of a computer system. It defines programming, describes computer hardware including the processor, memory and input/output devices. It also differentiates between primary and secondary memory and explains types of translators.

Uploaded by

Abhir999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views17 pages

Unit 1 PPS

The document discusses the introduction to programming and components of a computer system. It defines programming, describes computer hardware including the processor, memory and input/output devices. It also differentiates between primary and secondary memory and explains types of translators.

Uploaded by

Abhir999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Unit 1: Introduction

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.

Q1. What is Programming?

Ans Programming is the implementation of logic to simplify specified computing operations and functionality.

Q.2 What is computer?

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.

Q.3 Explain the Components of a Computer.

Ans The five classic components of a computer are briefly described below.

Figure : Components of Computer

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.

The major hardware components of a computer system are:

 Processor (CPU)

 Memory

 Input devices

 Output devices

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Processor (CPU)

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.

Memory is primarily of three types −

i) Cache Memory

ii) Primary Memory/Main 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

The advantages of cache memory are as follows −

 Cache memory is faster than main memory.

 It consumes less access time as compared to main memory.

 It stores the program that can be executed within a short period of time.

 It stores data for temporary use.

Disadvantages

The disadvantages of cache memory are as follows −

 Cache memory has limited capacity.


 It is very expensive.

ii) Primary Memory (Main Memory)

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

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
required to be processed resides in the main memory. It is divided into two subcategories RAM
and ROM.

Characteristics of Main Memory

 These are semiconductor memories.


 It is known as the main memory.
 Usually volatile memory.
 Data is lost in case power is switched off.
 It is the working memory of the computer.
 Faster than secondary memories.
 A computer cannot run without the primary memory.

iii) Secondary Memory

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.

Characteristics of Secondary Memory

 These are magnetic and optical memories.


 It is known as the backup memory.
 It is a non-volatile memory.
 Data is permanently stored even if power is switched off.
 It is used for storage of data in a computer.
 Computer may run without the secondary memory.
 Slower than primary memories.

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

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Q.4 Differentiate between primary memory and secondary memory

Ans

S.No. PRIMARY MEMORY SECONDARY MEMORY


Primary memory is directly accessible Secondary memory is not directly accessible
1
by Processor/CPU. by CPU.
2 It is also called as Main memory. It is also called as Auxiliary memory.
Instructions or data to be currently Data to be permanently stored is kept in
3
executed are copied to main memory. secondary memory.
4 Primary memory is usually volatile. Secondary memory is non-volatile.
Primary memories are made of Secondary memories are made of magnetic
5
semiconductors. and optical material.
Accessing data from primary memory is Accessing data from secondary memory is
6
faster. slower.
Primary memory is accessed by the data Secondary memory is accessed by input-
7
bus. output channels.
The computer has a small primary The computer has a larger secondary
8
memory. memory.
Primary memory is costlier than Secondary memory is cheaper than primary
9
secondary memory. memory
Primary memory is an internal
10 Secondary memory is an external memory.
memory.

Q.5 Explain Translators with types.

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.

Roles of translator are:

• 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.

Different type of translators


The different types of translator are as follows:

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.

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Interpreter
Interpreter is a translator which is used to convert programs in high-level language to low-level
language. Interpreter translates line by line and reports the error once it encountered during the
translation process. It directly executes the operations specified in the source program when the
input is given by the user. It gives better error diagnostics than a compiler.

Assembler
Assembler is a translator, which is used to translate the assembly language code into machine
language code.

Q.6 Differences between compiler and interpreter


Ans

SI. No Compiler Interpreter


1 Performs the translation of a program as a Performs statement-by-statement
whole. translation.
2 Execution is faster. Execution is slower.
3 Requires more memory as linking is needed Memory usage is efficient as no
for the generated intermediate object code. intermediate object code is generated.
4 Debugging is hard as the error messages are It stops translation when the first error is
generated after scanning the entire program met. Hence, debugging is easy.
only.
5 Programming languages like C, C++ uses Programming languages like Python,
compilers. BASIC, and Ruby uses interpreters.

Q.7 Define Algorithm. What are the keywords used in algorithm?

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.

Qualities of a good algorithm


1. Input and output should be defined precisely.

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
2. Each steps in algorithm should be clear and unambiguous.
3. Algorithm should be most effective among many different ways to solve a problem.
4. An algorithm should not have computer code. Instead, the algorithm should be written in such a way
that, it could be used in similar programming languages.

Examples :

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 out average of three numbers.

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

Write an algorithm to calculate Interest amount from loan amount.

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

Write an algorithm to convert kilometer in millimeter, centimeter, meter.

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

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Step 8: it=basic * 0.1
Step 9: netsal = gross - it
Step 10: display netsal
Step 11: End

Write an algorithm to find out whether number is negative or positive.

Step 1: start
Step 2: declare num
Step 3: if mnn>0
Display "Number is positive"
else
Display "Number is Negative"
Step 4: End

Write an algorithm to find out whether number is odd or even. Ans.:

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

Write an algorithm to compare two numbers using algorithm.

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

Write an algorithm to find all roots of a quadratic equation ax 2+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

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
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 declare the result of the student depending on percentage.

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

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

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
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 5.1 to 5.4 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

Q. 7 What is flowcharts ? Draw and give meaning of symbols used in flowcharts.

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.

Symbol Name Meaning


Used to represent the beginning
Terminal
(START) or the END of a task.
Used for input (reading) and
output (printing) operations.
Input/Output
The data to be read or printed
are written inside the symbol.
Used for arithmetic and data
Processing manipulation operations.

Used to indicate a point at which


a decision has to be made, and a
branch to one of two or more
alternatives is possible.
Decision The decision symbol has one
entry and two exit paths. The
path chosen depends on
whether the answer to a
question is ‘yes’ or 'no’.
Used to indicate the flow of
Flowlines operation.

Used to join different flow lines.


Connector

Used to indicate that the


Off – page flowchart continues to a second
connector page.

The following are some guidelines to draw a proper flowchart :

(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.

(c) Every flowchart must have a logical beginning and end.

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
(d) The normal direction of the flow of a flowchart is from top to bottom or left to right.

(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 :

1. Communication: As flowchart is a pictorial representation of a program, it is easier to explain the logic


of a program to some other person by using flowcharts.

2. Proper Documentation: Flowcharts often provide valuable documentation.

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.

Examples on flow chart :

Draw a flow chart to add two numbers entered by user.

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Draw a flow to find out average of three numbers.

Draw a flow to calculate Interest amount from loan amount.

Draw a flow to convert kilometer in millimeter, centimeter, meter.

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 out whether number is negative or positive.

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Draw a flow to find out whether number is odd or even. Ans.:

Draw a flow to compare two numbers using algorithm.

Draw a flow to find the factorial of a number entered by user.

Draw a flow to find the largest among three different numbers entered by user.

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Draw a flow to check whether a number entered by user is prime or not.

Q.8 What is Pseudocode?

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 :

Pseudocode to add 2 numbers is as follows;

SumOfTwoNumbers()
Begin
Set sum=0;
Read: num1, num2;
Set sum = num1+num2;
Print sum;
End

Pseudocode to find the area of a Rectangle is as follows.


AreaOfRectangle()
Begin
Read: width, length;
Set area = width * length;
Print area;
End

Pseudocode of sequential flow with multiple alternatives is as follows.


DisplayValues()
Begin
Read: x;
if x==1 then
Print: “One”;
else if x==2 then
Print: “Two”;
else
Print: “x is not 1 or 2”;
endif
End

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Pseudocode to print 5 numbers is as follows.
PrintOneToFive()
Begin
Set i=1;
while i<=5
Print : i;
Set i= i+1;
endwhile
End

Q.9 Write down the difference between algorithm and pseudocode

Ans

S.No BASIS FOR


ALGORITHM PSEUDOCODE
COMPARISON

1 Comprehensibility Quite hard to understand Easy to interpret

2 Uses Complicated programming Combination of programming


language language and natural language

3 Debugging Moderate Simpler

4 Ease of Complex Easier


construction

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Do it yourself

Sumit Kumar Sar


Department of Computer Science & Engineering
BIT, Durg
Sumit Kumar Sar
Department of Computer Science & Engineering
BIT, Durg
Sumit Kumar Sar
Department of Computer Science & Engineering
BIT, Durg

You might also like