2 Structured Programming Using C++

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

STRUCTURED

PROGRAMMING
USING C++

• Computer System Architecture


• C++ Development Environment
• Evolution of Programming
Languages
COMPUTER SYSTEM
ARCHITECTURE
• Computer system has five basic units that help the
computer to perform operations, which are given below:

• Input Unit
• Output Unit
• Storage Unit (Memory Unit)
• Arithmetic Logic Unit
• Control Unit
INPUT UNIT
• Data and instructions are given as input to the system so as to perform a particular
operation.
• Input unit connects the external environment with internal computer system. It provides
data and instructions to the computer system. Commonly used input devices
are keyboard, mouse, magnetic tape etc.
• instruction operation to be performed.
• Data  information over which an operation is to be performed.
• example : x+y  + symbol will be translated into an instruction (ADD)
• The following functions are performed by an input unit:
• Accept the data and instructions from the outside environment.
• Convert it into machine language.
• Supply the converted data to computer system.
• Translation:
• Translator that can translate the human
language in to the machine language .
• Low level Language – machine can understand .
• High level Language- we can understand .
• The set of programs that perform a translation
of high- level language in to low level language
are called as system programs.
• We must follow certain rules while writing the
programs in high level programming language.
These rules are called as syntax.
OUTPUT UNIT
• Output Unit:
• The output unit provides the results
of computer process to the users i.e
it links the computer with the
external environment.
• Most of the output data is the form
of audio or video. The different
output devices are monitors, printers,
speakers, headphones etc.
STORAGE UNIT

• Storage unit contains many computer components that are used to store data.
• It is traditionally divided into primary storage and secondary storage.
• Primary storage is also known as the main memory and is the memory directly
accessible by the CPU.
• Secondary or external storage is not directly accessible by the CPU.
• The data from secondary storage needs to be brought into the primary storage
before the CPU can use it.
• Secondary storage contains a large amount of data permanently.
Types of Primary MEMORY
1. RAM

2. ROM

• RAM • ROM
Difference RAM ROM

RAM is a volatile memory. So, its ROM is a non-volatile memory.


Data retention contents are lost when the device is Data remains even after power supply
powered off. is not present.

Data stored in RAM can be


Working type Data stored in ROM can only be read.
retrieved and altered.

Both R (read) and W (write) operations The ROM memory allows the user to read
Read/Write can be performed over the information the information. But, the user can’t alter the
which is stored in the RAM. information.
ROM memory is used to store
RAM is used to store temporary
Storage permanent information, which is non-
information.
erasable.
Speed It is a high-speed memory. It is much slower than the RAM.

The CPU can not access the data stored on it


CPU Interaction The CPU can access the data stored on it.
unless the data is stored in RAM.

Size and Capacity Large size with higher capacity. Small size with less capacity.

The data stored is not as easily accessible as in


Accessibility The data stored is easily accessible
RAM

Cost Costlier cheaper than RAM.


• Arithmetic Logical Unit:
• All the calculations are performed in ALU of the computer system.
• The ALU can perform basic operations such as addition, subtraction, division, multiplication
etc.
• Whenever calculations are required, the control unit transfers the data from storage unit to
ALU. When the operations are done, the result is transferred back to the storage unit.
• The arithmetic logic unit and the control unit together form the central processing unit.
• Control Unit:
• It controls all other units of the computer. It controls the flow of data and instructions to and
from the storage unit to ALU.
• This unit controls all the other units of the computer system and so is known as its central
nervous system. It transfers data throughout the computer as required including from
storage unit to central processing unit and vice versa.
It is Central Processing Unit of the computer. The control unit and ALU
are together known as CPU. CPU is the brain of computer system. It
performs following tasks:

CPU-
CENTRAL
PROCESSING It performs all operations.
UNIT

It takes all decisions.

It controls all the units of computer.


Editor
Pre-processor
C++
DEVELOPMEN Compiler
T
ENVIRONMEN Linker
T
Loader
Execution
• Creating a Program (or) Editor:

