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

Chapter 1

The document provides an introduction to computer programming, explaining the components of a computer system, including the CPU, memory units, and software types. It covers programming languages, their generations, and categorization, along with problem-solving methodologies using algorithms and flowcharts. Additionally, it discusses the importance of language processors and the syntax and semantics of programming languages.
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)
3 views17 pages

Chapter 1

The document provides an introduction to computer programming, explaining the components of a computer system, including the CPU, memory units, and software types. It covers programming languages, their generations, and categorization, along with problem-solving methodologies using algorithms and flowcharts. Additionally, it discusses the importance of language processors and the syntax and semantics of programming languages.
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

Introduction to computer Programming

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

The sole purpose is to connect the user and the computer.


It is used to feed data and instruction to CPU.
The 3 major functions of the input unit are-
Take the data to be processed by the user.
Convert the given data into machine-readable form.
And then, transmit the converted data into the main memory of the computer.

CPU – Central Processing Unit

the brain of the computer


It works the same way a human brain works.
As the brain controls all human activities, similarly the CPU controls all the tasks.

ALU – Arithmetic Logic Unit


1. the basic arithmetical operation Like addition, subtraction, multiplication, and
division. It performs all sorts of calculations required on the data.
2. The unit is also responsible for performing logical operations like AND, OR, Equal
to, Less than, etc. In addition to this it conducts merging, sorting, and selection of the
given data.

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.

a. General Purpose Software


b. Specific Purpose Software

Feature General-Purpose Software Specific-Purpose Software

Scope Wide range of tasks and functions. Tailored to specific tasks or functions.

Versatility Versatile, applicable across industries. Specialized, focused on specific domains.

Functionality Broad range of features. Limited to specific tasks or applications.


Word processors, web browsers, operating Medical imaging software, CAD tools, POS
Examples systems. systems.

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.

feature System Software Application Software


Manages computer resources and provides Performs specific tasks for end-
Purpose a platform for running applications. users.
Word processors (e.g.,
Operating systems (e.g., Windows), device Microsoft Word), web
Examples drivers. browsers.

Fundamental, manages hardware and Task-specific, addresses user


Scope provides a foundation. needs.

Direct Interacts with users for specific


Interaction Interacts directly with computer hardware. tasks.
Installed first, essential for the computer to Depends on system software
Dependency function. for support.

Development Emphasizes efficiency and hardware Focuses on user experience


Focus management. and tasks.

Updates and Less frequent updates, focused on system More frequent updates, adding
Upgrades improvements. features or fixing issues.
Programming Language

The act of writing computer programs is called computer programming.

A programming language is a formal language, which comprises a set of instructions that produce
various kinds of output.

programming language is the medium of communication between you (a person) and a


computer system.

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

Features of good program


Gives correct output
clarity
readable
understandable
simple

Types of Programming Language


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

Generation of Programming Language

There are five generation of Programming languages. They are:


a) First Generation Languages :

low-level languages like machine language


is pure machine code, that is just ones and zeros
e.g.. Programmers have to design their code by hand then transfer it to a computer by
using a punch card, punch tape or flicking switches.

b) Second Generation Languages:


low-level assembly languages used in kernels and hardware drives.
The usage of these mnemonic codes such as LDA for load and STA for store means the
code is easier to read and write.
To convert an assembly code program into object code to run on a computer requires
an Assembler and each line of assembly can be replaced by the equivalent one line of
object (machine) code:

c) Third Generation Languages:

high-level languages like C, C++, Java, Visual Basic and JavaScript.


brought many programmer-friendly features to code such as loops, conditionals, classes
etc.
This means that one line of third generation code can produce many lines of object
(machine) code
saving a lot of time when writing programs.

d) Fourth Generation Languages:

consist of statements that are similar to statements in the human language.


These are used mainly in database programming and scripting.
Example of these languages include Perl, Python, Ruby, SQL, MatLab (Matrix
Laboratory)
They are designed to reduce programming effort and the time it takes to develop
software, resulting in a reduction in the cost of software development

e) Fifth Generation Languages:

These languages were intended to make programming more accessible to non-programmers


and to facilitate the development of complex applications.
These are the programming languages that have visual tools to develop a program.
Examples of fifth generation language include Mercury, SQL, and Prolog.

