2 Structured Programming Using C++
2 Structured Programming Using C++
PROGRAMMING
USING C++
• 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
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.
Size and Capacity Large size with higher capacity. Small size with less capacity.
CPU-
CENTRAL
PROCESSING It performs all operations.
UNIT
• 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.
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++
• 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.
• 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