0% found this document useful (0 votes)
2 views19 pages

Unit1 Notes

The document provides an introduction to computer systems, detailing the components and functions of a computer, including input, processing, storage, and output. It explains the characteristics of computers such as speed, accuracy, and versatility, and discusses the role of software and operating systems in facilitating user interaction. Additionally, it covers programming languages, algorithms, flowcharts, and the processes involved in compiling and executing code.

Uploaded by

v7s7knyzg9
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)
2 views19 pages

Unit1 Notes

The document provides an introduction to computer systems, detailing the components and functions of a computer, including input, processing, storage, and output. It explains the characteristics of computers such as speed, accuracy, and versatility, and discusses the role of software and operating systems in facilitating user interaction. Additionally, it covers programming languages, algorithms, flowcharts, and the processes involved in compiling and executing code.

Uploaded by

v7s7knyzg9
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

Introduction to Computer System

A computer is an electronic device that accepts data as input, processes it according to a set
of instructions (called a program), stores it, and produces meaningful information as output.
Computers can perform calculations, process large amounts of data, and execute tasks
quickly and accurately.

In simple words,

Computer = Input + Processing + Storage + Output

Computers are used in almost every field such as education, healthcare, banking, business,
entertainment, communication, and scientific research.

Characteristics of a Computer
A computer has several important characteristics that make it useful in everyday life.

1. Speed

A computer performs millions or even billions of operations per second. It completes tasks
much faster than humans.

Example: Calculating the marks of 5,000 students within a few seconds.

2. Accuracy

A computer produces highly accurate results if the input data and instructions are correct.

Example: Calculating employee salaries without mathematical mistakes.

Note: Incorrect input leads to incorrect output (Garbage In, Garbage Out - GIGO).

3. Storage Capacity

Computers can store a large amount of data such as documents, images, videos, and
databases.

Example: A 1 TB hard disk can store thousands of movies and millions of documents.

4. Automation

Once a program is started, a computer performs all tasks automatically without continuous
human intervention.

Example: Automatic generation of electricity bills.


5. Diligence

Unlike humans, computers do not become tired or lose concentration even after performing
repetitive tasks for long periods.

6. Versatility

A computer can perform different types of tasks using different software.

Examples:
• Typing documents

• Playing games

• Programming

• Watching videos

• Internet browsing

7. Reliability
Computers provide consistent and dependable results when operated correctly.

Basic Structure of Computers

A computer consists of five functionally independent main parts input, memory, arithmetic
logic unit (ALU), output and control unit.
1. Input Unit:- Computer accepts encoded information through input unit. The standard input
device is a keyboard. Whenever a key is pressed, keyboard controller sends the code to
CPU/Memory. Examples include Mouse, Joystick, Tracker ball, Light pen, Digitizer, Scanner
etc.

2. Processor (CPU)

The Central Processing Unit (CPU) is known as the brain of the computer because it
performs all calculations, processes instructions, and controls the operation of all hardware
components.

Whenever a program is executed, the CPU fetches instructions from memory, processes them,
and produces the required output.

Main Parts of CPU: -

Arithmetic logic unit (ALU):- Stands for "Arithmetic Logic Unit." An ALU is an
integrated circuit within a CPU or GPU that performs arithmetic and logic operations.
Arithmetic instructions include addition, subtraction, and shifting operations, while logic
instructions include boolean comparisons, such as AND, OR, XOR, and NOT operations.

The ALU uses operands and code that tells it which operations to perform (opcode) for
input data. After the information is processed by the ALU, it's sent to the computer's
memory.

In some computer processors, the ALU is divided into an AU and LU. The AU performs
the arithmetic operations, and the LU performs the logical operations.

Control Unit:- Control unit co-ordinates activities of all units by issuing control signals.
Control signals issued by control unit govern the data transfers and then appropriate
operations take place. Control unit interprets or decides the operation/action to be
performed.
It effectively is the nerve center that sends signals to other units and senses their states.
The actual timing signals that govern the transfer of data between input unit, processor,
memory and output unit are generated by the control unit.

3. Registers

Registers are very small and very fast memory locations inside the CPU.

They temporarily store:

• Instructions

• Data

• Memory addresses

Registers are much faster than RAM.

3. Memory Unit: Memory unit stores the program instructions (Code), data and results of
computations etc. Memory unit is classified as: • Primary /Main Memory • Secondary
/Auxiliary Memory

➢ Primary Memory :- It is a semiconductor memory that provides access at high speed


