0% found this document useful (0 votes)
60 views

UNIT-01 Computer Fundamentals

The document provides an overview of computer system components, including memory, processor, and I/O devices, and explains the roles of hardware and software. It details the functions of an operating system, such as memory management and process scheduling, and introduces algorithms and pseudocode as tools for problem-solving. Additionally, it covers programming languages, their classifications, and the role of translators in converting code into machine language.

Uploaded by

mrai48851
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)
60 views

UNIT-01 Computer Fundamentals

The document provides an overview of computer system components, including memory, processor, and I/O devices, and explains the roles of hardware and software. It details the functions of an operating system, such as memory management and process scheduling, and introduces algorithms and pseudocode as tools for problem-solving. Additionally, it covers programming languages, their classifications, and the role of translators in converting code into machine language.

Uploaded by

mrai48851
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/ 56

Introduction to components of a computer system: Memory,

Processor, I/O Devices

Pre-requisite keywords:
• Program:A program can be defined as a collection
of instructions written to perform any user`s
defined task in computer.
• Data:Any raw facts
• Information: Collection of data that has some
meaning (Meaningful Data)
• Hardware:Computer hardware is a collective term
used to describe any of the physical components
of an analog or digital computer.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Pre-requisite keywords:
• Software:Software commands the hardware what to do & how
to do it. Together, the hardware & software form the computer
system. This software is further classified as system software &
application software.
• 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.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Introduction to computer:
Right from its inception, to the present day, all computer system
(irrespective of their shape & size) perform the following 5 basic
operations. It converts the raw input data into information, which is
useful to the users.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Components of computer:
Input: It is the process of entering data & instructions
to the computer system.
Storing: The data & instructions are stored for either
initial or additional processing, as & when required.
Processing: It requires performing arithmetic or logical
operation on the saved data to convert it into useful
information.
Output: 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.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Input Unit:
Input device: The input device is the means through
which data and instructions enter in a computer.
• Keyboard
• Mouse
• Microphone
• Joysticks
• Scanner
• Barcode Reader
• Camera
• Compact Disc (CD),etc.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Memory/Storage Unit: The storage unit is designed to
save the initial data, the intermediate result & the final
result.
They are of two types:
• Primary storage: The primary storage, also called as the
main memory, holds the data when the computer is
currently on. It is volatile in nature. Ex: RAM

• Secondary storage: The secondary storage, also called as


the auxiliary storage, handles the storage limitation & the
volatile nature of the primary memory.
• Magnetic Disk
• Floppy Disk
• Hard Disk
• CD/DVD
Introduction to components of a computer system: Memory,
Processor, I/O Devices
Processing: (CPU+ALU)
• Together the Control Unit & the Arithmetic Logic Unit are
called as the Central Processing Unit (CPU). The CPU is the
brain of the computer. The CPU is responsible for activating
& controlling the operation of other units of the computer
system.
• The actual execution of the instructions (arithmetic or
logical operations) takes place over here. The data &
instructions stored in the primary storage are transferred as
& when required. No processing is done in the primary
storage. 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.
Introduction to components of a computer system: Memory,
Processor, I/O Devices
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.
Output devices:
• Monitor
• CD
• Printer
• Speaker
• Headphones
Introduction to components of a computer system: Memory,
Processor, I/O Devices

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.
Introduction to components of a computer system: Memory,
Processor, I/O Devices

Memory Organization in Computer :


A memory unit is the collection of storage units or
devices together. The memory unit stores the
binary information in the form of bits. Generally,
memory/storage is classified into 2 categories:
– Volatile Memory: This loses its data, when power is
switched off. (Ex: RAM)
– Non-Volatile Memory: This is a permanent storage
and does not lose any data when power is switched
off. (Ex: ROM)
Operating System
Pre-requisite keywords
• Process: A program in execution is known as process.
• File: A file can be understood as a container in a computer
system for storing information/data.
• Network: Computer network can be defined as the group
of computers connected for the purpose of communicating
data from one computer to other.
• Resources: In computer, resources can be CPU, RAM,
Input/Output devices, Processor.
• Multiprogramming: A computer running more than one
program at a time (like running Excel and Firefox
simultaneously).
• Bug: Bug is a logical error which generate wrong output.
• Debugging: Identification of bug is debugging.
Operating System
Definition of OS:
An operating system (OS) is a collection of software
that manages computer hardware resources and
provides common services for computer programs.
Functions of OS:
Following are some of important functions of an
operating System.
– Memory Management
– Processor Management
– Device Management
– File Management
Operating System
Functions of OS:
• Memory Management
Memory management refers to management of
Primary Memory or Main Memory. Main memory
provides a fast storage that can be accessed. An
Operating System does the following activities for
memory management
• Keeps tracks of primary memory.
• In multiprogramming, the OS decides which process will get
memory, when and how much.
• Allocates the memory when a process requests it to do so.
• De-allocates the memory when a process no longer needs it
or has been terminated, directly by the CPU.
Operating System
Functions of OS:
• Processor Management
In multiprogramming environment, the OS
decides which process gets the processor when
and for how much time. This function is called
process scheduling. An Operating System does the
following activities for processor management
– Keeps tracks of processor and status of process.
– Allocates the processor (CPU) to a process.
– De-allocates processor when a process is no longer
required.
Operating System
Functions of OS:
• Device Management
An Operating System manages device
communication via their respective drivers. It
does the following activities for device
management
– Keeps tracks of all devices.
– Decides which process gets the device when and for
how much time.
– Allocates the device in the efficient way.
– De-allocates devices.
Operating System
Functions of OS:
• File Management
A file system is normally organized into directories
for easy navigation and usage. These directories
may contain files and other directions. An
Operating System does the following activities for
file management −
– Keeps track of information, location, uses, status etc.
The collective facilities are often known as file system.
– Decides who gets the resources.
– Allocates the resources.
– De-allocates the resources.
Algorithm and Pseudocode
Algorithm:
It’s an organized logical sequence of the actions or
the approach towards a particular problem. A
programmer implements an algorithm to solve a
problem. Algorithms are expressed using natural
verbal but somewhat technical annotations.
Example: Algorithm to find Whether Number N is Even
or Odd
– Step 1: Read number N,
– Step 2: Set remainder as N modulo 2,
– Step 3: If remainder is equal to 0 then number N is even,
else number N is odd,
– Step 4: Print output.
Algorithm and Pseudocode
Characteristics of algorithm
• Input specified-Input precision requires that you know
what kind of data, how much and what form the data
should be required for algorithm.
• Output specified-Output precision also requires that you
know what kind of data, how much and what form the
output should be (or even if there will be any output at all!)
• Definiteness-Each statement of algorithm should be clear,
well defined and precise in nature.
• Effectiveness-For an algorithm to be effective, it means
that all those steps that are required to get to output MUST
BE DOABLE!
• Finiteness-The algorithm should have sequence of finite
instructions.
Algorithm and Pseudocode
Pseudocode:
Pseudocode is an artificial and informal language that helps
programmers develop algorithms. Pseudocode is a "text-
based" detail (algorithmic) design tool. The rules of
Pseudocode are reasonably straightforward. All statements
showing "dependency" are to be indented. These include
while, do, for, if, switch.
Advantages of Pseudocode:
• Improves the readability of any approach. It’s one of the
best approaches to start implementation of an algorithm.
• Acts as a bridge between the program and the algorithm or
flowchart.
• The main goal of a pseudo code is to explain what exactly
each line of a program should do, hence making the code
construction phase easier for the programmer.
Algorithm and Pseudocode
Can you guess for what purpose the following
pseudocode has been written?
Ex 1:
Step1: If student's grade >= 60
Step2: Print "passed“
Step3: Else Print "failed"
Ex 2:
Step1: Initialize total =0
Step2: Set grade_counter =1
Step3: While (grade_counter<=10)
Step4: Input the next grade
Step5: Add the grade into the total
Step6: Set class_average = total/ten
Step7: Print the class average.
FLOW CHARTS
A flowchart is a type of diagram that represents an
algorithm or process, showing the steps as boxes of
various kinds, and their order by connecting these with
arrows. This diagrammatic representation can give a
step-by-step solution to a given problem.
FLOW CHARTS
Advantages of Using Flowchart: -
• Communication: Flowcharts are better way of
communicating the logic of a system to all concerned.
• Effective analysis: With the help of flowchart, problem
can be analyzed in more effective way.
• Proper documentation: Program flowcharts serve as a
good program documentation, which is needed for
various purposes.
• Efficient Program Maintenance: It helps the programmer
to put efforts more efficiently on that part
FLOW CHARTS
Disadvantages of Using Flowchart:
• Complex logic: - Sometimes, the program logic is quite
complicated. In that case, flowchart becomes complex
and clumsy.
• Alterations and Modifications: - If alterations are
required the flowchart may require re-drawing
completely.
• Reproduction: - As the flowchart symbols cannot be
typed, reproduction of flowchart becomes a problem.
The essentials of what is done can easily be lost in the
technical details of how it is done.
SOME EXAMPLES OF FLOW CHART AND
ALGORITHM
Example: Calculate the Interest of a Bank Deposit
Algorithm:
START
Step 1: Read amount,
Step 2: Read years, INPUT AMOUNT,YEARS AND
Step 3: Read rate, RATE
Step 4: Calculate the interest
Interest =Amount*Years*Rate/100 COMPUTE
Step 5: Print interest, Interest =Amount*Years*Rate/100

OUTPUT
INTEREST

END
SOME EXAMPLES OF FLOW CHART AND
ALGORITHM
Example: Determine and Output Whether Number N is
Even or Odd

Step 1: Read number N,


Step 2: Set remainder as N
modulo 2,
Step 3: If remainder is equal
to 0 then number N is
even, else number N is
odd,
Step 4: Print output
SOME EXAMPLES OF FLOW CHART AND
ALGORITHM
Example: Determine Whether a Student Passed the Exam
or Not:

Step 1: Input grades of 4


courses M1, M2, M3 and
M4,
Step 2: Calculate the average
grade
“Grade=(M1+M2+M3+M4)/4"
Step 3: If the average grade is
less than 60, print "FAIL",
else print "PASS".
Programming Basics
Computer Language:
A language that is acceptable to a computer system is
called a computer language or programming language.
Computer languages are broadly classified as:
a. Low Level Language:
The term low level highlights the fact that it is closer to a
language which the machine understands. The low level
languages are classified as:
– Machine Language: This is the language (in the form of 0’s and 1’s,
called binary numbers) understood directly by the computer.
– Assembly Language: This is the language where the machine
codes comprising of 0’sand 1’s are substituted by symbolic codes
(called mnemonics) to improve their understanding.
Programming Basics
Computer Language:
b. High Level Language:
High level languages are computer independent and
programming becomes quite easy and simple. Various high
level languages are : BASIC, COBOL, FORTRAN, C,C++, JAVA,
Python etc
Programming Basics
Programming Language Translators
A translator is a programming language processor that
modifies a computer program from one language to
another. It takes a program written in the source
program and modifies it into a machine program. It can
find and detect the error during translation.
There are the various tools to achieve this purpose:
• Compiler
• Interpreter
• Assembler
Programming Basics
Programming Language Translators
• Compiler: The software that reads a program written in
high level language and translates it into an equivalent
program in machine language is called as compiler.
• Interpreter: It also executes instructions written in a
high level language but it takes one statement,
translates it, executes it & then again takes the next
statement.
• Assembler: The software that reads a program written
in assembly language and translates it into an
equivalent program in machine language is called as
assembler.
LANGUAGE PROCESSING SYSTEM
Source program

PREPROCESSOR
Modified source
program

COMPILER
Target
assembly
language
ASSEMBLER
Relocatable
machine
code
Library files
Linker/Loader relocatable
object files
Target machine
code
C PROGRAMMING
Before we study the basic building blocks of the C
programming language, let us look at a bare
minimum C program structure so that we can take it
as a reference in the upcoming chapters.
Hello World Example
A “C” program basically consists of the following
parts − #include <stdio.h>
•Preprocessor Commands int main()
•Functions {
/* my first program in C */
•Variables
printf("Hello, World! \n");
•Statements & Expressions return 0;
•Comments }
C PROGRAMMING (BASIC SYNTAX)
Basic Syntax:
Tokens in C
A C program consists of various tokens and a token is either a
keyword, an identifier, a constant, a string literal, Operators and
special symbols. For example, the following C statement consists of
five tokens −

The individual tokens are −


printf("Hello, World! \n");
1. printf
2. (
3. "Hello, World! \n“
4. )
5. ;
C PROGRAMMING (BASIC SYNTAX)
Semicolons:
In a C program, the semicolon is a statement terminator.

printf("Hello, World! \n");


return 0;

Comments:
Comments are like helping text in your C program and they are
ignored by the compiler. They start with /* and terminate with the
characters */ as shown below −

/* my first program in C */
C PROGRAMMING (BASIC SYNTAX)
Identifiers:
A C identifier is a name used to identify a variable, function, or any
other user-defined item.
An identifier starts with a letter A to Z, a to z, or an underscore '_'
followed by zero or more letters, underscores, and digits (0 to 9).
C does not allow punctuation characters such as @, $, and %
within identifiers.
C is a case-sensitive programming language.
Thus, Sum and sum are two different identifiers in C. Here are
some examples of valid identifiers −
Area, sum, stu_add, _add, sum_1, sum1;
Invalid identifiers:
12sum, #asdj, sum@123
C PROGRAMMING (BASIC SYNTAX)
Keywords:
The following list shows the reserved words in C. These reserved
words may not be used as constants or variables or any other
identifier names.
C PROGRAMMING (BASIC SYNTAX)
Whitespace:
A line containing only whitespace, possibly with a comment, is
known as a blank line, and a C compiler totally ignores it.
int a, float b;

int area = length * breadth;


no whitespace characters are necessary between area and =, or
between = and length, although you are free to include some if
you wish to increase readability.
C PROGRAMMING (DATA TYPES)
Data Types:
Data types in c refer to an extensive system used for declaring
variables or functions of different types. The type of a variable
determines how much space it occupies in storage and how the bit
pattern stored is interpreted.
C PROGRAMMING (DATA TYPES)
Data Types storages:
C PROGRAMMING (ASCII TABLE)
C PROGRAMMING (VARIABLE)
Variable Definition in C
A variable definition tells the compiler where and how much
storage to create for the variable. A variable definition specifies a
data type and contains a list of one or more variables of that type
as follows −
datatype variable_list;
Here, type must be a valid C data type including char, w_char, int,
float, double, bool, or any user-defined object;
and variable_list may consist of one or more identifier names
separated by commas. Some valid declarations are shown here −
int i, j, k;
char c, ch;
float f, salary;
double d;
C PROGRAMMING (VARIABLE)
Declare a variable: #include <stdio.h>
int i; int main ()
{
float j; int a, b;
int c; float f; // Variable declaration:
Initialize value to variable:
i=10; a = 10; b = 20; /* actual initialization */
j=10.25
c = a + b;
c=‘a’; printf("value of c : %d \n", c);

x = 70.0/3.0;
printf("value of x : %f \n", x);
return 0;
}
C PROGRAMMING (ERRORS)
Errors:
Error is an illegal operation performed by the user which results in
abnormal working of the program.
Types of Error:
There are 5 types of error in C:
•Syntax Errors
•Runtime Errors
•Logical Errors
•Linked Errors
•Semantic Errors
C PROGRAMMING (ERRORS)
Types of Error:
•Syntax Errors
These are also referred to as compile-time errors. These errors
have occurred when the rule of C writing techniques or syntaxes
has been broken.

int main() int main()


{ {
printf(“Hello”) printf(“Hello”);
return 0; return 0;
} }

INCORRECT CORRECT
C PROGRAMMING (ERRORS)
Types of Error:
•Runtime Error
This type of error occurs while the program is running.
Because this is not a compilation error, the compilation will
be completed successfully.
C PROGRAMMING (ERRORS)
Types of Error:
•Logical Error
Logical errors are those errors in which we think that our code is correct,
the code compiles without any error and gives no error while it is running,
but the output we get is different from the output we expected.

int main() int main()


{ {
int a=7,b; int a=7,b;
b=7/0; b=7/0;
printf(“%d”,b); printf(“%d”,b);
return 0; return 0;
} }

INCORRECT
C PROGRAMMING (ERRORS)
Types of Error:
•Semantic Error
Errors that occur because the compiler is unable to
understand the written code are called Semantic Errors.

#include <stdio.h>
void main()
{
int a, b, c;
a * b = c; // generate a semantic error
}

Output: error: lvalue required as left operand of assignment


C PROGRAMMING (ERRORS)
Types of Error:
•Linker Error
Linker errors are the errors encountered when the
executable file of the code can not be generated even though
the code gets compiled successfully.

void Main()
{
int var = 10;
printf("%d", var);
}

Output: undefined reference to `main'


