Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views14 pages

Lec 1

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 14

Egyptian Korean Facility of Technological

Industry and Energy

PC Based
LECTURE 1
Dr. Sherif Kamal

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

Course Contents:
• C++ Overview
• C++ Basics
• C++ Variables and Constants
• C++ Data Types and Literals
• C++ Operators
• C++ Input/Output
• C++ Control Statements
• C++ Functions
• Class and Objects
• File Handling
• C++ Pointers and References
• C++ Arrays
• C++ Strings
• C++ Structures and Unions
• C++ Dynamic Memory Management
• C++ Object-Oriented Programming
• C++ Encapsulation and Abstraction
• C++ Function Overloading
• C++ Operator Overloading

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

Reference Books:
1. “The C++ Programming Language” by Bjarne Stroustrup
2. “Effective C++: 55 Specific Ways to Improve Your Programs
and Designs” by Scott Meyers
3. “C++ Primer Plus” by Stephen Prata
4. “C++ For Dummies” by Stephen R. Davis
5. “Data Structures and Algorithm Analysis in C++” by Mark
Allen Weiss
6. The name of C++ signifies the evolutionary nature of the
changes from C. “++” is the C increment operator.
7. C++ is one of the predominant languages for the
development of all kind of technical and commercial
software.
8. C++ introduces Object-Oriented Programming, not present in
C. Like other things, C++ supports the four primary features
of OOP: encapsulation, polymorphism, abstraction, and
inheritance.
9. C++ got the OOP features from Simula67 Programming
language.
10. A function is a minimum requirement for a C++ program to
run.(at least main() function)

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

Features of C++

C++•• is a general-purpose programming language that was developed as an enhancement of
the C language to include an object-oriented paradigm. It is an imperative and compiled
language. C++ has a number of features, including:

• Object-oriented Programming
• Machine Independent
• Simple
• High-Level Language
• Popular
• Case-sensitive
• Compiler Based
• Dynamic Memory Allocation
• Memory Management
• Multi-threading

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

1. Object-Oriented Programming

C++ is an Object-Oriented Programming Language, unlike C which is a procedural programming

language. This is the most important feature of C++. It can create/destroy objects while

programming. Also, It can create blueprints with which objects can be created. We have

discussed the Object-Orient Programming Concepts in C++ in this article.

Concepts of Object-oriented programming Language:

• Class

• Objects

• Encapsulation

• Polymorphism

• Inheritance

• Abstraction

2. Machine Independent

A C++ executable is not platform-independent (compiled programs on Linux won’t run on

Windows), however, they are machine-independent. Let us understand this feature of C++

with the help of an example. Suppose you have written a piece of code that can run on

Linux/Windows/Mac OSx which makes the C++ Machine Independent but the executable

file of the C++ cannot run on different operating systems.

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

3. Simple

It is a simple language in the sense that programs can be broken down into logical units and

parts, has rich library support and has a variety of data types. Also, the Auto Keyword of C++

makes life easier.

Auto Keyword

The idea of the auto keyword was to form the C++ compiler to deduce the data type while

compiling instead of making you declare the data type every freaking time. Do keep in mind

that you cannot declare something without an initializer. There must be some way for the

compiler to deduce your type.

4. High-Level Language

C++ is a High-Level Language, unlike C which is a Mid-Level Programming Language. It

makes life easier to work in C++ as it is a high-level language it is closely associated with the

human-comprehensible English language.

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

5. Popular

C++ can be the base language for many other programming languages that supports the

feature of object-oriented programming. Bjarne Stroustrup found Simula 67, the first object-

oriented language ever, lacking simulations, and decided to develop C++.

6. Case-sensitive

It is clear that C++ is a case-sensitive programming language. For example, cin is used to take

input from the input stream. But if the “Cin” won’t work. Other languages like HTML and

MySQL are not case-sensitive languages.

7. Compiler Based

