0% found this document useful (0 votes)
32 views59 pages

Unit - 1 Introduction

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views59 pages

Unit - 1 Introduction

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 59

Structured Programming using C

Unit - I
Introduction to Computer, Algorithm and Flowchart:
1.1 The Turing Machine architecture, The Von Neumann architecture,

Number system.

1.2 Introduction to operating system components.

1.3 System and application software.

1.4 Basic constructs of Algorithm and flowchart: Sequence, Decision

(Selection) and Repetition.

1.5 Compilation process: Syntax and semantic errors, ASCII.


What is Computer:
• A computer is an electronic machine that processes raw data to give information as output.

• An electronic device that accepts data as input, and transforms it under the influence of a set of
special instructions called Programs, to produce the desired output (referred to as Information).

• A computer has an internal memory, which stores data & instructions temporarily awaiting
processing, and even holds the intermediate result .
Program and Data:-
Program:

• A computer Program is a set of related instructions written in the language of the computer & is
used to make the computer perform a specific task.

• A set of related instructions which specify how the data is to be processed.

• A set of instructions used to guide a computer through a process.

Data :

• Data is a collection of raw facts, figures or instructions that do not have much meaning to the user.

• Data may be in form of numbers, alphabets/letters or symbols, and can be processed to produce
information.
The Turing Machine Architecture :-
• Turing Machine was invented by Alan Turing in 1936.

• It is used to accept Recursive Enumerable Languages (generated by Type-0


Grammar).

• A Turing machine consists of a tape of infinite length on which read and writes
operation can be performed.

• The tape consists of infinite cells on which each cell either contains input symbol
or a special symbol called blank.

• Turing Machine also consists of a head pointer which points to cell currently
being read and it can move in both directions.
The Turing Machine Architecture :
The Turing Machine Architecture :-

• A Turing machine is a mathematical model of computation describing an abstract machine.

• A Turing machine is a general example of a central processing unit (CPU) that controls all data
manipulation done by a computer, with the canonical machine using sequential memory to
store data.

• More specifically, it is a machine (automaton) capable of enumerating some arbitrary subset of


valid strings of an alphabet; these strings are part of a recursively enumerable set.
The Von Neumann Architecture :-

Historically there have been 2 types of Computers:

• Fixed Program Computers – Their function is very specific and they couldn’t be
re-programmed, e.g. Calculators.

• Stored Program Computers – These can be programmed to carry out many


different tasks, applications are stored on them, hence the name.
The Von Neumann Architecture :-
The Von Neumann Architecture :-

• The modern computers are based on a stored-program concept introduced by John


Von Neumann.

• In this stored-program concept, programs and data are stored in a separate storage
unit called memories and are treated the same.

• This novel idea meant that a computer built with this architecture would be much
easier to reprogram.
The Von Neumann Architecture :-

It is also known as ISA (Instruction set architecture) computer and is having three
basic units:

• The Central Processing Unit (CPU)

• The Main Memory Unit

• The Input/output Device


The Von Neumann Architecture :-

• Control Unit:- A control unit (CU) handles all processor control signals. It
directs all input and output flow, fetches code for instructions, and controls how
data moves around the system.

• Arithmetic and Logic Unit (ALU):-

e.g. Addition, Subtraction, and Comparisons. It performs Logical


Operations, Bit Shifting Operations, and Arithmetic operations.
The Von Neumann Architecture :-

Input/output Devices –

• Program or data is read into main memory from the input device or secondary
storage under the control of CPU input instruction.

• Output devices are used to output the information from a computer.


The Von Neumann Architecture :-
Buses – Data is transmitted from one part of a computer to another, connecting all
major internal components to the CPU and memory, by the means of Buses.

• Data Bus: It carries data among the memory unit, the I/O devices, and the
processor.

• Address Bus: It carries the address of data (not the actual data) between memory
and processor.

• Control Bus: It carries control commands from the CPU (and status signals from
other devices) in order to control and coordinate all the activities within the
computer.
Number Systems :-