• Creating program (normally known simply as an editor). You type a C++ program
(typically referred to as source code) using the editor, make any necessary corrections
and save the program on a secondary storage device, such as your hard drive.
• C++ source code file names often end with the .cpp, .cxx, .cc or .C extensions (note that
C is in uppercase) which indicate that a file contains C++ source code.
Preprocessor:
• The preprocessor performs preliminary operations on C and C++ files before they are
passed to the compiler.
• You can use the preprocessor to conditionally compile code, insert files, specify
compile-time error messages, and apply machine-specific rules to sections of code.
• All of these pre-processor directives begin with a ‘#’ (hash) symbol. The ‘#’ symbol
indicates that, whatever statement starts with #, is going to the preprocessor program,
and pre-processor program will execute this statement. Examples of some preprocessor
directives are: #include, #define etc.
• Compiler:
• C program can run on a computer, it must be translated from source code to
machine language.
• It’s performed by a program called a compiler. The compiler takes our source code
file as input and produces a disk file containing the machine language instructions
that correspond to our source code statements.
• LINKERS:
• A linker or link editor is a program that takes one or more objects generated
by a compiler and combines them into a single executable program.
• Loader:
• Before a program can be executed, it must first be placed in memory.
• This is done by the loader, which takes the executable image from disk and transfers it to
memory. Additional components from shared libraries that support the program are also
loaded.

• Execution:

• Finally, the computer, under the control of its CPU, executes the program one instruction at
a time.
EVOLUTION OF
PROGRAMMING
LANGUAGES
OOP:
Object-oriented programming aims to
implement real-world entities like
inheritance, abstraction, polymorphism, etc
in programming.

POP:
In this approach, a program is divided into
functions that perform specific tasks. This
approach is mainly used for medium-sized
applications. Data is global, and all the
functions can access global data.
. No. Key POP OOP

Definition POP stands for Procedural Oriented OOP stands for Object Oriented
1 Programming. Programing.

Approach POP follows top down approach. OOP follows bottom up


2 approach.

Division A program is divided into functions and A program is divided to objects


they interacts. and their interactions.
3

Inheritance Inheritance is not supported. Inheritance is supported.


4 supported

Data Hiding No data hiding present. Data is globally Encapsulation is used to hide
5 accessible. data.
Data hiding & security There is no proper way of hiding the Data is hidden in three modes
data, so data is insecure public, private, and protected.
hence data security increases.

Data sharing Global data is shared among the Data is shared among the objects
functions in the program. through the member functions.

Friend functions or friend No concept of friend function. Classes or function can become a
classes friend of another class with the
keyword "friend".
Note: "friend" keyword is used
only in c++

Virtual classes or virtual No concept of virtual classes . Concept of virtual function


function appear during inheritance.
OOP
• OOP, refers to Object Oriented Programming and its deals with objects and their
properties. Major concepts of OOPs are −

• Class
• objects
• Encapsulation
• Inheritance
• Abstraction
• Polymorphism
CLASS

• A Class is a user-defined data-type which has data members and member functions.
• A class is like a blueprint for an object.
• These data members and member functions define the properties and behavior of the objects in a Class.
Class Student //creating the class
{
int id=101;
String name=“Thibi”
fun1()
{

…….
…….
}
};
Object:
any entity that has state and behavior is known as an object. For example: chair, pen, table,
keyboard, bike etc. It can be physical and logical.

An object is an identifiable entity with some characteristics and behavior. An object is an


instance of a class. When a class is defined, no memory is allocated but when it is instantiated
(i.E. An object is created) memory is allocated.
class person
{
int main()
char name[20];
{
int id;
person p1; // p1 is a object
public:
}
void getdetails(){} //
};
• Encapsulation:
• Encapsulation is defined as wrapping up of data and information under a single unit. In Object-
Oriented Programming, Encapsulation is defined as binding together the data and the functions
that manipulate them.

• Abstraction:
• Abstraction means displaying only essential information and hiding the details. Data
abstraction refers to providing only essential information about the data to the outside world,
hiding the background details or implementation.
• Hiding internal details and showing functionality is known as abstraction. In C++, we use
abstract class and interface to achieve abstraction.
• Inheritance:
• When one object acquires all the properties and behaviours of parent object i.e. known as
inheritance. It provides code reusability.
• It is used to achieve runtime polymorphism.
• Base class (Parent)
• Derived Class (child)
• Polymorphism:
• The word polymorphism means having many forms. In simple words, we can define
polymorphism as the ability of a message to be displayed in more than one form.
• When one task is performed by different ways i.e. known as polymorphism. For example:
to convince the customer differently, to draw something e.g. shape or rectangle etc.

• Two types:
• Compile time Polymorphism -Overloading
• Run time Polymorphism - overriding

You might also like