KEMBAR78
Chapter 1 Introduction To C++ | PDF | Object Oriented Programming | Class (Computer Programming)
0% found this document useful (0 votes)
21 views13 pages

Chapter 1 Introduction To C++

This document introduces the process of compiling and running C++ programs, detailing the roles of compilers, linkers, and loaders. It also covers programming methodologies, specifically structured procedural programming and object-oriented programming, highlighting their differences and key concepts such as encapsulation, inheritance, and polymorphism. The document emphasizes the importance of understanding these programming paradigms for effective problem-solving and program design.

Uploaded by

S'fiso Mzilikazi
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)
21 views13 pages

Chapter 1 Introduction To C++

This document introduces the process of compiling and running C++ programs, detailing the roles of compilers, linkers, and loaders. It also covers programming methodologies, specifically structured procedural programming and object-oriented programming, highlighting their differences and key concepts such as encapsulation, inheritance, and polymorphism. The document emphasizes the importance of understanding these programming paradigms for effective problem-solving and program design.

Uploaded by

S'fiso Mzilikazi
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/ 13

CHAPTER 1

What are we doing?

 Section 1.1 Compiling a C++ program

 Section 1.2 Programming and Problem-Solving

You should:
 be aware of what the process of compiling and linking a C++ program entails;

 have a broad understanding of the concept of object-oriented programming.


COMPILING AND RUNNING A
PROGRAM
 Section 1.1 Compilers
 A compiler is a program that translates a high-level language program, such as a
C++ program, into a machine-language program that the computer can directly
understand and execute.

Source code: written in a


high-level language

E R
IL
OMP
C
Object code: low-level,
machine code equivalent
of source code
COMPILING AND RUNNING A
PROGRAM
 A text editor is used to type the program (in a high-level language) and make corrections if
necessary.
 The program is then stored in a file (the .cpp file) on a secondary storage device such as the
hard disk.
 The program typed in by the programmer is called the source code.

 The Code::Blocks integrated development environment (IDE) provides the text editor we use in
this course, and forms the interface to the compiler, the linker and the loader.
COMPILING AND RUNNING A
PROGRAM
 The programmer gives the command to compile the program.

 The compiler checks for syntax errors and translates the C++ source program into machine
language code (also referred to as object code and stored in a file with extension .o).
 In a C++ system, the compiler invokes a preprocessor program automatically before the
compiler’s translation phase begins.
COMPILING AND RUNNING A
PROGRAM
 C++ programs usually contain references to functions defined elsewhere, such as in private
(user-defined) libraries or the standard libraries (A library is code that has already been defined, it
has been fully debugged and tested, and therefore users should not need to have access to the
source code).
 The C++ preprocessor executes special commands called preprocessor directives. Preprocessor
directives typically call for the inclusion of other text files in the file that has to be compiled.
 The code for the functions residing in the libraries must be combined with the object code
produced by the C++ compiler. This is done by a linker.
 A linker links the object code produced from your source code with the code for the missing
functions to create the executable code (saved in a file with the extension .exe).
 The executable code is loaded into the main memory for execution. This is done by the loader,
which transfers the executable program from disk to memory.
 Finally, the computer executes the program.
COMPILING AND RUNNING A
PROGRAM

See Savitch p.43


PROGRAMMING
METHODOLOGIES
 The two most popular programming paradigms are:

 Structured procedural programming: the program moves through a linear series of instructions.

 Object-oriented programming: the data states and functionality to modify those data states are
packaged together while keeping the implementation details hidden.
STRUCTURED PROCEDURAL
PROGRAMMING
 Procedural programming focuses on the processes that data undergoes from input until
meaningful output is produced.
 During the design stage, the processing steps are described in an algorithm.

 An algorithm is a sequence of precise instructions that leads to a solution.

 Structured programming uses a technique called top-down design or step-wise refinement which
involves iteratively dividing a problem into subproblems until eventually, each subproblem is
straightforward enough to be solved easily.
 Each subproblem is normally written as a separate function (or procedure) that is called by a
main controlling function or module.
 A structured procedural program defines variables and then calls a series of procedures to input
values for the variables, manipulate them and output the results.
OBJECT-ORIENTED
PROGRAMMING
In object–oriented programming:-
 Applications are organized around objects rather than processes.

 A system is seen as a collection of interacting objects.

 Program components are envisioned as objects that belong to classes and are similar to real-
world objects.
 The programmer manipulates the objects and has them interrelate to achieve a desired result.

 The focus is on determining the objects you want to manipulate rather than the processes or
logic required to manipulate the data.
 Object-oriented programming involves three fundamental concepts: encapsulation, inheritance
and polymorphism.
OBJECT-ORIENTED
PROGRAMMING
 Writing object-oriented programs involves:-

 Creating classes,

 Creating objects from those classes, and

 Creating applications, i.e. stand-alone executable programs, that use those objects.

Code with OOP design is:


 Flexible

 Modular

 Abstract

If classes are designed properly, they can be reused repeatedly to develop new programs.
OBJECT-ORIENTED
PROGRAMMING
 An object generally represents a concrete entity in the real world such as a person, place or
thing.
 Such an object has certain characteristics or attributes and certain behaviours or actions.

 An object’s characteristics represent data or facts that we know about the object i.e. the state of
the object.
 The object’s behaviours are actions that the object can take. These actions are expressed in
functions or methods that execute algorithms.
 The object interacts with other objects through messages or function calls.

 Encapsulation: combining the attributes and behaviours, i.e. an object’s data and functions
together to form a class.
OBJECT-ORIENTED
PROGRAMMING
 There are four major benefits to object-oriented programming:

Encapsulation: in OOP, you bundle code into a single unit where you can determine the
scope of each piece of data.

Abstraction: by using classes, you generalize your object types, simplifying your program.

Inheritance: because a class can inherit attributes and behaviours from another class, you
can reuse more code.

Polymorphism: one class can be used to create many objects, all from the same flexible
piece of code.
OOP TERMINOLOGY
 A class is a template or blueprint that can be used to construct or instantiate many similar
objects. A class can also be seen as a sort of user-defined data type, which we call an abstract
data type (ADT).
 An object is an instance of a class.

 A class hides information by restricting access to it. In effect the data and methods within an
object are hidden from users to prevent inadvertent changes. Users of the class simply need to
understand how to use the interface or interaction between the object and its methods.
 Through inheritance it is possible to define subclasses that share the parent class’s attributes
and methods, but with more specific features. This enables the reuse of code.
 Polymorphism (many forms) describes the feature in languages that allow us to interpret the
same word differently in different situations based on the context in which it is used. In object-
oriented programs, similar objects can respond to the same function call or message in different
ways.

You might also like