Based on the base value and the number of allowed digits, number systems are of
many types. The four common types of Number System are:

• Decimal Number System ( Number 0 to 9)


• Binary Number System ( 0 and 1)
• Octal Number System (0 to 7)
• Hexadecimal Number System (0 to 9 and A to F)
Number Systems :-
Number Systems :-

1. Decimal Number System: - Number system with base value 10 is termed as


Decimal number system. It uses 10 digits i.e. 0-9 for the creation of numbers.
Here, each digit in the number is at a specific place with place value a product
of different powers of 10.

•For example: 10285 has place values as


(1 × 104) + (0 × 103) + (2 × 102) + (8 × 101) + (5 × 100)
1 × 10000 + 0 × 1000 + 2 × 100 + 8 × 10 + 5 × 1

10000 + 0 + 200 + 80 + 5

10285
Number Systems :-
2. Binary Number System: -
• Number System with base value 2 is termed as Binary number system. It uses 2 digits i.e. 0 and 1
for the creation of numbers.

• The numbers formed using these two digits are termed as Binary Numbers.

• Binary number system is very useful in electronic devices and computer systems because it can
be easily performed using just two states ON and OFF i.e. 0 and 1.

• Decimal Numbers 0-9 are represented in binary as: 0, 1, 10, 11, 100, 101, 110, 111, 1000, and
1001
Examples:
• 14 can be written as 1110
• 19 can be written as 10011
• 50 can be written as 110010
Number Systems :-

2. Binary Number System: -


Number Systems :-
3. Octal Number System:-

• Octal Number System is one in which the base value is 8.

• It uses 8 digits i.e. 0-7 for creation of Octal Numbers.

• Octal Numbers can be converted to Decimal value by multiplying each digit with the
place value and then adding the result.

• Here the place values are 80, 81, and 82. Octal Numbers are useful for the representation of
UTF8 Numbers.
Example:
•(135)10 can be written as (207)8

•(215)10 can be written as (327)8


Number Systems :-

4. Hexadecimal Number System: -


• Number System with base value 16 is termed as Hexadecimal Number System.

• It uses 16 digits for the creation of its numbers.

• Digits from 0-9 are taken like the digits in the decimal number system but the digits from 10-15
are represented as A-F i.e. 10 is represented as A, 11 as B, 12 as C, 13 as D, 14 as E, and 15 as F.

• Hexadecimal Numbers are useful for handling memory address locations

Examples:
•(255)10 can be written as (FF)16

•(1096)10 can be written as (448)16

•(4090)10 can be written as (FFA)16


Components of Operating System :-

•An operating system is a large and complex system that can only be created by partitioning into
small parts.

•These pieces should be a well-defined part of the system, carefully defining inputs, outputs, and
functions.

•Although Windows, Mac, UNIX, Linux, and other OS do not have the same structure, most
operating systems share similar OS system components, such as file, memory, process, I/O device
management.
Components of Operating System :-

• Operating system components help you get the correct computing by detecting
CPU and memory hardware errors.
Components of Operating System :-
Process Management
 The process management component is a procedure for managing many processes running
simultaneously on the operating system.
 Every running software application program has one or more processes associated with them.
 Process management keeps processes running efficiently.
 It also uses memory allocated to them and shutting them down when needed.
 The execution of a process must be sequential so, at least one instruction should be executed on
behalf of the process.
Components of Operating System :-
Process Management

Functions of process management


Functions of process management
o Process creation and deletion. o Synchronization process

o Suspension and resumption. o Communication process


Components of Operating System :-
File Management

• A file is a set of related information defined by its creator. It commonly represents programs (both
source and object forms) and data. Data files can be alphabetic, numeric, or alphanumeric.

Function of file management


o File and directory creation and
deletion.
o For manipulating files and
directories.
o Mapping files onto secondary
storage.

o Backup files on stable storage


media.
Components of Operating System :-
Network Management
• Network management is the process of administering and managing computer networks.