C++ is a compiler-based language, unlike Python. That is C++ programs used to be compiled

and their executable file is used to run them. C++ is a relatively faster language than Java

and Python.

8. Dynamic Memory Allocation

When the program executes in C++ then the variables are allocated the dynamical heap space.

Inside the functions, the variables are allocated in the stack space. Many times, We are not

aware in advance how much memory is needed to store particular information in a defined

variable and the size of required memory can be determined at run time.

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

9. Memory Management

• C++ allows us to allocate the memory of a variable or an array in run time. This is

known as Dynamic Memory Allocation.

• In other programming languages such as Java and Python, the compiler automatically

manages the memories allocated to variables. But this is not the case in C++.

• In C++, the memory must be de-allocated dynamically allocated memory manually

after it is of no use.

• The allocation and deallocation of the memory can be done using the new and delete

operators respectively.

10. Multi-threading

• Multithreading is a specialized form of multitasking and multitasking is a feature that

allows your system to execute two or more programs concurrently. In general, there

are two sorts of multitasking: process-based and thread-based.

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy
• Process-based multitasking handles the concurrent execution of programs. Thread-

based multitasking deals with the multiprogramming of pieces of an equivalent

program.

• A multithreaded program contains two or more parts that will run concurrently. Each

part of such a program is named a thread, and every thread defines a separate path of

execution.

• C++ doesn’t contain any built-in support for multithreaded applications. Instead, it

relies entirely upon the OS to supply this feature.

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

C++ Hello World Program


Below is the C++ program to print Hello World.

// C++ program to display "Hello World"

// Header file for input output functions


#include <iostream>
using namespace std;

// Main() function: where the execution of


// program begins
int main()
{
// Prints hello world
cout << "Hello World";

return 0;
}

Output
Hello World

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

Working of Hello World Program in C++


Let us now understand every line and the terminologies of the
above program.

1. // C++ program to display “Hello World”

This line is a comment line. A comment is used to display


additional information about the program. A comment does not
contain any programming logic. When a comment is encountered
by a compiler, the compiler simply skips that line of code. Any
line beginning with ‘//’ without quotes OR in between /*…*/ in
C++ is a comment.

2. #include

This is a preprocessor directive. The #include directive tells the


compiler to include the content of a file in the source code.
For example, #include<iostream> tells the compiler to include
the standard iostream file which contains declarations of all the

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

standard input/output library functions.

3. using namespace std

This is used to import the entity of the std namespace into the
current namespace of the program. The statement using
namespace std is generally considered a bad practice. When we
import a namespace, we are essentially pulling all type definitions
into the current scope.

The std namespace is huge. The alternative to this statement is to


specify the namespace to which the identifier belongs using the
scope operator(::) each time we declare a type. For example,
std::cout.

4. int main() { }

A function is a group of statements that are designed to perform a


specific task. The main() function is the entry point of every C++
program, no matter where the function is located in the program.

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

The opening braces ‘{‘ indicates the beginning of the main function
and the closing braces ‘}’ indicates the ending of the main function.

5. cout<<“Hello World”;

std::cout is an instance of the std::ostream class, that is used to


display output on the screen. Everything followed by the character
<< in double quotes ” ” is displayed on the output device. The semi-
colon character at the end of the statement is used to indicate that
the statement is ending there.

6. return 0

This statement is used to return a value from a function and


indicates the finishing of a function. This statement is basically
used in functions to return the results of the operations performed
by a function.

LECTURE 1 Dr. Sherif Kamal


Egyptian Korean Facility of Technological
Industry and Energy

Important Points
1. Always include the necessary header files for the smooth
execution of functions. For example, <iostream> must be
included to use std::cin and std::cout.
2. The execution of code begins from the main() function.
3. It is a good practice to use comments in programs for easy
understanding.
4. cout is used to print statements and cin is used to take
inputs.

LECTURE 1 Dr. Sherif Kamal

You might also like