Pps - Unit-1 Bcs101 Notes
Pps - Unit-1 Bcs101 Notes
Computer: A computer is a machine or device that performs processes, calculations and operations based on instructions
provided by a software or hardware program. It is designed to execute applications and provides a variety of solutions by
combining integrated hardware and software components.
A computer is made up of multiple parts and components that facilitate user functionality. A computer has two primary
categories:
Hardware: Physical structure that houses a computer's processor, memory, storage, communication ports and
peripheral devices
Software: Includes operating system (OS) and software applications
Digital Computer: All computer system (irrespective of their shape & size) performs the following 5 basic operations. It
converts the raw input data into information, which is useful to the users.
Inputting: It is the process of entering data & instructions to the computer system.
Storing: The data & instructions are stored for either initial or additional processing.
Processing: It requires performing arithmetic or logical operation on the saved data to convert it into useful information.
Outputting: It is the process of producing the output data to the end user.
Controlling: The above operations have to be directed in a particular sequence to be completed.
Input Unit: We need to first enter the data & instruction in the computer system, before any computation begins. This task
is accomplished by the input devices. (Eg: keyboard, mouse, scanner, digital camera etc.)
Storage Unit: The data & instruction that are entered have to be stored in the computer. Similarly, the end results & the
intermediate results also have to be stored somewhere before being passed to the output unit. The storage unit provides
solution to all these issues. This storage unit is designed to save the initial data, the intermediate result & the final result.
Primary Storage: The primary storage, also called as the main memory, holds the data when the computer is currently on.
As soon as the system is switched off or restarted, the information held in primary storage disappears (i.e. it is volatile in
nature).
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Secondary Storage: The secondary storage, also called as the auxiliary storage, can retain information even when the
system is off. It is basically used for holding the program instructions & data on which the computer is not working on
currently, but needs to process them later.
Central Processing Unit: Together the Control Unit & the Arithmetic Logic Unit are called as the Central Processing Unit
(CPU). The CPU is the brain of the computer. Like in humans, the major decisions are taken by the brain itself & other
body parts function as directed by the brain. Similarly in a computer system, all the major calculations & comparisons are
made inside the CPU. The CPU is responsible for activating & controlling the operation of other units of the computer
system.
Arithmetic Logic Unit: The actual execution of the instructions (arithmetic or logical operations) takes place over here.
Intermediate results that are generated in ALU are temporarily transferred back to the primary storage, until needed later.
Hence, data may move from the primary storage to ALU & back again to storage, many times, before the processing is
done.
Control Unit: This unit controls the operations of all parts of the computer but does not carry out any actual data
processing. It is responsible for the transfer of data and instructions among other units of the computer. It manages and
coordinates all the units of the system. It also communicates with Input/output devices for transfer of data or results from
the storage units.
Output Unit: The job of an output unit is just the opposite of an input unit. It accepts the results produced by the computer
in coded form. It converts these coded results to human readable form. Finally, it displays the converted results to the
outside world with the help of output devices (E.g. monitors, printers, projectors etc).
Computer Memory– Memory is storage part in computer. It stores data, information, programs during processing in
computer. It stores data either temporarily or permanent basis. Memory used to important role in saving and retrieving
data.
1. Primary Memory / Volatile Memory– Primary memory is internal memory of the computer. It is also known as main
memory and Temporary memory. Primary Memory holds the data and instruction on which computer is currently working.
Primary Memory is nature volatile. It means when power is switched off it lost all data.
Types of Primary Memory– Primary memory is generally of two types.
RAM (Random Access Memory) – It stands for Random Access Memory. RAM is known as read /writes memory. It
generally refereed as main memory of the computer system. It is a temporary memory. The information stored in this
memory is lost as the power supply to the computer is switched off. That’s why RAM is also called “Volatile Memory”.
RAM is also of two types:
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
a) Static RAM- Static RAM also known as SRAM, retain stored information as long as the power supply is ON. SRAM are
of higher coast and consume more power. They have higher speed than Dynamic RAM.
b) Dynamic RAM– Dynamic RAM also known as DRAM, its stored information in a very short time (a few milliseconds)
even though the power supply is ON. The Dynamic RAM is cheaper and moderate speed and also they consume less power.
ROM (Read Only Memory) – It stands for Read Only Memory. ROM is a Permanent Type memory. Its content are not
lost when power supply is switched off. Content of ROM is decided by the computer manufacturer and permanently stored
at the time of manufacturing. ROM cannot be overwritten by the computer. It is also called “Non-Volatile Memory”.
ROM memory is three types names are following-
PROM (Programmable Read Only Memory)-PROM chip is programmable ROM .It is PROM chips to write data once
and read many. Once chip has been programmed, the recorded information cannot be changed. PROM is also nonvolatile
memory.
EPROM (Erasable Programmable Read Only Memory) - EPROM chip can be programmed time and again by erasing
the information stored earlier in it. Information stored in EPROM exposing the chip for some time ultraviolet light.
EEPROM (Electrically Erasable Programmable Read Only Memory)-The EEPROM is programmed and erased by
special electrical waves in millisecond. A single byte of a data or the entire contents of device can be erased.
2. Secondary Memory / Non Volatile Memory– Secondary Memory is external memory of the computer. It is also
Known as Auxiliary memory and permanent memory. It is used to store the different programs and the information
permanently. Secondary Memory is nature non volatile. It means data is stored permanently even if power is switched
off.example: Floppy Disks, Magnetic (Hard) Disk, Magnetic Tapes, Pen Drive, Optical Disk (CD, DVD).
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Differences between Primary and Secondary Memory
Cache Memory: A special very high-speed memory called a cache is sometimes used to increase the speed of
processing by making current program and data available to the CPU at a rapid rate.
The purpose of cache memory is to store program instructions and data that are used repeatedly in the operation of
programs or information that the CPU is likely to need next. The computer processor can access this information quickly
from the cache rather than having to get it from computer's main memory. In the Memory Hierarchy System, a cache
memory is placed between CPU & main memory.
Memory Hierarchy: The total memory capacity of a computer can be visualized by hierarchy of components. The
memory hierarchy system consists of all storage devices contained in a computer system from the slow Auxiliary Memory
to fast Main Memory and to smaller Cache memory.
A "memory hierarchy" in computer storage distinguishes each level in the “hierarchy" by response time. Each level
of the hierarchy is of higher speed and lower latency, and is of smaller size, than lower levels. ... Faster memory is
costly.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
System Software- System software are a set of programs, responsible for running the computer, controlling
various operations of computer systems and management of computer resources. They act as an interface between
the hardware of the computer & the application software. E.g.: Operating System
Application Software- Application software is a set of programs designed to solve a particular problem for users.
It allows the end user to do something besides simply running the hardware. E.g.: Web Browser, Gaming
Software, etc.
System software is used for operating Application software is used by user to perform
1. computer hardware. specific task.
Translators: A program written in high-level language is called as source code. To convert the source code into
machine code, translators are needed. A translator takes a program written in source language as input and converts it into
a program in target language as output. It also detects and reports the error during translation.
Roles of translator:
1. Translating the high-level language program input into an equivalent machine language program.
2. Providing diagnostic messages wherever the programmer violates specification of the high-level language program.
Type of translators: The different types of translator are as follows:
Compiler: Compiler is a translator which is used to convert programs in high-level language to low-level language. It
translates the entire program and also reports the errors in source program encountered during the translation.
Interpreter: Interpreter is a translator which is used to convert programs in high-level language to low-level language.
Interpreter translates line by line and reports the error once it encountered during the translation process. It directly
executes the operations specified in the source program when the input is given by the user. It gives better error
diagnostics than a compiler.
Assembler: Assembler is a translator which is used to translate the assembly language code into machine language.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Memory Memory requirement is more due to It requires less memory as it does not
the creation of object code. create intermediate object code.
Errors Display all errors after compilation, Displays error of each line one by one.
all at the same time.
Error detection Difficult Easier comparatively
Programming C, C++, C# uses compiler. PHP, Perl, Python, Ruby uses an
languages interpreter.
Loader: Loader is the program of the operating system which loads the executable from the disk into the primary
memory (RAM) for execution. It allocates the memory space to the executable module in main memory and then
transfers control to the beginning instruction of the program.
Linker: It is a computer program that takes one or more object files generated by a compiler and combines them into
one, executable program. Computer programs are usually made up of multiple modules that span separate object files, each
being a compiled computer program. The program as a whole refers to these separately compiled object files using
symbols. The linker combines these separate files into a single, unified program; resolving the symbolic references as it
goes along.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Computer Program: A program is a set of instructions following the rules of the chosen language.
Programming Language:
• A vocabulary and set of grammatical rules (syntax) for instructing a computer to perform specific tasks. • Programming
languages can be used to create computer programs.
• The term programming language usually refers to high-level languages, such as BASIC, C, C++, COBOL, FORTRAN,
Ada, and Pascal.
First Generation Programming Language (1GL): First generation of programming language refers to machine
language.
Machine language is lower level language which uses object code (sometimes also known as machine code). Object code
is the combination of binary digits.
These languages directly talk to hardware.
While easily understood by computers, machine languages are almost impossible for humans to use because they consist
entirely of numbers.
Programs written in machine language are not portable.Example:
Second Generation Programming Language (2GL): Second generation of languages is also low level language which
is known as assembly language.
A program written in assembly language consists of a series of instructions mnemonics that correspond to a stream of
executable instructions, when translated by an assembler that can be loaded into memory and executed.
Assembly languages use keywords and symbols (mnemonics) much like English, to form a programming language but at
the same time introduce a new problem.
Programs written in machine language are not portable.
The problem is that the computer doesn't understand the assembly code, so we need a way to convert it to machine code.
Assembly language programs are translated into machine language by a program called an assembler.
Algorithm: An algorithm is a description of a procedure which terminates with a result. Algorithm is a step by-step
method of solving a problem. Purpose of algorithms is to implement re-usability in software applications. Once we have
designed the overview of solution to any problem in algorithmic form it can be coded in any language like C, C++, Java
etc.
Types of Algorithm:
Algorithms generally fall under two categories:
Iterative: These algorithms sequentially execute the input using loops and conditional statements. E.g. Linear
search
Recursive: These algorithms recursively break a larger problem into some smaller problems and solve those
problems. Then they combine the result of smaller problems to solve the main given problem.
Pseudo code is a simple way of writing programming code in English. Pseudo code is not actual programming language.
It uses short phrases to write code for programs before you actually create it in a specific language. Once you know what
the program is about and how it will function, then you can use pseudo code to create statements to achieve the required
results for your program. Algorithms are written in Pseudo code.
1. Start
2. Enter length, L
3. Enter width, B
4. Compute Perimeter = 2*L+ 2*B
5. Display Perimeter of a rectangle
6. End
Flowchart: A flowchart is a graphical or pictorial representation of an algorithm. Each step in the process is
represented by a different symbol and contains a short description of the process step. The flow chart symbols are linked
together with arrows showing the process flow direction. Some common flowchart symbols are listed below.
Example 1: Flowchart to compute the perimeter of a Example 2: Flowchart to convert temperature Fahrenheit to
rectangle: Celsius
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Advantages of Flowchart:
Better explanation of program: Flowchart is a pictorial description of any program. The program created by it can
easily be understood.
Effective analysis: Through the flowcharts, the program is divided into smaller parts, making effective analysis of the
program.
Systematic debugging: When any program is created, it is always tried to make it right, but still the mistake remains
somewhere. These mistakes can only be known when we start the execution of the program on the computer. The
mistake of this type of program, is called Bugs and the method of removing this mistake, is called Debugging. A flow
chart is very helpful in detecting, locating and removing the mistake in a program.
Disadvantages of Flowchart:
Time consuming: Creating a flow chart takes more time. The flow chart is made especially for big complex problems.
Which take more time and very hard work?
Difficult to make changes: If there is any modification in the flow chart the entire flowchart has to be recreated.
No standard: Program flowcharts, although easy to understand, but cannot be written as a standard, like others language.
Nor with the help of flowcharts, it can be converted into the language of the program. Each programmer resolves the
problem in its own way and creates a flow chart accordingly.
Structure of C Program: The structure of a C program is a protocol (rules) to the programmer, which he has to
follow while writing a C program. The general basic structure of C program is shown in the figure below.
/* Documentation section */
/* Link section */
/* Definition section */
/* Global declaration section */
main()
{
Declaration part
Executable part (statements)
}
/* Sub-program section */
The documentation section: is used for displaying any information about the program like the purpose of the program
etc, and this section should be enclosed within comment lines. The statements in the documentation section are ignored
by the compiler.
The link section: consists of the inclusion of header files.
The definition section: consists of macro definitions, defining constants etc. Anything declared in the global declaration
section is accessible throughout the program, i.e.accessible to all the functions in the program.
main ( ): function is mandatory for any program and it includes two parts, the declaration part and the executable part.
Sub-program section: is optional and used when we require including user defined functions in the program.
#include <stdio.h>
void main( )
{
int number;
printf("Please enter a number: " );
scanf("%d", &number );
printf("You entered %d", number );
return 0;
}
#include
The part of the compiler which actually gets your program from the source file is called the preprocessor.
#include <stdio.h>
#include is a pre-processor directive. It is not really part of our program, but instead it is an instruction to the
compiler to make it do something. It tells the C compiler to include the contents of a file (in this case the system file
called stdio.h).
The compiler knows it is a system file, and therefore must be looked for in a special place, by the fact that the
filename is enclosed in < > characters
<stdio.h>
stdio.h is the name of the standard library definition file for all STanDard Input and Output functions.
Your program will almost certainly want to send information to the screen and read things from the keyboard, and
stdio.h is the name of the file in which the functions that we want to use are defined.
The function we want to use is called printf. The actual code of printf will be tied in later by the linker.
The ".h" portion of the filename is the language extension, which denotes an include file.
void
This means that this means nothing. In this case, it is referring to the function whose name follows.
Void tells to C compiler that a given entity has no meaning, and produces no error.
main
In this particular example, the only function in the program is called main.
A C program is typically made up of large number of functions. Each of these is given a name by the programmer
and they refer to each other as the program runs. C regards the name main as a special case and will run this
function first i.e. the program execution starts from main.
{ (Brace)
As the name implies, braces come in packs of two - for every open brace there must be a matching close one.
Braces allow us to group pieces of program together, often called a block.
A block can contain the declaration of variable used within it, followed by a sequence of program statements. In
this case the braces enclose the working parts of the function main.
; (semicolon)
All statements in C programs are separated by ";" (semicolon) characters. It tells the compiler where a given statement
ends.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
If the compiler does not find one of these characters where it expects to see one, then it will produce an error.
scanf
The function used to get input from the user during execution of program and stored in a variable of specified form is
called scanf ( ) function.
printf
This function is used to display text, constant or value of variable on screen in specified format.
Just like scanf, it is described in the system file stdio.h.
1. Source File- This file contains the source code of the program. The file extension of any c file is .c. The file contains C
source cod e that defines the main function & maybe other functions.
2. Header File- A header file is a file with extension .h which contains the C function declarations and macro definitions and to be
shared between several source files.
3. Object File- An object file is a file containing object code, with an extension .o, meaning relocatable format machine code that
is usually not directly executable. Object files are produced by an assembler, compiler, or other language translator, and used as
input to the linker, which in turn typically generates an executable or library by combining parts of object files.
4. Executable File- The binary executable file is generated by the linker. The linker links the various object files to produce a
binary file that can be directly executed.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Types of Errors
Syntax error: The errors which arises due to violation of any rule or regulation of C language during the development of
program those errors are known as Syntax error. These errors are these errors are identified by a compiler during compilation.
Example: missing of semicolon.
Runtime error: The error that occurs during execution of program those errors are turn termed as runtime error. These errors
are identified during linking object code with system library. Example: incorrect header file name.
Logical error: The errors which are introduced due to usage of wrong expression formula for logic in program these errors are
called as logical error for example using 2 * 3.14 as area of circle.
Input data error: The error which occur during the data entry process because of entering wrong input values after the
execution of program
C Language Components
1) The Character Set: Character set is a set of valid characters that a language cab recognize. A character represents any letter,
digit or any other sign.
2) Tokens: The smallest individual unit in a program is known as a token.C has five tokens:
i. Keywords
ii. Identifiers
iii. Constants
iv. Strings
v. Operators
vi. Special Symbols
i) Keywords: Keywords are reserved word in C. They have predefined meaning cannot changed. All keywords must be written in
lowercase. Eg:- auto,long,char,short etc.There are total 32 keywords in C.
ii) Identifiers: - Identifiers refer to the names of variable, functions and arrays. These are user- defined names. An identifier in C
can be made up of letters, digits and underscore. Identifiers may start with either alphabets or underscore. Two rules must be
kept in mind when naming identifiers.
iii) Constants: - Constants in C refers to fixed values that do not change during the execution of a program. C support several types
of constants.
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
Integer Constant: - An integer constant is a whole number without any fractional part. C has three types of integer
constants.
Octal Constant: - An Octal integer constant can be any combination of digits from 0 through 7. In C the first digit of an octal
number must be a zero(0) so as to differentiate it from a decimal number. Eg.: 06,034,-07564.
Hexadecimal Constant: Hexadecimal integer constants can be any combination of digits 0 through 9 and alphabets from „a‟
through „f‟ or „A‟ through „F‟. In C, a hexadecimal constant must begin with 0x or 0X (zero x) so as to differentiate it from
a decimal number. Eg:- 0x50,0XAC2 etc
Floating Constants (Real): Real or floating point numbers can contain both an integer part and a fractional part in the
number.
E.g:- 18.5, .18 etc.
Very large and very small numbers are represented using the exponent form. The exponent notation use the „E‟ or „e‟
symbol in the representation of the number. The number before E‟ is called as mantissa and the number after forms the
exponent.
Eg:-5.3E-5, 78e05
Single Character Constant: - A character constant in usually a single character or any symbol enclosed by single quotes.
Eg.: ch=’a’
String Constant: - A sequence of character enclosed between double quotes is called string constant. Eg. “Hello Good
Morning”
Punctuations: - 23 characters are used as punctuations in C. eg: + _ /; : > ! etc.
iv) String:- It may consist of any combination of digits, letters, escaped sequences and spaces enclosed in double quotes.Every
string constant ends up with a NULL character which is automatically assigned (before the closing double quotation mark) by
the compiler.
v) Operators: -
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C language is
rich in built-in operators and provides the following types of operators:
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Increment and decrement operators
• Conditional operators
vi) Special Symbols:!@#$%^&*
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
3) Variables: A variable is an object or element that may take on any value or a specified type. Variable are nothing but
identifiers, which are used to identify variables programming elements. Eg: name, sum, stu_name, acc_no etc.
4) Data types: Data types indicate the types of data a variable can have. A data types usually define a set of values, which
can be stored in the variable along with the operations that may be performed on those values. C includes two types of
data.
The process of giving something to the computer is known as input. Input is mostly given through keyboard.
The process of getting something from the computer is known as output.
Types of I/O Statements:
scanf() function: The function used to get input from the user during execution of program and stored in a variable of
specified form is called scanf() function.
Syntax:
scanf(“format string”,& variable name);
format string format specifier is written & address operator
Types:
Single input eg. scanf(“%d”,&a);
Multiple input eg. scanf(“%d %d”, &a,&b);|
Example :
#include<stdio.h>
void main ()
{
int a;
printf("Enter integer value:");
scanf("%d",&a);
printf("The value you enter = %d",a);
}
Output Enter integer value: 5 The value you enter =5
printf () function: This function is used to display text, constant or value of variable on screen in specified format.
Syntax:
printf(“format string”, argument list);
Types:
printf(“hello world”); // Printf()with no argument list
printf(“the value of integar=%d”,a); //Printf() with one argument
printf(“Sum of %d+%d=%d”,a,b,a+b); //Printf()with more than one argument
getchar(): The getchar function is a part of the standard C input/output library. It returns a single character from a standard
input device (typically a keyboard). The function does not require any arguments, though a pair of empty parentheses must
follow the word getchar.
Syntax
character variable = getchar( );
where character variable refers to some previously declared character variable
PROGRAMMING FOR PROBLEM SOLVING (BCS101/BCS201)
Lecture Notes (Unit-1)
. getch() getche()
getch() is used to get a character getche() is used to get a character from console, and
from console but does not echo to echoes to the screen.
the screen.
It reads a single character directly getche() reads a single character from the keyboard and
from the keyboard, without echoing echoes it to the current text window, using direct video
to the screen. or BIOS.
putchar():The putchar function like getchar is a part of the standard C input/output library. It transmits a single character
to the standard output device (the computer screen).
Syntax
putchar (character variable)
Where character variable refers to some previously declared character variable.