Run time program instructions and operands are stored in the main memory. Main
memory is classified again as ROM and RAM. ROM holds system programs and
firmware routines such as BIOS, POST, I/O Drivers that are essential to manage the
hardware of a computer. RAM is termed as Read/Write memory or user memory that
holds run time program instruction and data. While primary storage is essential, it is
volatile in nature and expensive
➢ Secondary memory: - Is used where large amounts of data & programs have to be
stored, particularly information that is accessed infrequently. Examples: - Magnetic
disks & tapes, optical disks (ie CD-ROM’s), floppies etc.

4. Output unit:-

These actually are the counterparts of input unit. Its basic function is to send the processed
results to the outside world. Examples :- Printer, speakers, monitor etc.

The operation of a computer can be summarized as follows: ‹ The computer accepts


information in the form of programs and data through an input unit and stores it in the memory
‹ Information stored in the memory is fetched, under program control, into an ALU, where it
is processed ‹ Processed information leaves the computer through an output unit ‹ All activities
inside the machine are directed by the control unit.
Where is a program stored and executed in computers:-

Whenever we save a program (anything) into a file (any kind of file, say ‘add.c’), it
automatically gets stored in the secondary storage i.e. the hard disk. The Operating System’s
kernel (kernel’s File management system) does it for us.