C PROGRAMMING
Storage classes:
A storage class defines the scope (visibility) and life-time of
variables and/or functions within a C Program. We have four
different storage classes in a C program −
•auto : It is a default storage class.
•extern: It is a global variable.
•static: It is a local variable which is capable of returning a value
even when control is transferred to the function call.
•register: It is a variable which is stored inside a Register.
C PROGRAMMING
Storage classes:
AUTO STORAGE CLASS:
•The variables defined using auto storage class are called as local
variables.
•Auto stands for automatic storage class.
•A variable is in auto storage class by default if it is not explicitly
specified.
•The scope of an auto variable is limited with the particular block
only.
•Once the control goes out of the block, the access is destroyed.
•This means only the block in which the auto variable is declared
can access it.
•A keyword auto is used to define an auto storage class.
Ex: auto int age;

By default, an auto variable contains a garbage value.


C PROGRAMMING
Storage classes:
EXTERN STORAGE CLASS:
•Extern stands for external storage class.
•Extern storage class is used when we have global functions
or variables which are shared between two or more files.
•Keyword extern is used to declaring a global variable or
function in another file to provide the reference of variable or
function which have been already defined in the original file.
•The variables defined using an extern keyword are called
as global variables. These variables are accessible
throughout the program.
Ex: extern int a=5;

