Chapter 1
Chapter 1
Computer
A computer is a programmable electronic device that accepts raw data as input and process it with a
set of instruction (a program) to produce the result as output.
Input
CU – Control Unit
Controller of all the activities/tasks and operations.
the control unit coordinates the tasks inside the computer in sync with the input and
output units.
Memory Unit
All the data that has to be processed or has been processed is stored in the memory unit. The
memory unit acts as a hub of all the data.
There are two types of computer memory-
1. Primary memory –
used to store recent data.
The data stored in this is temporary so, called temporary memory or main
memory.
RAM stands for Random Access Memory. It is an example of primary
memory. This memory is directly accessible by the CPU.
2. Secondary memory –
the primary memory stores temporary data. Thus it cannot be accessed in the
future. For permanent storage purposes, secondary memory is used.
It is also called permanent memory or auxiliary memory.
The hard disk is an example of secondary memory. Even in a power failure
data does not get erased easily.
Output
All the information sent to the computer once processed is received by the user through the
output unit. Devices like printers, monitors, projectors, etc. all come under the output unit.
Computer Software
It is a computer program which is a sequence of instruction designed to a direct computer to
perform certain task.
It is the interface between user and computer.
It is responsible for controlling, integrating and managing the hardware component of
computer system.
1. System Software
It consists of several programs which responsible for controlling, integrating and
managing the individual hardware components of computer system. Example: OS
2. Application Software
software that performs specific functions for a user. When a user interacts directly with a
piece of software, it is called application software. The sole purpose of application software
is to assist the user in doing specified tasks. Microsoft Word and Excel, as well as popular
web browsers like Firefox and Google Chrome, are examples of application software.
Scope Wide range of tasks and functions. Tailored to specific tasks or functions.
Applicability Used in diverse settings and industries. Designed for specific industries or tasks.
Flexibility Adaptable to various use cases. Less flexible, designed for specific needs.
User Base Typically has a larger user base. May have a smaller, niche user base.
Can be developed more quickly for targeted
Development
Time Takes longer to develop due to complexity. purposes.
Cost Generally more affordable for a broad audience. May be expensive due to specialized features.
Payroll management, Hotel management,
Example DBMS, Graphics, Presentation etc. Reservation System etc.
Updates and Less frequent updates, focused on system More frequent updates, adding
Upgrades improvements. features or fixing issues.
Programming Language
A programming language is a formal language, which comprises a set of instructions that produce
various kinds of output.
It is the set of some instructions written in a specific style (coding) to instruct the computer to do
some specific task.
The description of a programming language is usually split into the two components of syntax (form)
and semantics (meaning). Example: Java, C, C++, Python, PHP
Machine-Level
feature Language Low-Level Language High-Level Language
Representation Binary code mnemonics Similar Natural language
Abstraction Minimal abstraction,
Level close to hardware Moderate abstraction High abstraction
Requires deep
understanding of Requires understanding of Can be used without in-
Accessibility hardware computer architecture depth hardware knowledge
More readable than machine code,
Difficult for humans to Readable and closer to
Readability read and write but still involves low-level details human language
Development Time-consuming due to
Time detailed instructions Moderate development time Faster development time
Not portable, tied to More portable across
Portability specific hardware Moderately portable platforms
Examples Machine code Assembly language, C Python, Java, C#, Ruby
In object-oriented programming language, a problem is divided into a number of objects which can
interact by passing messages to each other.example: c++, c#
Problem Oriented Language were designed to solve specific problem and allow the programmer to
concentrate more on the problem rather than spending time learning complex syntax of
language.example: Query Language
Natural Language using natural Language like English, French etc. to communicate with computer
and it is still under development.
Trend 4: IoT
Problem Analysis
Problem Solving is the sequential process of analyzing information related to a given situation
and generating appropriate response options.
In order to instruct a computer correctly, the user must have clear understanding of the
problem to be solved. A part from this, user should be able to develop a method, in the form
of series of sequential steps, to solve it.
Thus, before attempt to write a computer program to solve a given problem, it is necessary
to formulate or define the problem in a precise manner. Once the problem is defined, the
steps required to solve it, must be stated clearly in the required order.
In order to solve a problem by the computer, one has to pass though certain stages or steps.
They are
Here we try to understand the problem to be solved in totally. Before with the next stage or
step, we should be absolutely sure about the objectives of the given problem.
After understanding thoroughly, the problem to be solved, we look different ways of solving
the problem and evaluate each Algorithm Development and Flowchart 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 carries
out to solve the given problem.
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
implantation.
Algorithm
A set of sequential steps usually written in Ordinary Language to solve a given problem
is called Algorithm.
The choice of various algorithms depends on the factors like reliability, accuracy and
easy to modify.
The most important factor in the choice of algorithm is the time requirement to
execute it, after writing code in High-level language with the help of a computer.
The algorithm which will need the least time when executed is considered the best.
For an algorithm, there are quantities to be supplied called input and these are fed externally.
The input is to be identified first for any specified problem.
From an algorithm, at least one quantity is produced, called for any specified problem.
All the calculations to be performed in order to lead to output from the input are to be
identified in an orderly manner.
The instructions composing the algorithm must be clear and there should not be any
ambiguity in them.
If we go through the algorithm, then for all cases, the algorithm should terminate after a
finite number of steps.
The instructions in the algorithm must be sufficiently basic and in practice they can be carries
out easily.
An algorithm must possess the following properties
1. Finiteness: An algorithm must terminate in a finite number of steps
2. Definiteness: Each step of the algorithm must be precisely and unambiguously stated
3. Effectiveness: Each step must be effective, in the sense that it should be primitive easily
convert able into program statement) can be performed exactly in a finite amount of time.
4. Generality: The algorithm must be complete in itself so that it can be used to solve
problems of a specific type for any input data.
5. Input/output: Each algorithm must take zero, one or more quantities as input data produce
one or more output values. An algorithm can be written in English like sentences or in any
standard representation sometimes, algorithm written in English like languages are called
Pseudo Code.
Example 1. Suppose we want to find the average of three numbers, the algorithm is as
follows
Step 1 Read the numbers a, b, c
Step 2 Compute the sum of a, b and c
Step 3 Divide the sum by 3
Step 4 Store the result in variable d
Step 5 Print the value of d
Step 6 End of the program
Example 2. Write an algorithm to find simple interest.
Flowchart
A flow chart is a step by step diagrammatic representation of the logic paths to solve
a given problem. Or A flowchart is visual or graphical representation of an algorithm.
The flowcharts are pictorial representation of the methods to b used to solve a given
problem and help a great deal to analyze the problem and plan its solution in a
systematic and orderly manner.
A flowchart when translated in to a proper computer language, results in a complete
program.
Advantages of Flowcharts
1. The flowchart shows the logic of a problem displayed in pictorial fashion which felicitates
easier checking of an algorithm.
2. The Flowchart is good means of communication to other users. It is also a compact means
of recording an algorithm solution to a problem.
3. The flowchart allows the problem solver to break the problem into parts. These parts can
be connected to make master chart.
4. The flowchart is a permanent record of the solution, which can be consulted at a later time.
Pseudo code
The Pseudo code is neither an algorithm nor a program. It is an abstract form of a program.
It consists of English like statements which perform the specific operations.
In pseudo code, the program is represented in terms of words and phrases, but the syntax of
program is not strictly followed.
Example:
INPUT s1
INPUT s2
sum=s1+s2
OUTPUT sum
Class Activities:
Language Processor.
A special translator system software is used to translate the program written in high-level
language into machine code is called Language Processor.
Compiler
Interpreter
Assembler
Syntax and Semantics
1. Syntax:
What it is: Syntax refers to the set of rules that dictate how you must structure your
code in a programming language.
Why it matters: Think of syntax as the grammar rules of a programming language.
If you don't follow these rules, the computer won't understand your instructions.
Example: In C, to print something, you use the syntax printf("Hello, World!"); If you
forget the parentheses or the quotation marks, you'll get a syntax error.
2. Semantic:
What it is: Semantic refers to the meaning or interpretation of the code. It's about
understanding what the code does.
Why it matters: Even if your code has perfect syntax, it might not do what you
intend if the semantics are off. It's like using correct grammar but expressing the
wrong idea.
Example: In a programming language, if you define a variable temperature and later
use it in a calculation, the semantic correctness depends on whether it represents
Celsius or Fahrenheit. Using it in the wrong context could lead to incorrect results.
Source Code refers to file which is a text-based document that is written by the
programmer. The Source Code is human readable but machines cannot understand
instructions.
Object Code is the output of the compiler and is a binary file having instructions that are given
by the programmer in the Source Code. These instructions are encoded in the binary digits and
Object Code is machine readable, or better to say machine executable code, but not human
readable. Object Code is generated through a process called compilation.
A linker is a computer program that takes one or more object files generated by a compiler
and combines them into one, executable program.
A
A syntax error on many scientific calculators can occur in many ways, including:
Open bracket without closing bracket (unless missing closing bracket is at the
very end)
Trying to use negative number symbol as a minus sign
Having missing numbers in an equation (e.g. “12*+5” )
b) Semantics Errors
A semantic error is also called a "logic error;" however, some programmers
believe a logic error produces erroneous data, whereas a semantic error yields
nothing meaningful at all.
3. Logical Errors
A logic error (or logical error) is a mistake in a program's source code that results
in incorrect or unexpected behavior. It is a type of runtime error that may simply
produce the wrong output or may cause a program to crash while running.
Debugging
It is the process of isolating and correcting different type of errors
Debugging Technique:
1. Error Isolation
Find location of error by temporarily deleting a certain portion of program code and
see the changes appear on system.
2. Tracing
printf () statement is used to print values of some important variable at different stage
of program.
3. Watch Values
A watch value is the value of variable or an expression which is display continuously
as program execute.
4. Breakpoints
It is a temporary stopping point with in program.
5. Stepping
The process of executing one instruction at a time is called stepping.
Testing
It is the process of executing a program or system with the intent of finding errors.
Testing is usually performed for improving quality, verification and validation and reliability
of software.
Human testing
Computer Based Testing (compile and run time testing)
Documentation
Documentation is written text or illustration that accompanies computer software or is embedded in
the source code. It either explains how it operates or how to use it, and may mean different things to
people in different roles.
Advantages of Documentation
These are some of the advantages of providing program documentation −
Keeps track of all parts of a software or program
Maintenance is easier
Programmers other than the developer can understand all aspects of software
Improves overall quality of the software
Assists in user training
Ensures knowledge de-centralization, cutting costs and effort if people leave the system
abruptly
Problem definition
Program Design (algorithm/flow chart)
Coding
Compilation and execution
Debugging and Testing
Documentation
Class Activities:
Write an algorithm and draw flow chart:
1. To find convert temp from Celsius to Fahrenheit(F=9/5C+32)
2. To find area and perimeter of circle
3. To find volume largest among two number
4. To find largest among three number
5. To find factorial of number