When we run a program, it is loaded into the main/primary memory of the computer called
RAM (the entire program is transferred to the RAM, by a small program called the loader
(which often comes with the compiler i.e. is a part of the compiler).

Computer System

A computer system is a combination of hardware, software, data, users, and procedures


that work together to perform computing tasks efficiently.

A computer alone cannot perform useful work. It requires software, user instructions, and
data to function properly.

Hardware - Hardware refers to the physical parts of a computer that can be seen and
touched.

Examples

• Keyboard

• Mouse

• Monitor

• CPU

• Printer

• Hard Disk

Software- Software is a collection of programs and instructions that tell the hardware what to
do.

Examples

• Windows

• Linux

• MS Word

• Google Chrome
What is an Operating System?

An Operating System (OS) is software that acts as an interface between computer hardware
components and the user. Every computer system must have at least one operating system to
run other programs. Applications like Browsers, MS Office, Notepad Games, etc., need some
environment to run and perform its tasks.

The OS helps us to communicate with the computer without knowing how to speak the
computer’s language. It is not possible for the user to use any computer or mobile device
without having an operating system.

Functions of Operating System

1. Process Management

Manages the execution of programs.

2. Memory Management

Allocates and deallocates memory to programs.

3. File Management

Creates, deletes, stores, and manages files and folders.

4. Device Management

Controls input and output devices such as printers and keyboards.

5. Security

Protects the computer using passwords and access control.


6. User Interface

Allows users to interact with the computer through Graphical User Interface (GUI) or
Command Line Interface (CLI).

Source and Object Code:-


The programs are written mostly in high level languages like Java, C++, and Python etc. and
are called source code.

This source code cannot be executed directly by the computer and must be converted into
machine language to be executed.

Hence, a special translator system software is used to translate the program written in high-
level language into machine code is called Language Processor and the program after
translated into machine code is called object program / object code.

Compiler –
The language processor that reads the complete source program written in high level
language as a whole in one go and translates it into an equivalent program in machine
language is called as a Compiler.
Example: C, C++, C# and Java compilers.

In a compiler, the source code is translated to object code successfully if it is free of errors.

The compiler specifies the errors at the end of compilation with line numbers when there are
any errors in the source code.

The errors must be removed before the compiler can successfully recompile the source code
again.
Types of Programming Languages:-

Some programming languages provide less or no abstraction while some provide higher
abstraction. Based on the levels of abstraction, they can be classified into two categories:

1. Low-level language
2. High-level language

1. Low-level language
The low-level language is a programming language that provides no abstraction from
the hardware, and it is represented in 0 or 1 forms, which are the machine instructions.
The languages that come under this category are the Machine level language and
Assembly language.

Machine Language

Every device has a processor responsible for all the functions performed by that device.
These processors use machine language to “talk” to the different parts of the device, for
example, giving and receiving instructions to/from the keyboard and mouse. As we touched
on earlier, machine language is written in binary form (0s and 1s) in a hexadecimal format
and each family of processors has its own version. Although processors speak machine
language fluently, it’s extremely challenging for a human to read or use — and virtually
impossible for someone to do so quickly. That’s where assembly language comes in.

Assembly Languages

In general, assembly language is a bit more user-friendly than machine-level language but
more difficult than high-level language. It uses short codes to instruct the machine to perform
certain operations. Whereas machine language uses 0s and 1s to instruct the computer,
assembly language uses mnemonics that are easier for humans to work with.

As we already know, processors only speak machine language. So, to translate the machine
code into assembly language and vice versa, a program called an assembler is required.

[Link]-level Languages

Higher-level computer languages are processor agnostic and are designed to give instructions
in a human-readable manner. Programs written in higher-level languages can be read by
humans (as long as they know the language) and are concise and easy to operate. A compiler
is required to translate a high-level language into a low-level language.

Algorithm:-

In computer programming terms, an algorithm is a set of well-defined instructions to solve a


particular problem. It takes a set of input(s) and produces the desired output.

OR

Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a


certain order to get the desired output.

Algorithms are generally created independent of underlying languages, i.e. an algorithm can
be implemented in more than one programming language.

Qualities of a Good Algorithm:-

➢ Input and output should be defined precisely.


➢ Each step in the algorithm should be clear and unambiguous.
➢ Algorithms should be most effective among many different ways to solve a problem.
➢ An algorithm shouldn't include computer code. Instead, the algorithm should be
written in such a way that it can be used in different programming languages.

Properties of Algorithm:

➢ It should terminate after a finite time.


➢ It should produce at least one output.
➢ It should be deterministic means giving the same output for the same input
case.
➢ Every step in the algorithm must be effective i.e. every step should do some
work.

Algorithm 1: Add two numbers entered by the user


Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
Algorithm 2: Find the largest number among three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
If a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop

Definition of Flow chart

A flowchart is the graphical or pictorial representation of an algorithm with the help of


different symbols, shapes, and arrows to demonstrate a process or a program. With
algorithms, we can easily understand a program. The main purpose of using a flowchart is to
analyze different methods. Several standard symbols are applied in a flowchart:

Terminal Box - Start / End

Input / Output

Process / Instruction

Decision

Connector / Arrow
➢ The symbols above represent different parts of a flowchart. The process in a flowchart
can be expressed through boxes and arrows with different sizes and colors.
➢ In C programming, flowcharts are often used to represent algorithms or programs.
They show the connections, flow of information, and processes within an algorithm or
a program.
➢ Programmers use flowcharts in the program-planning, or the debugging process, often
to solve problems, even in complex programs.
➢ A program might contain many flows of logic and processes, so flowcharts, using
natural language and symbols, can also help normal, non-technical people understand
how the program works

Input Number and Check If They Are Odd Or Even :-

Pseudo Code
➢ Pseudo code in C can be referred to as a simple way or method to write programming
code or program algorithm in English. A pseudocode is an informal representation of
an algorithm which is free from the programming language.
➢ It is not an actual programming language; it is just a form of representing the basic
concept or logic behind the actual code.
➢ The pseudo code cannot be compiled and executed as the conversion of this code into
an executable code is not possible. It is just a simple syntax written in English
language in order to explain complex programming concepts or short but simple code
written for algorithms before they are converted into a targeted or specific program
code.
➢ A pseudocode is written in order to simplify the complex programming
instructions/code or algorithms into plain english language so that it can be
understood by anyone. It is intended for human reading.
➢ It is a text based detailed design tool.
➢ It is an intermediary between algorithm & implemented program.

Algorithm to Find the Sum of Natural Numbers.

Step 1: start

Step 2: declare and initialize

n, sum = 0 and i

Step 3: Input number n

Step 4: for i=1 to i<=n

Step 5: sum = sum + i

Step 6: i++ [increment i value by one]


Step 7: print sum

Step 8: stop

Let’s implement pseudo-code from the above algorithm.

➢ Start program
➢ Declare variables n, sum = 0 and i
➢ Enter the number for n
➢ For i=1 to i<=n
➢ Perform operation sum = sum + i
➢ Increment i value by one
➢ Print sum
➢ End program

Linker

• The main function of the linker is to generate executable files.


• The linker takes the input as the object code which would be generated by a
compiler/assembler.
• The process of linking can be understood as a method to combine different snippets of
code in order to obtain executable code.

Loader

• The main function of a loader is to load executable files to the main memory.
• It takes the executable files (generated by linker) as its input.
• It can be understood as a process of loading the executable codes into main memory
where it is execute further.
C Variables :-
Variable is like a container (storage space) with a name in which we can store data. When we
create a variable in a C program, the C compiler allocates a storage space, depending upon
the datatype of the variable and then that storage space is given a name which is the variable
name.

Once a variable is created, we can store value in it. We can change the value stored in a
variable as many times as we want, but we should make sure we store the correct data type
value.

Syntax for using Variable:

Here is how you can create or declare a new variable in the C language:-

data_type var_name;

int marks;

Here, marks is the name of the variable, and it can store values of int type.

Once we have declared or created the variable, then we can assign a value to it. This is
called variable definition.
// variable declaration

int marks;

// variable definition

marks = 10;

We can do declaration and definition in a single step too, like this (recommended).

int marks = 10;

We can change the value of the variable, whenever we want. But make sure the value is of
correct data type.

// variable defined

int marks = 10;

// assign a new value

marks = 33;

Datatype of the Variable

A variable in C language must be given a type, which defines what type of data can be stored
in the variable. If we do not provide any datatype, then the C compiler will give compile-
time error or syntax error.
The datatype can be char, int, float, double, or short int, long int, etc. data type along with
modifiers.

Rules to name a Variable

When you create a variable, you should always give a meaningful name to the
variable. And follow the below rules for naming the variable:

➢ Variable name must not start with a digit.


➢ The variable name can consist of alphabets, digits, and special symbols like
underscore _.
➢ Blank or spaces are not allowed in the variable name.
➢ Keywords are not allowed as a variable name.
➢ Upper and lower case names are treated as different, as C is case-sensitive, so it is
suggested to keep the variable names in lower case.

Format Specifiers:-

➢ Format specifiers are used together with the printf() function to tell the compiler what
type of data the variable is storing. It is basically a placeholder for the variable value.
➢ A format specifier starts with a percentage sign %, followed by a character.

For example, to output the value of an int variable, you must use the format specifier %d or
%i surrounded by double quotes, inside the printf() function:

Example:-

int myNum = 15;

printf("%d", myNum); // Outputs 15

Data Types Memory Size Range

char 1 byte −128 to 127

signed char 1 byte −128 to 127

unsigned char 1 byte 0 to 255

short 2 byte −32,768 to 32,767

signed short 2 byte −32,768 to 32,767


unsigned short 2 byte 0 to 65,535

int 2 byte −32,768 to 32,767

signed int 2 byte −32,768 to 32,767

unsigned int 2 byte 0 to 65,535

short int 2 byte −32,768 to 32,767

signed short int 2 byte −32,768 to 32,767

unsigned short int 2 byte 0 to 65,535

long int 4 byte -2,147,483,648 to 2,147,483,647

signed long int 4 byte -2,147,483,648 to 2,147,483,647

unsigned long int 4 byte 0 to 4,294,967,295

float 4 byte

double 8 byte

long double 10 byte

Object and executable code in C Language

Source code is the C program that you write in your editor and save with a ‘.C ‘extension
which is un-compiled (when written for the first time or whenever a change is made in it and
saved)

Object code is the output of a compiler after it processes the source code. The object code is
usually a machine code, also called a machine language, which can be understood directly by
a specific type of CPU (central processing unit), However, some compilers are designed to
convert source code into an assembly language or some other another programming
language. An assembly language is a human-readable notation using the mnemonics
(mnemonicis a symbolic name for a single executable machine language instruction called an
opcode) in the ISA (Instruction Set Architecture) of that particular CPU .
Executable (also called the Binary) is the output of a linker after it processes the object
code. A machine code file can be immediately executable (i.e., runnable as a program), or it
might require linking with other object code files (e.g. libraries) to produce a complete
executable program.

Syntax errors: Errors that occur when you violate the rules of writing C/C++ syntax are
known as syntax errors. This compiler error indicates something that must be fixed before the
code can be compiled. All these errors are detected by compiler and thus are known as
compile-time errors.
Most frequent syntax errors are:
• Missing Parenthesis (})
• Printing the value of variable without declaring it
• Missing semicolon like this:

Logical Errors : On compilation and execution of a program, desired output is not obtained
when certain input values are given. These types of errors which provide incorrect output but
appears to be error free are called logical errors. These are one of the most common errors
done by beginners of programming.
These errors solely depend on the logical thinking of the programmer and are easy to detect if
we follow the line of execution and determine why the program takes that path of execution.

int main()
{
int i = 0;

// logical error : a semicolon after loop


for(i = 0; i < 3; i++);
{
cout << "loop ";
continue;
}
return 0;
}

Run-time Errors : Errors which occur during program execution(run-time) after successful
compilation are called run-time errors. One of the most common run-time error is division by
zero also known as Division error. These types of error are hard to find as the compiler
doesn’t point to the line at which the error occurs.
Data Size Description
Type

int 2 or 4 Stores whole numbers, without decimals


bytes

float 4 bytes Stores fractional numbers, containing one or more decimals. Sufficient
for storing 7 decimal digits

double 8 bytes Stores fractional numbers, containing one or more decimals. Sufficient
for storing 15 decimal digits

char 1 byte Stores a single character/letter/number, or ASCII values

You might also like