Notice that the extern variable cannot be initialized it has


already been defined in the original file.
C PROGRAMMING
Storage classes:
STATIC STORAGE CLASS:
•The static variables are used within function/ file as local
static variables.
•They can also be used as a global variable.
•Static local variable is a local variable that retains and stores
its value between function calls or block and remains visible
only to the function or block in which it is defined.
•Static global variables are global variables visible only to
the file in which it is declared.
Example: static int count = 10;
C PROGRAMMING
Storage classes:
REGISTER STORAGE CLASS:
•You can use the register storage class when you want to store local
variables within functions or blocks in CPU registers instead of RAM to
have quick access to these variables. For example, “counters” are a good
candidate to be stored in the register.
•The keyword register is used to declare a register storage class.
•The variable is limited to the particular block.
•The only difference is that the variables declared using register storage
class are stored inside CPU registers instead of a memory.
•Register has faster access than that of the main memory.

Ex: register int a=5;


C PROGRAMMING
Type casting/Type Conversion:
Type casting /type conversion is a way to convert a variable from
one data type to another data type.
For example, if you want to store a long value into a simple integer
then you can typecast long to int.
#include<stdio.h>
int main ()
{
float x;
x = (float) 7/5; // Type conversion
printf(“%f”,x);
}

Output: 1.400000
C PROGRAMMING
Types of Type casting/Type Conversion:
Types of typecasting in C

•Implicit Conversion :
Implicit conversions do not require any operator for converted.
They are automatically performed when a value is copied to a
compatible type in the program.

•Explicit Conversion:
In C language, Many conversions, especially those that imply a
different interpretation of the value, require an explicit conversion.
C PROGRAMMING
Types of Type casting/Type Conversion:
Ex: Implicit Ex: Explicit
#include<stdio.h> #include<stdio.h>
#include<conio.h> #include<conio.h>
void main() void main()
{ {
int i=20; double p; int i=20, float p;
clrscr(); clrscr();
p=i; // Implicit Conversion p=(float)i; // Explicit Conversion
printf(“implicit value is %d”, p); printf(“Explicit value is %f”, p);
getch(); getch();
} }

Output: implicit value is 20. Output: Explicit value is 20.

You might also like