Unit 1
Unit 1
INTRODUCTION
What is computer?
Computer is an electronic device which capable of performing computation and making logical decisions
at speed of millions and even billions of times faster than human beings can.
Computers process data under the control of sets of instructions called computer programs.These
programs guide the computer through orderly sets of actions specified by people called Computer
programmers.
Computer Systems:
A computer is a system made of two major components: hardware and software. The computer hardware is the
physical equipment. The software is the collection of programs (instructions) that allow the hardware to do its job.
Computer
System
Hardware Software
Hardware:
The visible part of a personal computer system, the physical equipment that can perform the basic
functions, is called the hardware. The hardware component of the computer system consists of five parts: input
devices, central processing unit (CPU) ,primary storage, output devices, and auxiliary storage devices in fig
Input unit:
The input device is usually a keyboard where programs and data are entered into the computers. Examples of other
input devices include a mouse, a pen or stylus, a touch screen, or an audio input unit.
This section of the computer is responsible for supervising the operation of the other sections. The CPU is
the brain of the computer. It is made up of different parts: the control unit (CU), instruction decoder,
arithmetic logic unit (ALU), and internal processor storage units. The control unit directs all the other
parts of the computer and a complicated instruction decoding circuit determines what action should be
performed. The control unit interprets the actions determined by the decoder and produces the respective
control signals. CPU tells the input when information should be read into memory unit, tells the
arithmetic and logic unit (ALU) when information from the memory unit should be used in calculations
and tells the output unit when to send information from the memory unit to certain output devices.
Primary storage ,also known as main memory, is a place where the programs and data are stored
temporarily during processing. The data in primary storage are erased when we turn off a personal
computer or when we log off from a time-sharing system.
Operational registers:
All the arithmetic and logical operations performed in CPU use special storage areas called registers. The
size of the register is one of the important considerations in determining the processing capabilities of the
CPU. Register size refers to the amount of information that it can hold at a time for processing. The larger
the register size, the faster may be the speed of processing.
ALU is a part of CPU. The ALU performs various arithmetic operations such as addition, subtraction,
multiplication, and logical operations such as AND, OR, and NOT. It contain decision mechanisms that
allow the computer to complete tasks such as comparing two items from the memory unit to determine
whether or not they are equal.
The output device is usually a monitor or a printer to show output. If the output is shown on the monitor,
we say we have a soft copy. If it is printed on the printer, we say we have a hard copy.
Auxiliary storage, also known as secondary storage, is used for both input and output. It is the place
where the programs and data are stored permanently. When we turn off the computer, or programs and
data remain in the secondary storage, ready for the next time we need them.
Software:
A set of detailed instructions design to direct a computer to perform certain functions is called program or
software. Or set of instructions to the computer is called programs or software. Software is generally
categorized as System software (Operating System) and Application Software.
System software manages the computer resources .It provides the interface between the hardware and the
users. Application software, on the other hand is directly responsible for helping users solve their
problems.
Software
System Application
Software Software
System Software:
System software consists of programs that manage the hardware resources of a computer and perform
required information processing tasks. These programs are divided into three classes: the operating
system, system support, and system development.
The operating system provides services such as a user interface, file and database access, and interfaces
to communication systems such as Internet protocols. The primary purpose of this software is to keep the
system operating in an efficient manner while allowing the users access to the system.
System support software provides system utilities and other operating services. Examples of system
utilities are sort programs and disk format programs. Operating services consists of programs that provide
performance statistics for the operational staff and security monitors to protect the system and data.
System development software, includes the language translators that convert programs into machine
language for execution ,debugging tools to ensure that the programs are error free and computer –assisted
software engineering(CASE) systems.
.
Application software:
This is consists of a number of programs designed to perform specific user applications. It enables the
computer to perform a specific data processing task. There are two categories of application software,
pre-written software packages and user-developed application programs.
Application software is broken in to two classes :general-purpose software and application –specific
software. General purpose software is purchased from a software developer and can be used for more
than one application. Examples of general purpose software include word processors ,database
management systems ,and computer aided design systems. They are labeled general purpose because they
can solve a variety of user computing problems.
Application –specific software can be used only for its intended purpose.
A general ledger system used by accountants and a material requirements planning system used by a
manufacturing organization are examples of application-specific software. They can be used only for the
task for which they were designed they cannot be used for other generalized tasks.
COMPUTING ENVIRONMENTS:
Computers can be used in different environments. An environment describes a situation. There are
basically three types of computing environments depending on the way the computer are used. They are:
Personal Computing:
In 1977, Apple Computer popularized the concept of Personal Computing. Computers become
economical enough for people to buy them for their own personal or business use. In 1981, IBM, the
world’s largest computer vendor, introduced the IBM Personal Computer. Personal computing became
legitimate in business, industry and government organizations.
If we are using a personal computer, all of the computer hardware components are tied together in our
personal computer(PC).
Time-Sharing Environment:
Employees in large companies often work in what is known as a time-sharing environment. In the
times-sharing environment, many users are connected to one or more computers. These computers may be
minicomputers or central mainframes. The terminals they use are often nonprogrammable, although today
we see more and more microcomputers being used to simulate terminals. Also, in the time-sharing
environment, the output devices and auxiliary storage devices are shared by all of the users. A typical
college lab in which a minicomputer is shared by many students is shown in figure :
In the time-sharing environment ,all computing must be done by the central computer. The central
computer has many duties: It must control the shared resources; it must manage the shared data and
printing and it must do the computing.
Client/Server Environment
A client/server computing environment splits the computing function between a central computer and
users’ computers. The users are given personal computers or work stations so that some of the
computation responsibility can be moved from the central computer and assigned to the workstations. In
the client-server environment, the users’ micro computers or workstations are called the client. The
central computer, which may be a powerful microcomputer, minicomputer, or central mainframe system,
is known as the server. Because the work is now shared between the users’ computers and the central
computer, response time and monitor display are faster and the users are more productive.
Distributed Computing:
COMPUTER LANGUAGES:
Programmers write instructions in various programming languages, some directly understandable by the
computer and other that require intermediate translation steps. These may be classified into two types:
The languages in this category are the Machine Level Language and Assembly Language
Computer can understand only digital signals, which are in binary digits i.e. 0 and 1. So the instructions
given to the computer can be only in binary codes. The machine language consists of instructions that are
in binary 0 or 1. Computer can understand only machine level language.
Writing a program in machine level language is a difficult task because it is not easy for programmers to
write instructions in binary code. A machine level language program is error-prone and its maintenance is
very difficult. Furthermore machine language programs are not portable. Every computer has its own
machine instructions, so the program written for one computer are not valid for other computers.
Assembly Language:
The difficulties faced in machine level language were reduced to some extent by using a modified form of
machine level language called assembly language. In assembly language instructions are given in English
like words, such as MOV, ADD, SUB etc. so it is easier to write and understand assembly programs
MOV [100], A Save the result in the main memory location 100
Since a computer can understand only machine level language, hence assembly language program must
be translated into machine language. The translator that is used for translating is called “assembler”;
Although writing programs in assembly language is a bit easier, but still the programmer has to know all
the low level details related with the hardware of a computer. In assembly language, data is stored in
computer registers and each computer has different set of registers. Hence the assembly language
program is also not portable. Since the low level languages are related with the hardware, hence the
execution of a low level program is faster.
High Level Languages are designed keeping in mind the features of portability i.e. these languages are
machine independent. These are English like languages, so it is easy to write and understand the programs
of high-level language. While programming in high level language, the programmer is not concerned with
the low level details, and so the whole attention can be paid to the logic of the program being solved. For
translating a high-level language program into machine language, compiler or interpreter is used. Every
language has its own compiler or interpreter. Some languages in this category are FORTRAN, COBOL,
BASIC, JAVA, Pascal etc.
The computer can understand only machine level language, which is in binary 1 or 0. It is difficult to
write and maintain programs in machine level language. So the need arises for converting the code of
high-level and low-level languages into machine level language and translators are used for this purpose.
These translators are just computer program, which accept a program written in high level or low-level
language and produce an equivalent machine language program as output. The three types of translators
used are-
Assembler
Compiler
Interpreter
Assembler is used for converting the code of low-level language (assembly language) into machine level
language.
Compilers and Interpreters are used to convert the code of high-level language into machine language.
The high level program is known as source program and the corresponding machine language program is
known as object program. Although both compiler and interpreters perform the same task but there is a
difference in their working.
A compiler searches all errors of program and lists them. If the program is error free then it converts the
code of program into machine code and then the program can be executed by separate commands.
An interpreter checks the errors of program statement by statement. After checking one statement, it
converts that statement into machine code and then executes that statement. This process continues until
the last statement of program or an erroneous statement occurs.
Computer hardware understands a program only if it is coded in its machine language. It is the job of the
programmer to write and test the program.
The software used to write programs is known as a text editor. A text editor helps us enter, change, and
store character data. Depending on the editor on our system, we could use it to write letters, create reports,
or write programs. The main difference between text processing and program writing is that programs are
written using lines of code, while most text processing is done with character and lines.
Text editor is a generalized word processor, but it is more often a special editor included with the
compiler. Some of the features of the editor are search commands to locate and replace statements, copy
and paste commands to copy or move statements from one part of a program to another, and formatting
commands that allow us to set tabs to align statements.
After completing a program, we save our file to disk. This file will be input to the compiler; it is known as
a source file.
Compiling Programs:
The code in a source file stored on the disk must be translated into machine language ,This is the job of
the compiler. The c compiler is two separate programs. the preprocessor and the translator.
The preprocessor reads the source code and prepares it for the translator. While preparing the code ,it
scans for special instructions known as preprocessor commands. These commands tell the preprocessor to
look for special code libraries, make substitutions in the code ,and in other ways prepare the code for
translation into machine language. The result of preprocessing is called the translation unit.
After the preprocessor has prepared the code for compilation, the translator does the actual work of
converting the program into machine language. The translator reads the translation unit and writes the
resulting object module to a file that can then be combined with other precompiled units to form the final
program. An object module is the code in machine language. The output of the compiler is machine
language code, but it is not ready to run; that is ,it is not executable because it does not have the required
C and other functions included.
Linking Programs:
A C program is made up of many functions. We write some of these functions, and they are a part of our
source program. There are other functions, such as input/output processes and, mathematical library
functions, that exist elsewhere and must be attached to our program. The linker assembles all of these
functions, ours and systems into our final executable program.
Executing Programs:
Once program has been linked, it is ready for execution. To execute a program we use an operating
system command, such as run, to load the program into primary memory and execute it. Getting the
program into memory is the function of an operating system program known as the loader. It locates the
executable program and reads it into memory. When everything is loaded, the program takes control and
it begins execution.
In a typical program execution, the reads data for processing ,either from the user or from a file. After the
program processes the data, it prepares the output. at output can be to the user’s monitor or to a file. When
the program has finished its job, it tells the operating system ,which then removes the program from
memory.
System
Requirement
Analysis
Design
Code
System Test
Maintanance
System Requirements:
The waterfall model starts with System Requirements. In this phase, the systems analyst defines requirements that
specify what the proposed system is to accomplish. The requirements are usually stated in terms that the user
understands.
Analysis:
This phase looks at alternatives from system’s point of view. In this phase programmer analyse the problem and
understand the problem to solve in particular manner.
Design:
Designing phase concerned the designing of the problem. In the design phase, the functions of the individual
programs that will make up the system are determined and the design of the file.
It partitions the requirements to hardware or software systems. It establishes overall system architecture.
The architecture of a software system refers to an abstract representation of that system. Architecture is
concerned with making sure the software system meets the requirements of the product, as well as
ensuring that future requirements can be addressed.
Code:
In coding programmer code the problem in some software language. This activity reduces a design to code and
may be the most obvious part of the software engineering job.
System Test:
After the programs have been written and tested to the programmer’s satisfaction, the project proceeds to system
test. All of the programs are tested together to make sure the system works as a whole.
Maintenance:
The last phase of the software developing is maintenance of the software. In this phase maintenance is required for
successful performance of software.
ALGORITHMS
What is an Algorithm?
An algorithm is “a step-by-step procedure for accomplishing some task'' An algorithm can be given in
many ways. For example, it can be written down in English (or French, or any other ''natural'' language).
Every algorithm should have the following five characteristics:
1. Each algorithm will be logically enclosed by two statements START and STOP.
2. To accept data from user, the INPUT or READ statements are to be used.
3. To display any user message or the content in a variable, PRINT statement will be used. Note
that the message will be enclosed within quotes.
‘<’ Less than ‘=’ Equality ‘>=’ Greater than or equal to ‘!=’ Non-equality
Advantages of Algorithm:
It provides the core solution to a given problem. This solution can be implemented on a computer system
using any programming language of user’s choice.
Disadvantages:
Example 1: Write the algorithm for finding the sum of two numbers
1. START
2. PRINT “ENTER TWO NUMBER”
3. INPUT A, B
4. C = A + B
5. PRINT C
6. STOP
Example 2: Print the largest number among three numbers.
1. START
2. PRINT “ENTER THREE NUMBERS”
3. INPUT A, B, C
4. IF A > B AND B > C THEN
5. PRINT A
6. IF B >C AND C >A THEN
7. PRINT B
8. ELSE
9. PRINT C
10. STOP
Example 3: Classify the triangle as equilateral, isosceles or scalene.
1. START
1. START
2. PRINT “ENTER THE NUMBER”
3. INPUT N
4. F = 1
5. C = 1
6. F = F * C
7. C = C + 1
8. IF C <= N THEN GOTO STEP 6
9. PRINT F
10. STOP
PSEUDOCODE:
There is a need of a specification that only focuses on the logic of the program. Pseudocodes serve
this purpose by specifying only the logic, which is used by the programmer for developing a
computer program.
Pseudocode is a English like statements that follow a freely defined syntax and are used to convey the
design of an algorithm. Its purpose is to describe, in precise algorithmic detail, what the program
being designed is to do. This requires defining the steps to accomplish the task in sufficient details so
that they can be converted into a computer program.
Rules:
Instruction or operation in a pseudocode statement must be kept all capitalized; for example
READ(input operation), PRINT (specify print command), and so on.
The ending of looping and decision-making constructs must be labeled appropriately with
corresponding “END” keywords.
Advantages:
Developing program code using pseudocode is easier in comparison to developing the program code
from flowchart.
Disadvantages:
Since pseudocode does not use any kind of pictorial representations for program elements; it may at
times become difficult to understand the program logic.
Ex:1
BEGIN
END.
FLOWCHARTS:
Some standard symbols frequently required for flowcharting many computer programs are shown
below
A magnetic tape
A magnetic disk
Flow lines
Module Call
Display
START
READ A,B,C
STOP
A
START
NO YES
READ A,B,C IS D>0
NO
YES
D=B*B-4*A*C REAL1 = (-B+SQRT(D)) / (2*A)
IS D>0
REAL2= (-B-SQRT(D)) / (2*A)
A
REAL1=-B/2*A
REAL2=-B/2*A
STOP
START
DECLARE N, I, SUM=0
READ N
i++ i= 0 F
i<N
T
SUM = SUM+N
WRITE SUM
STOP
DECLARE a,b,c
SUM = x+y+z
AVG(avg,a,b,c)
RETURN
WRITE avg
STOP
© Copyright JNTUH College of Engineering, Jagitial
UNIT-I C Programming And Data Structure
1. Explain and specify the interactions between various components that support the basic
functionality of a computer (Computer System)?
2. Differentiate between application software and system software?
3. Briefly discuss various computing environments with neat diagrams?
4. Differentiate between compiler, interpreter and assembler?
5. What are the different types of errors one can encounter during the program execution?
6. Explain about translator, loader and linker?
7. Discuss in detail the program execution steps (creating and Running Program)?
8. List the activities involved in each phase of waterfall system development life cycle model?
9. Define Algorithm? What are the characteristics that any algorithm should satisfy?
10. Write an Algorithm for calculating factorial of a given number?
11. Define Pseudo code? What are the characteristics of Pseudo code?
12. Define Flowchart? Draw a flowchart for finding maximum of given three integers?
13. Draw a flowchart for finding the sum of ‘n’ numbers starting from 1?
14. Draw a flowchart to check whether a given number is perfect or not.
15. Draw a flowchart to finding the roots of Quadratic Equation?
16. Write an Algorithm to find the largest among three numbers?
17. Draw a flowchart to read sum of 10 numbers
18. Draw a flowchart to Avg of 3 subjects using Module call statement?
19. Write an Algorithm to find whether given year is leap year or not?
20. Write an Algorithm to find the whether given number is prime or not?