Professional Documents
Culture Documents
Unit 1 PPS
Unit 1 PPS
Unit I
Introduction
Syllabus
1. COMPUTER
An automatic electronic apparatus for making calculations or controlling operations that are
expressible in numerical or logical terms.
2.1 Hardware
Hardware is the physical components of the computer that includes all mechanical, electrical and
electronic parts attached to it. A computer consists of major components as follows:
SVCE Page 1
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Input and Output devices , central processing unit, memory unit and storage devices, interface
unit.
Keyboard
A computer keyboard is one of the primary input devices used with a computer that looks similar
to those found on electric typewriters, but with some additional keys. Keyboards allow you to
input letters, numbers, and other symbols into a computer that can serve as commands or be used
to type text.
Mouse
A mouse is the pointing device attached to a computer. It is used to move the cursor around the
screen and to point to an object for the purpose of selecting or activating objects on graphical
interface.
Scanner
A scanner is a device that captures pictures or documents so that they can be stored in storage
devices, seen on a video screen, modified suitably, transported to other computers or printed on a
printer.
Monitor
The monitor displays the computer's user interface and open programs, allowing the user to
interact with the computer, typically using the keyboard and mouse.
Printer
Printer is a device that prints any data, report, documents, picture, diagrams etc.
SVCE Page 2
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Registers
These are high-speed storage devices. It contains a set of general purpose registers that are used
for temporary storage of data values as needed during processing.
Special purpose registers are reserved for special purpose. Instruction Register (IR) holds the
current instruction to be executed. Program Counter (PC) is a register that holds the address of
the next instruction to be executed.
an instruction decoding circuit that interprets what action should be performed.
a control and timing circuit detects all the other parts of the computer by producing the
respective control signals.
Primary Memory is the area where data and programs stored while the program is being
executed along with the data .
Secondary memory provides large, non volatile and inexpensive storage for programs and
data.
2.1.5 Interface Unit
The interface unit interconnects the CPU with memory and also with the various input / output
devices. The instruction and data move between the CPU and other hardware components
through interface unit.
SVCE Page 3
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
2.2 Software
Software provides the instructions that tells the hardware exactly what is to be performed and in
what order. This set of instruction is sequenced and organised in a computer program. A program
is a series of instructions which is intended to direct a computer to perform certain functions and
executed by the processor.
Software is generally categorised as follows:
System software is designed to facilitate and coordinate the use of computer by making
hardware operational. Examples: Operating system, language translator, loader, linker.
Application program is designed to perform specific tasks for the user. Example Word,
Excel, AutoCAD, Internet explorer.
3. COMPUTER NETWORK
Communication is the process of transferring messsages from one point to another. The three
basic elements of a communication system are:
There are three ways or modes of transmitting data from one point to another. These are simplex,
half duplex and full duplex.
SVCE Page 4
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
3.2.1 Simplex:
In half duplex mode, data can be transmitted in both directions on a signal carrier except not at
the same time. At a certain point, it is actually a simplex channel whose transmission direction
can be switched. Walkie-talkie is a typical half duplex device. It has a ―push-to-talk‖ button
which can be used to turn on the transmitter but turn off the receiver. Therefore, once you push
the button, you cannot hear the person you are talking to but your partner can hear you. An
advantage of half-duplex is that the single track is cheaper than the double tracks.
A full duplex communication channel is able to transmit data in both directions on a signal
carrier at the same time. It is constructed as a pair of simplex links that allows bidirectional
simultaneous transmission. Take telephone as an example, people at both ends of a call can
speak and be heard by each other at the same time because there are two communication paths
between them. Thus, using the full duplex mode can greatly increase the efficiency of
communication.
SVCE Page 5
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
The speed with which data can be transmitted from one device to another. Data rates are often
measured in megabits (million bits) or megabytes (million bytes) per second. These are usually
abbreviated as Mbps and MBps,respectively.
A term used to describe the data handling capacity of a communication system is bandwidth.
Bandwidth is the range of frequencies that is available for the transmission of data. The
communication data transfer rate is measured in a unit called baud. Baud is identical to bits per
second. Depending on their transmission speeds, communication channels are grouped into the
following three basic categories:
3.3.1Narrow band:
Narrowband or subvoice grade channels range in speed from 45 to 300 baud. They are used for
handling low data volumes and are adequate for low-speed devices. They are mainly for
telegraphs lines and low speed terminals.
3.3.2Voice band:
Voice band channels handle moderate data volumes and can transmit data at speeds upto 9600 baud.
Their major application is ordinary telephone voice communication. They are also used for data
transmission from slow I/O devices to CPU or vice-versa.
3.3.3Broad band:
Broadband are used when large volumes of data are to be transmitted at high speed. These systems
provide data transmission rates of 1 million baud or more.
3.4.1Transmission media is a pathway that carries the information from sender to receiver. We use
different types of cables or waves to transmit data. Data is transmitted normally through electrical or
electromagnetic signals.
Wired or Guided Media or Bound Transmission Media : Bound transmission media are the
cables that are tangible or have physical existence and are limited by the physical
geography. Popular bound transmission media in use are twisted pair cable, co-axial cable and
fiber optical cable. Each of them has its own characteristics like transmission speed, effect of
noise, physical appearance, cost etc.
A twisted pair is a pair of copper wires, with diameters of 0.4-0.8 mm, twisted together and
wrapped with a plastic coating. The twisting reduces the electrical noise and the error rate of the
data transmission. Each conductor is separately insulated by some low-smoke and fires retardant
substance.
Co-axial Cable
Coaxial cable is a robust shielded copper wire two-conductor cable in which a solid center
conductor runs concentrically (coaxial) inside a solid outer circular conductor.
SVCE Page 7
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Coaxial cable includes shield for improved performance and therefore is expensive. Cable TV
networks use coaxial cable. Local Area Networks can operate over coaxial cable to the
10BASE5, 10BASE2 and 10BASET specifications. In general, coaxial cable enables longer
distance transmission at higher data rates than twisted pair cable but this is more expensive.
Advantages:
High Bandwidth
Better noise Immunity
Easy to install and expand
Inexpensive
Disadvantages:
Fiber-Optics Cable
A cable with central glass tube covered with protective shield which transmit data using photons
is fiber optics cable. These cables transmit data via concentrated bursts of laser beams which are
carried through bundles of hair thin glass fibers.
They have advantages over electronic cables in transmission speed and volume. This technology
has revolutionized telecommunication applications which used electronic cables. Fiber optics
cables as free from electro-magnetic interference as well as wire tapping. fiber optics cable
considered a broad band communication channel
Advantages:
Increased capacity and bandwidth
Light weight
High cost
SVCE Page 8
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Fragile
Radiowaves
These are easy to generate and can penetrate through buildings.The sending and receiving
antennas need not be aligned. Frequency Range:3KHz – 1GHz. AM and FM radios and cordless
phones use Radiowaves for transmission.
Microwaves
It is a line of sight transmission i.e. the sending and receiving antennas need to be properly
aligned with each other. The distance covered by the signal is directly proportional to the height
of the antenna. Frequency Range:1GHz – 300GHz. These are majorly used for mobile phone
communication and television distribution.
Infrared
Infrared waves are used for very short distance communication. They cannot penetrate through
obstacles. This prevents interference between systems. Frequency Range:300GHz – 400THz. It
is used in TV remotes, wireless mouse, keyboard, printer, etc.
4.NETWORK TOPOLOGIES
4.1.1BUS Topology
Bus topology is a network type in which every computer and network device is connected to
single cable. When it has exactly two endpoints, then it is called Linear Bus topology.
SVCE Page 9
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
It is cost effective.
Cable required is least compared to other network topology.
Used in small networks.
It is easy to understand.
Easy to expand joining two cables together.
Disadvantages of Bus Topology
4.1.2RING Topology
It is called ring topology because it forms a ring as each computer is connected to another
computer, with the last one connected to the first. Exactly two neighbours for each device.
SVCE Page 10
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
In Dual Ring Topology, two ring networks are formed, and data flow is in opposite direction in
them. Also, if one ring fails, the second ring can act as a backup, to keep the network up.
Data is transferred in a sequential manner that is bit by bit. Data transmitted, has to pass through
each node of the network, till the destination node.
Transmitting network is not affected by high traffic or by adding more nodes, as only the
nodes having tokens can transmit data.
Cheap to install and expand
4.1.3STAR Topology
In this type of topology all the computers are connected to a single hub through a cable. This hub
is the central node and all others nodes are connected to the central node.
SVCE Page 11
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
4.1.4MESH Topology
It is a point-to-point connection to other nodes or devices. All the network nodes are connected
to each other. Mesh has n(n-1)/2 physical channels to link n devices.
SVCE Page 12
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Fully connected.
Robust.
Not flexible.
4.1.5TREE Topology
It has a root node and all other nodes are connected to it forming a hierarchy. It is also called
SVCE Page 13
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Heavily cabled.
Costly.
If more nodes are added maintenance is difficult.
Central hub fails, network fails.
4.1.6HYBRID Topology
It is two different types of topologies which is a mixture of two or more topologies. For example
if in an office in one department ring topology is used and in another star topology is used,
connecting these topologies will result in Hybrid Topology (ring topology and star topology).
SVCE Page 14
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Complex in design.
Costly.
5.1 Repeater – A repeater operates at the physical layer. Its job is to regenerate the signal over
the same network before the signal becomes too weak or corrupted so as to extend the length to
which the signal can be transmitted over the same network. An important point to be noted about
repeaters is that they do not amplify the signal. When the signal becomes weak, they copy the
signal bit by bit and regenerate it at the original strength. It is a 2 port device.
5.2 Hub – A hub is basically a multiport repeater. A hub connects multiple wires coming from
different branches, for example, the connector in star topology which connects different stations.
Hubs cannot filter data, so data packets are sent to all connected devices. In other
words, collision domain of all hosts connected through Hub remains one. Also, they do not have
intelligence to find out best path for data packets which leads to inefficiencies and wastage.
5.3 Bridge – A bridge operates at data link layer. A bridge is a repeater, with add on
functionality of filtering content by reading the MAC addresses of source and destination. It is
also used for interconnecting two LANs working on the same protocol. It has a single input and
single output port, thus making it a 2 port device.
5.4 Switch – A switch is a multi port bridge with a buffer and a design that can boost its
efficiency(large number of ports imply less traffic) and performance. Switch is data link layer
device. Switch can perform error checking before forwarding data, that makes it very efficient as
it does not forward packets that have errors and forward good packets selectively to correct port
only.
5.5 Routers – A router is a device like a switch that routes data packets based on their IP
addresses. Router is mainly a Network Layer device. Routers normally connect LANs and
WANs together and have a dynamically updating routing table based on which they make
decisions on routing the data packets. Router divide broadcast domains of hosts connected
through it.
SVCE Page 15
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
5.6 Gateway – A gateway is a passage to connect two networks together that may work upon
different networking models. They basically works as the messenger agents that take data from
one system, interpret it, and transfer it to another system. Gateways are also called protocol
converters and can operate at any network layer. Gateways are generally more complex than
switch or router.
SVCE Page 16
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
It is also called LAN and designed for small physical areas such as an office, group of buildings
or a factory. LANs are used widely as it is easy to design and to troubleshoot. Personal
computers and workstations are connected to each other through LANs.
LAN can be a simple network like connecting two computers, to share files and network among
each other while it can also be as complex as interconnecting an entire building.
LAN networks are also widely used to share resources like printers, shared hard-drive etc.
Characteristics of LAN
LAN's are private networks, not subject to tariffs or other regulatory controls.
LAN's operate at relatively high speed when compared to the typical WAN.
There are different types of Media Access Control methods in a LAN, the prominent ones
are Ethernet, Token ring.
It connects computers in a single building, block or campus, i.e. they work in a restricted
geographical area.
Advantages of LAN
Resource Sharing
Software Applications Sharing
Easy and Cheap Communication
SVCE Page 17
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Centralized Data
Data Security
Internet Sharing
Disadvantages of LAN
Characteristics of MAN
Advantages of MAN
Extremely efficient and provide fast communication via high-speed carriers, such as fibre
optic cables.
It provides a good back bone for large network and provides greater access to WANs.
The dual bus used in MAN helps the transmission of data in both directions
SVCE Page 18
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
simultaneously.
A MAN usually encompasses several blocks of a city or an entire city.
Disadvantages of MAN
More cable required for a MAN connection from one place to another.
It is difficult to make the system secure from hackers and industrial espionage(spying)
graphical regions.
It is used for the network that covers large distance such as cover states of a country. It is not
easy to design and maintain. Communication medium used by WAN are PSTN or Satellite links.
WAN operates on low data rates.
Characteristics of WAN
Advantages of WAN
Covers a large geographical area so long distance business can connect on the one
network.
Shares software and resources with connecting workstations.
SVCE Page 19
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Messages can be sent very quickly to anyone else on the network. These messages can
have picture, sounds or data included with them(called attachments).
Expensive things(such as printers or phone lines to the internet) can be shared by all the
computers on the network without having to buy a different peripheral for each computer.
Everyone on the network can use the same data. This avoids problems where some users
may have older information than others.
Disadvantages of WAN
Need a good firewall to restrict outsiders from entering and disrupting the network.
Setting up a network can be an expensive, slow and complicated. The bigger the network
the more expensive it is.
Once set up, maintaining a network is a full-time job which requires network supervisors
and technicians to be employed.
Security is a real issue when many different people have the ability to use information
from other computers. Protection against hackers and viruses adds more complexity and
expense.
7. INTERNET
The Internet is a global system of interconnected computer networks that use the standard
Internet protocol suite (TCP/IP) to serve billions of users worldwide. It is a network of networks
that consists of millions of private, public, academic, business, and government networks, of
local to global scope, that are linked by a broad array of electronic, wireless and optical
networking technologies. The Internet carries a vast range of information resources and services,
such as the interlinked hypertext documents of the World Wide Web (WWW) and the
infrastructure to support electronic mail.
Internet has been the most useful technology of the modern times which helps us not only in our
daily lives, but also our personal and professional lives developments. The internet helps us
achieve this in several different ways.
For the students and educational purposes the internet is widely used to gather information so as
to do the research or add to the knowledge of various subjects. Even the business professionals
and the professionals like doctors, access the internet to filter the necessary information for their
use. The internet is therefore the largest encyclopedia for everyone, in all age categories. The
internet has served to be more useful in maintaining contacts with friends and relatives who live
abroad permanently.
SVCE Page 20
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
E-mail: Email is now an essential communication tools in business. With e-mail you can
send and receive instant electronic messages, which works like writing letters. Your
messages are delivered instantly to people anywhere in the world, unlike traditional mail
that takes a lot of time. Email is free, fast and very cheap when compared to telephone,
fax and postal services.
24 hours a day 7 days a week: Internet is available, 24x7 days for usage.
Information: Information is probably the biggest advantage internet is offering. There is
a huge amount of information available on the internet for just about every subject,
ranging from government law and services, trade fairs and conferences, market
information, new ideas and technical support. You can almost find any type of data on
almost any kind of subject that you are looking for by using search engines like google,
yahoo, msn, etc.
Online Chat: You can access many ‗chat rooms‘ on the web that can be used to meet
new people, make new friends, as well as to stay in touch with old friends.
Services: Many services are provided on the internet like net banking, job searching,
purchasing tickets, hotel reservations, guidance services on array of topics engulfing
every aspect of life.
Communities: Communities of all types have sprung up on the internet. Its a great way
to meet up with people of similar interest and discuss common issues.
E-commerce: Along with getting information on the Internet, you can also shop online.
There are many online stores and sites that can be used to look for products as well as
buy them using your credit card. You do not need to leave your house and can do all
your shopping from the convenience of your home. It has got a real amazing and wide
range of products from household needs, electronics to entertainment.
Entertainment: Internet provides facility to access wide range of Audio/Video songs,
plays films. Many of which can be downloaded. One such popular website is YouTube.
Software Downloads: You can freely download innumerable, softwares like utilities,
games, music, videos, movies, etc from the Internet.
Theft of Personal information: Electronic messages sent over the Internet can be easily
snooped and tracked, revealing who is talking to whom and what they are talking about.
If you use the Internet, your personal information such as your name, address, credit
card, bank details and other information can be accessed by unauthorized persons. If you
use a credit card or internet banking for online shopping, then your details can also be
‗stolen‘.
Negative effects on family communication: It is generally observed that due to more
time spent on Internet, there is a decrease in communication and feeling of togetherness
among the family members.
Internet addiction: There is some controversy over whether it is possible to actually be
addicted to the Internet or not. Some researchers, claim that it is simply people trying to
SVCE Page 21
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
E-mail or Electronic mail is a paperless method of sending messages, notes or letters from one
person to another or even many people at the same time via Internet. E-mail is very fast
compared to the normal post. E-mail messages usually take only few seconds to arrive at their
destination. One can send messages anytime of the day or night, and, it will get delivered
immediately. You have the privilege of sending something extra such as a file, graphics, images
etc. along with your e-mail. The biggest advantage of using email is that it is cheap, especially
when sending messages to other states or countries and at the same time it can be delivered to a
number of people around the world. It allows you to compose note, get the address of the
recipient and send it. Once the mail is received and read, it can be forwarded or replied. One can
even store it for later use, or delete. In e-mail even the sender can request for delivery receipt and
read receipt from the recipient.
Features of E-mail:
File Transfer Protocol, is an Internet utility software used to uploaded and download files. It
gives access to directories or folders on remote computers and allows software, data and text
files to be transferred between different kinds of computers.
SVCE Page 22
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
FTP works on the basis of same principle as that of Client/Server. FTP ―Client‖ is a program
running on your computer that enables you to communicate with remote computers. The FTP
client takes FTP command and sends these as requests for information from the remote computer
known as FTP servers. To access remote FTP server it is required, but not necessary to have an
account in the FTP server. When the FTP client gets connected, FTP server asks for the
identification in terms of User Login name and password of the FTP client. If one does not have
an account in the remote FTP server, still he can connect to the server using anonymous login.
Using anonymous login anyone can login in to a FTP server and can access public archives;
anywhere in the world, without having an account. One can easily Login to the FTP site with the
username anonymous and e-mail address as password.
Objectives of FTP :
Provide flexibility and promote sharing of computer programs, files and data
Transfer data reliably and more efficiently over network
Encourage implicit or indirect use of remote computers using Internet
Shield a user from variations in storage systems among hosts.
Telnet (Remote Computing)
SVCE Page 23
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
gain access to remote computer, you can use it for the intended purpose. The TELNET works in
a very step by step procedure. The commands typed on the client computer are sent to the local
Internet Service Provider (ISP), and then from the ISP to the remote computer that you have
gained access. Most of the
ISP provides facility to TELENET into your own account from another city and check your e-
mail while you are travelling or away on business.
A computer cannot solve a problem on its own. One has to provide step by step solutions of the
problem to the computer. In fact, the task of problem solving is not that of the computer. It is the
programmer who has to write down the solution to the problem in terms of simple operations
which the computer can understand and execute. In order to solve a problem by the computer,
one has to pass though certain stages or steps.
They are
1. Understanding the problem
2. Analyzing the problem
3. Developing the solution
4. Coding and implementation.
1. Understanding the problem: Here we try to understand the problem to be solved in totally.
Before proceeding to the next stage or step, we should be absolutely sure about the objectives of
the given problem.
2. Analyzing the problem: After understanding thoroughly the problem to be solved, we look
into different ways of solving the problem and evaluate each of these methods. The idea here is
to search an appropriate solution to the problem under consideration. The end result of this stage
is a broad overview of the sequence of operations that are to be carried out to solve the given
problem.
3. Developing the solution: Here the overview of the sequence of operations that was the result
of analysis stage is expanded to form a detailed step by step solution to the problem under
consideration.
4. Coding and implementation: The last stage of the problem solving is the conversion of the
detailed sequence of operations in to a language that the computer can understand. Here each
step is converted to its equivalent instruction or instructions in the computer language that has
been chosen for the implementation.
SVCE Page 24
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
We know that a system is composed of more than one sub-systems and it contains a number of
components. Further, these sub-systems and components may have their own set of sub-system
and components and creates hierarchical structure in the system.
Top-down design takes the whole software system as one entity and then decomposes it to
achieve more than one sub-system or component based on some characteristics. Each sub-system
or component is then treated as a system and decomposed further. This process keeps on running
until the lowest level of system in the top-down hierarchy is achieved.
Top-down design starts with a generalized model of system and keeps on defining the more
specific part of it. When all components are composed the whole system comes into existence.
Top-down design is more suitable when the software solution needs to be designed from scratch
and specific details are unknown.
Top down program design is an approach to program design that starts with the general concept
and repeatedly breaks it down into its component parts. In other words, it starts with the abstract
and continually subdivides it until it reaches the specific. Consider creating the prime
factorization of a number like 1540. The steps involved might look like:
1540
2 x 770
2 x 2 x 385
2 x 2 x 5 x 77
2 x 2 x 5 x 7 x 11
Top down program design works the same way. We start with the overall objective and wind up
with a series of steps needed to accomplish it.
Top-down analysis, therefore, simplifies or reduces the complexity of the process of problem
solving. It is not limited by the type of program. Top-down analysis is a general method for
attending to any problem. It provides a strategy that has to be followed for solving all problems.
There are two essential ideas in top-down analysis:
subdivision of a problem
hierarchy of tasks
Subdivision of a problem means breaking a big problem into two or more smaller problems.
Therefore, to solve the big problem, first these smaller problems have to be solved. Top-down
analysis does not simply divide a problem into two or more smaller problems.It goes further than
that. Each of these smaller problems is further subdivided. This process continues downwards,
creating a hierarchy of tasks, from one level to the next, until no further break up is possible.
Step 2: Based on the definition of the problem, divide the problem into two or more separate
parts.
Step 3: Carefully define the scope of each of these separate tasks and subdivide them further, if
necessary, into two or more smaller tasks.
Step 4: Repeat step 3. Every step at the lowest level describes a simple task, which cannot be
broken further.
The bottom up design model starts with most specific and basic components. It proceeds with
composing higher level of components by using basic or lower level components. It keeps
creating higher level components until the desired system is not evolved as one single
component. With each higher level, the amount of abstraction is increased.
Bottom-up strategy is more suitable when a system needs to be created from some existing
system, where the basic primitives can be used in the newer system.
Bottom up program design works in the exact opposite way. It starts with the component parts
and repeatedly combines them to achieve the general concept. In other words, it starts with the
specific and continually combines it until it reaches the abstract. For example, consider the
factorization from the previous section. For bottom up design the steps involved might look like:
2 x 2 x 5 x 7 x 11
2 x 2 x 5 x 77
2 x 2 x 385
2 x 770
1540
In top-down approach, main function is written In bottom-up approach, code is developed from
first and all sub functions are called from main modules and then these modules are integrated
function thus, sub-functions are written based with main function
on the requirement
9. ALGORITHM
An algorithm can be stated using three basic constructs: sequence, decision, and repetition.
Sequence
Sequence means that each step or process in the algorithm is executed in the specified order.
The decision constructs— if ... then, if ... then ... else ...
In algorithms the outcome of a decision is either true or false; there is no state in between.
The outcome of the decision is based on some condition that can only result in a true or false
value. For example, if today is Friday then collect pay is a decision and the decision takes the
general form:
A proposition, in this sense, is a statement, which can only be true or false. It is either true that
‗today is Friday‘ or it is false that ‗today is not Friday‘. It can not be both true and false. If the
proposition is true, then the process or procedure that follows the then is executed.
This is the if … then … else … form of the decision. This means that if the proposition is true
then execute process1, else, or otherwise, execute process2 The first form of the decision if
proposition then process has a null else, that is, there is no else.
Example:
Repeat
Fill water in kettle
Until kettle is full
The process is ‗Fill water in kettle,‘ the proposition is ‗kettle is full‘.
The Repeat loop does some processing before testing the state of the proposition. What happens
though if in the above example the kettle is already full? If the kettle is already full at the start of
the Repeat loop, then filling more water will lead to an overflow. This is a drawback of the
Repeat construct.
In such a case the while loop is more appropriate. The above example with the while loop is
shown as follows:
while kettle is not full
fill water in kettle
Since the decision about the kettle being full or not is made before filling water, the possibility of
an overflow is eliminated. The while loop finds out whether some condition is true before
repeating a process or a sequence of processes.
If the condition is false, the process or the sequence of processes is not executed. The general
form of while loop is:
while proposition
begin
Process 1
Process 2
………..
………...
Process N
end
The if .. then goto .. is also used to repeat a process or a sequence of processes until the given
proposition is false. In the kettle example, this construct would be implemented as follows:
SVCE Page 28
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
So long as the proposition ‗kettle not full‘ is true the process, ‗fill some water in kettle‘ is
repeated. The general form of if .. then goto .. is:
Process1
Process2
……….
……….
ProcessN
if proposition then goto Process1
Termination
The algorithm must end after a finite number of steps.
Correctness
The prepared algorithm needs to be verified for its correctness. Correctness means how easily its
logic can be argued to meet the algorithm‘s primary goal. This requires the algorithm to be made
in such a way that all the elements in it are traceable to the requirements.
Solution Let the two numbers be A and B and let their sum be equal to C. Then, the desired algorithm is given as follows:
1. START
2. PRINT “ENTER TWO NUMBERS”
3. INPUT A, B
4. C = A + B
5. PRINT C
6. STOP
2. Write the algorithm for determining the remainder of a division operation where the dividend and divisor are both
integers.
SVCE Page 29
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
3. Write an algorithm that compares two numbers and prints either the message identifying the greater number or the
message stating that both numbers are equal.
Solution This example demonstrates how the process of selection or decision making is implemented in an algorithm using the
stepform. Here, two variables, A and B, are assumed to represent the two numbers that are being compared. The algorithm for this
problem is given as follows.
1. START
2. PRINT “ENTER TWO NUMBERS”
3. INPUT A, B
4. IF A > B THEN
PRINT “A IS GREATER THAN B”
5. IF B > A THEN
PRINT “B IS GREATER THAN A”
6. IF A = B THEN
PRINT “BOTH ARE EQUAL”
7. STOP
4. Write an algorithm to check whether a number given by the user is odd or even.
Solution Let the number to be checked be represented by N. The number N is divided by 2 to give an integer quotient, denoted
by Q. If the remainder, designated as R, is zero, N is even; otherwise N is odd. This logic has been applied in the following algorithm.
1. START
2. PRINT “ENTER THE NUMBER”
3. INPUT N
4. Q <- N/2 (Integer division)
5. R <- N – Q * 2
6. IF R = 0 THEN
PRINT “N IS EVEN”
7. IF R != 0 THEN
PRINT “N IS ODD”
8. STOP
Solution Let the sum of N given numbers be represented by S. Each time a number is given as input, it is assigned to the
variable A. The algorithm using the loop construct ‘if … then goto …’ is used as follows:
1. START
2. PRINT “HOW MANY NUMBERS?”
3. INPUT N
4. S <- 0
5. C <- 1
6. PRINT “ENTER NUMBER”
7. INPUT A
8. S <- S + A
9. C <- C + 1
10. IF C <= N THEN GOTO 6
11. PRINT S
12. STOP
10 FLOWCHART
A flowchart comprises a set of various standard shaped boxes that are interconnected by flow lines. Flow lines
have arrows to indicate the direction of the flow of control between the boxes. The activity to be performed is
written within the boxes in English. In addition, there are connector symbols that are used to indicate that the
flow of control continues elsewhere, for example, the next page.
SVCE Page 30
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible
answer, can leave the decision symbol.
SVCE Page 31
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
A sequence of steps or processes that are executed in a particular order is shown using process
symbols connected with flow lines. One flow line enters the first process while one flow line emerges
from the last process in the sequence.
Selection of a process or step is depicted by the decision making and process symbols. Only one input
indicated by one incoming flow line and one output flowing out of this structure exists. The decision
symbol and the process symbols are connected by flow lines.
Iteration or looping is depicted by a combination of process and decision symbols placed in proper
order. Here flow lines are used to connect the symbols and depict input and output to this structure.
SVCE Page 32
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
2. The XYZ Construction Company plans to give a 5% year-end bonus to each of its employees earning Rs 5,000 or
more per year, and a fixed bonus of Rs 250 to all other employees. Draw a flowchart and write the step-form
algorithm for printing the bonus of any employee.
SVCE Page 33
UNIT 1 IT18101 PROGRAMMING FOR PROBLEM SOLVING
3. Draw a flowchart for calculating the simple interest using the formula SI = (P * T * R)/100, where P denotes the
principal amount, T time, and R rate of interest.
SVCE Page 34