Functions of Network management


o A distributed system also offers the user access to
the various resources the network shares.

o It helps to access shared resources that help


computation to speed up or offers data availability
and reliability.
Components of Operating System :-
Main Memory management :-

•Main memory is a large array of storage or bytes, which has an address. The memory management
process is conducted by using a sequence of reads or writes of specific memory addresses.

•It should be mapped to absolute addresses and loaded inside the memory to execute a program.

•The selection of a memory management method depends on several factors. (that is the hardware
support and the algorithm).

•Main memory offers fast storage that can be accessed directly by the CPU.
Components of Operating System :-

Functions of Memory management

o It helps you to keep track of primary memory.

o Determine what part of it are in use by whom,


what part is not in use.

o In a multiprogramming system, the OS decides


which process will get memory and how much.

o Allocates the memory when a process requests.

o It also de-allocates the memory when a process no


longer requires or has been terminated.
Components of Operating System :-

• Secondary-Storage Management:-
• Main memory of the computer is very small to store all data and programs permanently. So the
computer system offers secondary storage to back up the main memory.

Functions of Secondary storage


management
o Storage allocation

o Free space management

o Disk scheduling
Components of Operating System :-
I/O Device Management :-

Device management in an operating system controls the Input/output devices like disk,
microphone, keyboard, printer, magnetic tape, USB ports, camcorder, scanner, other accessories,
and supporting units.

• A process may require various resources, if resources


are available, they could be allocated, and control
returned to the CPU.

• Otherwise, the procedure would have to be postponed


until adequate resources become available.
Components of Operating System :-
I/O Device Management :-

• One of the important use of an operating system that helps to hide the variations
of specific hardware devices from the user.

Functions of I/O management:-


o It offers a buffer caching system

o It provides drivers for particular hardware devices.

o I/O helps you to know the individualities of a specific


device.
Components of Operating System :-
Security Management :-

•The various processes in an operating system need to be secured from other activities.

•Therefore, various mechanisms can ensure those processes that want to operate files, memory CPU, and other
hardware resources should have proper authorization from the operating system.

•Security refers to a mechanism for controlling the access of programs, processes, or users to the resources
defined by computer controls to be imposed, together with some means of enforcement.
Components of Operating System :-
Command Interpreter System :-

• The command interpreter is the primary interface between the user and the rest of
the system.
Components of Operating System :-

Command Interpreter System :-


•Many commands are given to the operating system by control statements.

•A program that reads and interprets control statements is automatically executed when a new job is
started in a batch system or a user logs in to a time-shared system.

•Its function is quite simple, get the next command statement, and execute it.

•The command statements deal with process management, I/O handling, secondary storage
management, main memory management, file system access, protection, and networking.
Types of Software :-
• Systems Software is Programs that coordinate the activities and functions of the hardware and
various other programs.

• Application Software is Programs that help users solve particular computing problems.

• Role of Systems Software :-

Operating Systems ß Control the computer hardware and act as an interface with
applications programs.
Types of Software :-

System Software:-

• System software is computer software designed to operate the computer hardware to provide
basic functionality and to provide a platform for running application software.

• Refers to the operating system and all utility programs that manage computer resources at a low
level.
Function of System Software (Operating System) :-

• Perform common computer hardware functions (e.g. I/O)

• Provide a user interface

• Provide a degree of hardware independence

• Manage system memory

• Manage processing tasks

• Provide networking capability

• Control access to system resources and Manage files


Types of Software :-
Application Software:-

• A program or group of programs designed for end users.

• Allows end users to accomplish one or more specific (non-computer related) tasks.

Examples of Computer Application Software:-

• Word processor

• Spreadsheets

• Presentation Software

• Database Management System

• Graphic Editor

• Web Browser
Types of Application Software

• Proprietary Software is Designed to solve a unique and specific problem.

• In-House Developed or Contract.

• Off-The-Shelf Software is An existing software program that can be used without


considerable changes expected

