0% found this document useful (0 votes)
6 views16 pages

CSC 201 Note Two

Uploaded by

sanihkmpl
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)
6 views16 pages

CSC 201 Note Two

Uploaded by

sanihkmpl
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

CSC 201 Computer programming 1

c++
Presented By :
Muhammad Fatima Adam
fatima.m@[Link]
Department of Computer Science
2022/2023
Problem Solving
Suppose a particular person is giving travel directions to a friend, that
person might explain those directions in any one of several languages,
such as English, Hausa, Yaruba, or Ibo.

The directions are the same no matter which language is used to explain
them, but the manner in which the directions are expressed is different.
Furthermore, the friend must be able to understand the language being
used to order to follow the directions.

Similarly, a problem can be solved by writing a program in one of many


programming languages, such as C++, Java, Pascal, and Smalltalk.
Problem Solving
Methodologies
The purpose of writing a program is to solve a
problem. Problem solving, in general, consists of
multiple steps:
Understand the problem.
Breaking the problem in to manageable pieces.
Designing a solution.
Considering alternatives to the solution and
refining the solution.
Implementing the solution.
Testing the solution and fixing any problems
that exist.
COMPILERS AND
To help with
INTERPRETERS
the development of new programs, several
special purpose programs are necessary, which are commonly
referred to as software tools since they are used to build
programs.
Basic software tools, such as an editor, a compiler, and an
interpreter, are used as examples.

The translation of source code into machine language,


specifically for a particular type of CPU, can occur in various
ways.
COMPILERS
A compiler is a software that converts code written in
one language to an equivalent form in another language,
with the original code being referred to as source code,
and the resulting language being the target language.

In the case of most conventional compilers, the source


code is directly translated into a specific machine
language, and the translation process happens only
once, producing an executable program that can be run
as needed.
INTERPRETERS
An interpreter is comparable to a compiler but with a
significant difference in its operation.
It integrates the translation and execution activities by
interpreting and executing a small portion of the source
code, such as a single statement, and then proceeding to
interpret and execute another statement, and so on.

This approach eliminates the requirement for a distinct


compilation phase, but it usually results in slower program
execution because the translation process occurs during
each execution.
Errors
In programming, an error refers to any deviation from the
expected or desired behavior of a program. These deviations can
occur due to a wide range of factors, such as syntax mistakes,
logical mistakes, incorrect usage of programming constructs or
functions, data input errors, memory issues, hardware or software
faults, and unexpected events such as power outages or network
failures.
Programming errors can lead to program crashes, data loss,
incorrect results, security vulnerabilities, and other types of
problems that can affect the functionality, reliability, and usability
of the program. The process of identifying, diagnosing, and fixing
programming errors is commonly known as debugging.
Types of Errors
1. Compile-time errors: These are errors that occur during
the compilation phase of the program, where the source
code is converted into machine code. The compiler
detects these errors and prevents the program from
running. Some examples of compile-time errors are
syntax errors, type errors, and missing header files.
2. Runtime errors: These are errors that occur during the
execution of the program when the program is running.
Types of Errors
These errors can happen due to various reasons, such as
incorrect input data, memory issues, division by zero, or
referencing a null pointer. Runtime errors can cause the
program to crash or behave unpredictably.
3. Logical errors: These are errors that occur when the program
runs without any errors or warnings but does not produce the
expected or desired output due to a flaw in the program's logic.
Logical errors can be difficult to detect and fix as they require a
thorough understanding of the program's intended behavior and
the error in the code.
Syntax, Semantics, and Pragmatics
In programming languages, syntax pertains to the structure of
programs, defining the required arrangement of expressions,
commands, declarations, and other constructs to form a well-
formed program.
Semantics, on the other hand, pertains to the meaning of
programs, describing the expected behavior of a well-formed
program when executed on a computer.
Pragmatics deals with the practical use of the programming
language, specifying the intended ways in which the language
should be utilized.
C++ History
C++ was developed by Bjarne Stroustrup of AT&T Bell
Laboratories in the early 1980's, and is based on the C
language. The name is a pun - "++" is a syntactic construct
used in C (to increment a variable), and C++ is intended as an
incremental improvement of C.
what are the four pillars of object-oriented
development C++ fully supports ?
The four pillars of object-oriented development are as
follows:
Encapsulation:
Inheritance:
Polymorphism:
Abstraction:
what are the four pillars of object-oriented
development C++ fully supports ?
Encapsulation: This is the concept of binding data and the
methods that operate on that data into a single unit or object,
thereby hiding the implementation details from the outside world.
Encapsulation promotes data security, improves code modularity
and reusability, and reduces the likelihood of naming conflicts.

Inheritance: This is the mechanism that allows new classes to be


derived from existing classes, inheriting their attributes and
behavior. Inheritance facilitates code reuse, promotes modularity
and extensibility, and reduces code duplication.
what are the four pillars of object-oriented
development C++ fully supports ?
Polymorphism: This is the ability of objects to take on many forms or behaviors,
depending on the context in which they are used. Polymorphism enables code
to be more flexible, modular, and extensible, and it enhances code reuse.

Abstraction: This is the process of representing complex real-world entities or


systems in a simplified form, by focusing on the essential features and ignoring
the non-essential ones. Abstraction promotes code readability, maintainability,
and scalability, and it reduces code complexity and duplication.

C++ fully supports all four pillars of object-oriented development, making it a


powerful and flexible language for developing complex software systems.
HOW TO WRITE AND RUN PROGRAMS

To write and run C++ programs, you need to


have a text editor and a C++ compiler installed on
your computer.
A text editor is a software system that allows
you to create and edit text files on your computer.
Programmers use text editors to write programs
in a programming language such as C++.
Thank
you!

You might also like