Categorization of Programming language


1. programming language

1.1 High level language

1.2 Low Level Language

1.1.1 Procedure Oriented Language

1.1.2 Object Oriented Language

1.1.3 Problem Oriented Language

1.1.4 Natural Language

1.2.1 Machine Language

1.2.2 Assembly Language


In Procedure Oriented Language, a program is written as a sequence of procedures. Each procedure
contains a series of instruction for performing a specific task.example: c programming

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.

General Software Features


Portability
Maintainability
Efficient
Reliable
Machine Independent
Cost Effective
Flexible
Correctness
Reusability
Secure

Recent trends in Computer software developments are:

Trend 1: Artificial Intelligence (AI)

Trend 2: Cross-Platform Development Tools

Trend 3: Block chain

Trend 4: IoT

Trend 5: Deep learning

Trend 6: Neural Network


Problem Solving using Computer

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

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

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

Steps involved in algorithm development

Step 1. Identification of input:

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.

Step 2: Identification of output:

From an algorithm, at least one quantity is produced, called for any specified problem.

Step 3: Identification the processing operations:

All the calculations to be performed in order to lead to output from the input are to be
identified in an orderly manner.

Step 4: Processing Definiteness:

The instructions composing the algorithm must be clear and there should not be any
ambiguity in them.

Step 5: Processing Finiteness:

If we go through the algorithm, then for all cases, the algorithm should terminate after a
finite number of steps.

Step6 : Possessing Effectiveness :

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.

Symbols used flowchart

Guidelines to be followed to draw a flow chart


All necessary requirement should be listed out in logical order.
Should be clear, neat, and easy to follow
Flow chart has logical start and finish
usual direction of flow chart is from left to right or top to bottom.
only 1 flow line should be come out from a process symbol
only 1 flow line should enter a decision symbol but 2 or 3 flow line (one for each
possible answer) should leave the decision symbol.
Only 1 flow line is used in conjunction with terminal symbol
Avoid the intersection of flow lines
If flow chart become complex use connector to reduce number of flow lines

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:

NUMBER s1, s2, sum

OUTPUT ("Input number 1:")

INPUT s1

OUTPUT ("Input number 2:")

INPUT s2

sum=s1+s2

OUTPUT sum

Class Activities:

Write algorithm and design flowchart of followings:

1. To find convert temp from Celsius to Fahrenheit(F=9/5C+32)


2. To find area and perimeter of circle
3. To find largest of two number a,b
4. To find the largest of three numbers a,b,c
5. To find factorial of number

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 and Object Code

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

Compilation and Execution


The process by which source codes of a computer programming language are translated into machine
codes is known as compilation. After compilation if everything is ok, the code is going under other
process that is known as execution. We get the required output after execution process.

Figure: Illustration of Compilation Process

Debugging and Testing


It is the process of detecting and removing error in a program, so that the program produces
the desired results on all occasion.
Program Errors
1. Runtime error
Those errors that occurs during the execution of a c program and generally
occurs due to illegal operation that perform in the program.
eg. dividing number by zero
try to open file which is not created
lack of free memory space
2. Compile error
Those errors that occur at the time of compilation of program.
a) Syntax Errors
A syntax error in computer science is an error in the syntax of a coding or
programming language, entered by a programmer. Syntax errors are caught by a
software program called a compiler, and the programmer must fix them before the
program is compiled and then run.

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.

These are some guidelines for creating the documents −


Documentation should be from the point of view of the reader
Document should be unambiguous
There should be no repetition
Industry standards should be used
Documents should always be updated
Any outdated document should be phased out after due recording of the phase out

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

Program Development cycle/ Process/stage

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

Assignment 1: Short notes of Compiler, Interpreter and Assembler


Difference between compiler and Interpreter and assembler
Assignment 2: Write algorithm and draw flowchart of following:
1. To find volume of cube
2. To find volume of cylinder
3. To find smallest of two number
4. To find root of quadratic equation ax2+bx+c
5. To find sum of series 1+2+3+4+…+N
6. To find Fibonacci series till term <1000
7. To find largest among N number
8. To find number is even or odd

You might also like