• Customized Package is Blend of off-the-shelf software and internal/contract


software development.

• Application Service Provider.


Algorithm :-

• The word Algorithm means “a process or set of rules to be followed in


calculations or other problem-solving operations”.

• Therefore Algorithm refers to a set of rules/instructions that step-by-step define


how a work is to be executed in order to get the expected results.

• It is convenient to debug errors.

• It is somewhat easier to solve complex problem.

• It costs more time to create an algorithm.


Flowchart :-

• It is a graphic representation of a process.

• The process is shown in block-by-block information diagram.

• It is intuitive and easy to understand.

• It is hard to debug errors.

• The solution is showcased in pictorial format.

• It is hard to solve complex problem.

• It costs less time to create a flowchart.


Flowchart :-
Basic constructs of Algorithm and flowchart

There are THREE basic programming constructs.

• SEQUENCE

• SELECTION

• ITERATION
Basic constructs of Algorithm and flowchart

Sequence :-

• Sequence logic is used for performing instructions one after another in sequence.

• Sequence is the most basic of the constructs

• It is simply performing one step after another

• Each step is followed in a specific sequence, hence the name “Sequence” can be
thought of as “do this, then do this, then do this”
Sequence :-
Selection (Decision):-

• Selection logic, also known as decision logic, is used for making decisions. Selection
logic is depicted as either an IF…THEN…ELSE or IF…..THEN structure.

• Selection is the decision-making construct.

• It is used to make yes/no or true/false decisions logically.

• Selection can be thought of as “if something is true, take this action, otherwise take
that action”.
Iteration ( Loop/ Repetition):-
• Iteration logic is used when one or more instructions may be executed several times depending on
some condition.

• Iteration comes from the word “reiterate”, which means to repeat

• Iteration is a looping construct

• Iteration is a combination of decision and sequence and can repeat steps

• Iteration can be thought of as “while something is true, do this, otherwise stop”


Compilation process: Syntax and semantic errors, ASCII.

Programming Errors in C

• Errors are the problems or the faults that occur in the program, which makes the
behavior of the program abnormal.

• 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.
Compilation process: Syntax and semantic errors, ASCII.

Programming Errors in C

There are mainly five types of errors exist in C programming:

• Syntax error

• Run-time error

• Linker error

• Logical error

• Semantic error
Compilation process: Syntax and semantic errors, ASCII.

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 errors can be easily debugged or corrected.


Compilation process: Syntax and semantic errors, ASCII.
Syntax error

• For example:-

If we want to declare the variable of type integer,

int a; // this is the correct form

Int a; // this is an incorrect form.

Commonly occurred syntax errors are:

• If we miss the parenthesis (}) while writing the code.

• Displaying the value of a variable without its declaration.

• If we miss the semicolon (;) at the end of the statement.


Compilation process: Syntax and semantic errors, ASCII.
Syntax error Example:-
Compilation process: Syntax and semantic errors, ASCII.
Semantic error :-

• Semantic errors are the errors that occurred when the statements are not
understandable by the compiler.
The following can be the cases for the semantic error:
• Use of a un-initialized variable.
int i;
i=i+2;
• Type compatibility
int b = "javatpoint";
• Errors in expressions
int a, b, c;
a+b = c;
Compilation process: Syntax and semantic errors, ASCII.
Semantic error :-
ASCII code :-
• The full form of ASCII is the American Standard Code for information interchange.

• It is a character encoding scheme used for electronics communication.

• Each character or a special character is represented by some ASCII code, and each ascii code occupies
7 bits in memory.

• In C programming language, a character variable does not contain a character value itself rather the
ascii value of the character variable.

• The ascii value represents the character variable in numbers, and each character variable is assigned
with some number range from 0 to 127.

• For example, the ascii value of 'A' is 65.

• In the above example, we assign 'A' to the character variable whose ascii value is 65, so 65 will be
stored in the character variable rather than 'A'.
ASCII code :-
ASCII code :-

You might also like