PPS Module-1
PPS Module-1
Functions of Computers
A computer performs the following functions −
Receiving Input
Data is fed into computer through various input devices like keyboard, mouse, digital
pens, etc. Input can also be fed through devices like CD-ROM, pen drive, scanner, etc.
Processing the information
Operations on the input data are carried out based on the instructions provided in the
programs.
Storing the information
After processing, the information gets stored in the primary or secondary storage area.
Producing output
The processed information and other details are communicated to the outside world
through output devices like monitor, printer, etc.
Components of Computer
Computer systems consist of three components as shown in below image: Central
Processing Unit, Input devices and Output devices. Input devices provide data input
to processor, which processes data and generates useful information that’s displayed to
the user through output devices. This is stored in computer’s memory.
Input devices help to get input or data from user. Some of input devices are −
Control Unit
As name indicates, this part of CPU extracts instructions, performs execution, maintains
and directs operations of entire system.
Functions of Control Unit
Control unit performs following functions −
Memory Unit
This is unit in which data and instructions given to computer as well as results given by
computer are stored. Unit of memory is "Byte".
1 Byte = 8 Bits
Computer memory refers to storage area where data is stored. It is of two types −
Primary Memory
Secondary Memory
Primary Memory
Primary memory is the main memory of computer present in motherboard. Primary
memory is of two types as shown in the image below.
The below table jots down the major differences between RAM and ROM −
2 The contents are temporary; data The contents are permanent; data is
is lost when electricity supply is not lost even when power is switched
lost. off.
Secondary Memory
Sometimes when data to be processed is large, it cannot fit in primary memory as it is
limited, in such cases, we use supplement memory or secondary memory. Secondary
memory helps to store information permanently and is non-volatile. Examples of
secondary storage memory are compact disk, floppy disk, pen drive, external hard
drive, etc.
Operating System
Operating system is a software that controls system’s hardware and interacts with user
and application software.
In short, an operating system is computer’s chief control program.
Introduction to Compiler
o A compiler is a translator that converts the high-level language into the machine
language.
o High-level language is written by a developer and machine language can be
understood by the processor.
o Compiler is used to show errors to the programmer.
o The main purpose of compiler is to change the code written in one language
without changing the meaning of the program.
o When you execute a program which is written in HLL programming language
then it executes into two parts.
o In the first part, the source program compiled and translated into the object
program (low level language).
o In the second part, object program translated into the target program through
the assembler.
Characteristics of Algorithm
1. An algorithm should be defined clearly.
2. An algorithm should produce at least one output.
3. An algorithm should have zero or more inputs.
4. An algorithm should be executed and finished in finite number of steps.
5. An algorithm should be basic and easy to perform.
6. Each step started with a specific indentation like, “Step-1”,
7. There must be “Start” as the first step and “End” as the last step of the
algorithm.
Step 1: Start
Step 2: Take some water in a bowl.
Step 3: Put the water on a gas burner.
Step 4: Turn on the gas burner
Step 5: Wait for some time until the water is boiled.
Step 6: Add some tea leaves to the water according to the requirement.
Step 7: Then again wait for some time until the water is getting colorful as tea.
Step 8: Then add some sugar according to taste.
Step 9: Again wait for some time until the sugar is melted.
Step 10: Turn off the gas burner and serve the tea in cups with biscuits.
Step 11: End
Here is an algorithm for making a cup of tea. This is the same for computer
science problems.
WAP in C
#include<stdio.h>
#include<conio.h>
int main() {
int length, breadth, area;
return (0);
}
Output:
Step 4: If 'x' is less than 20, then go back to step 2. Otherwise, go to the next step.
Step 5: Exit.
Advantages of Algorithm
An algorithm uses a definite procedure.
It is easy to understand because it is a step-by-step definition.
The algorithm is easy to debug if there is any error happens.
It is not dependent on any programming language
It is easier for a programmer to convert it into an actual program because the
algorithm divides a problem into smaller parts.
Disadvantages of Algorithms
An algorithm is Time-consuming, there is specific time complexity for
different algorithms.
Large tasks are difficult to solve in Algorithms because the time complexity
may be higher, so programmers have to find a good efficient way to solve
that task.
Looping and branching are difficult to define in algorithms.
Flowchart
The Flowchart is the most widely used graphical representation of an algorithm and
procedural design workflows. It uses various symbols to show the operations and
decisions to be followed in a program. It flows in sequential order. As an instance, a
parallelogram in the flowchart may be used to indicate input and output, a rectangular
box indicates a mathematical operation, a diamond symbol indicates the decision-
making statements, and several other symbols are used in flowcharts.
In many cases, a programmer usually makes a flowchart using paper and pencil or
makes it by connecting the shapes on a computer screen using the software. In a large
system, a flowchart is an important document for a system and individual program
because it summarizes a program's function in the form of symbols that are easy to
understand and clearly explained in English.
Advantages of flowchart
o Proper debugging
o Effective analysis
o Efficient coding
o Proper documentation
o Efficient program maintenance
Disadvantages of flowchart
o Time-consuming
o Complex
o Difficult to modify
o It has no standard
Programming Errors in C
Errors are the problems or the faults that occur in the program, which makes the
behavior of the program abnormal, and experienced developers can also make these
faults. Programming errors are also known as the bugs or faults, and the process of
removing these bugs is known as debugging.
These errors are detected either during the time of compilation or execution. Thus, the
errors must be removed from the program for the successful execution of the program.
o Syntax error
o Run-time error
o Linker error
o Logical error
o Semantic error
Syntax error
Syntax errors are also known as the compilation errors as they occurred at the
compilation time, or we can say that the syntax errors are thrown by the compilers.
These errors are mainly occurred due to the mistakes while typing or do not follow the
syntax of the specified programming language. These mistakes are generally made by
beginners only because they are new to the language. These errors can be easily
debugged or corrected.
For example
1. #include <stdio.h>
2. int main()
3. {
4. a = 10;
5. printf("The value of a is : %d", a);
6. return 0;
7. }
In the above output, we observe that the code throws the error that 'a' is undeclared.
This error is nothing but the syntax error only.
There can be another possibility in which the syntax error can exist, i.e., if we make
mistakes in the basic construct. Let's understand this scenario through an example.
1. #include <stdio.h>
2. int main()
3. {
4. int a=2;
5. if(.) // syntax error
6.
7. printf("a is greater than 1");
8. return 0;
9. }
In the above code, we put the (.) instead of condition in 'if', so this generates the syntax
error as shown in the below screenshot.
Output
Logical error
The logical error is an error that leads to an undesired output. These errors produce the
incorrect output, but they are error-free, known as logical errors. These types of
mistakes are mainly done by beginners. The occurrence of these errors mainly depends
upon the logical thinking of the developer. If the programmers sound logically good,
then there will be fewer chances of these errors.
Let's understand through an example.
1. #include <stdio.h>
2. int main()
3. {
4. int sum=0; // variable initialization
5. int k=1;
6. for(int i=1;i<=10;i++); // logical error, as we put the semicolon after loop
7. {
8. sum=sum+k;
9. k++;
10. }
11. printf("The value of sum is %d", sum);
12. return 0;
13. }
Output
In the above code, we are trying to print the sum of 10 digits, but we got the wrong
output as we put the semicolon (;) after the for loop, so the inner statements of the for
loop will not execute. This produces the wrong output.
Source Code, Object Code and Executable Code
Object code is
Source code is generated by generated by compiler
01. human or programmer. or other translator.
Object code is
Source code is written in plain translated code of
text by using some high level source code. It is in
03. programming language. binary format.
Performance of object
code is more than
Performance of source code is source code as it is
less than object code as it is more close towards
11. less close towards machine. machine.
What is a compilation?
The compilation is a process of converting the source code into object code. It is done
with the help of the compiler. The compiler checks the source code for the syntactical or
structural errors, and if the source code is error-free, then it generates the object code.
The c compilation process converts the source code taken as input into the object code
or machine code. The compilation process can be divided into four steps, i.e., Pre-
processing, Compiling, Assembling, and Linking.
The preprocessor takes the source code as an input, and it removes all the comments
from the source code. The preprocessor takes the preprocessor directive and interprets
it. For example, if <stdio.h>, the directive is available in the program, then the
preprocessor interprets the directive and replace this directive with the content of
the 'stdio.h' file.
The following are the phases through which our program passes before being
transformed into an executable form:
o Preprocessor
o Compiler
o Assembler
o Linker
Preprocessor
The source code is the code which is written in a text editor and the source code file is
given an extension ".c". This source code is first passed to the preprocessor, and then
the preprocessor expands this code. After expanding the code, the expanded code is
passed to the compiler.
Compiler
The code which is expanded by the preprocessor is passed to the compiler. The
compiler converts this code into assembly code. Or we can say that the C compiler
converts the pre-processed code into assembly code.
Assembler
The assembly code is converted into object code by using an
assembler. The name of the object file generated by the
assembler is the same as the source file. The extension of the
object file in DOS is '.obj,' and in UNIX, the extension is 'o'.
If the name of the source file is 'hello.c', then the name of
the object file would be 'hello.obj'.
Linker
Mainly, all the programs written in C use library functions.
These library functions are pre-compiled, and the object code of
these library files is stored with '.lib' (or '.a') extension.
The main working of the linker is to combine the object code of
library files with the object code of our program. Sometimes the
situation arises when our program refers to the functions
defined in other files; then linker plays a very important role
in this. It links the object code of these files to our program.
Therefore, we conclude that the job of the linker is to link the
object code of our program with the object code of the library
files and other files. The output of the linker is the
executable file. The name of the executable file is the same as
the source file but differs only in their extensions. In DOS,
the extension of the executable file is '.exe', and in UNIX, the
executable file can be named as 'a.out'. For example, if we are
using printf() function in a program, then the linker adds its
associated code in an output file.
1. #include <stdio.h>
2. int main()
3. {
4. printf("Hello javaTpoint");
5. return 0;
6. }