0% found this document useful (0 votes)
2 views

EE172_Lecture_1_Introduction_to_C++

EE172 is a Computer Programming course for Engineers, focusing on C++ and MATLAB, with a total course weight of 2 units. The course includes lectures and practical sessions, with assessments comprising continuous assessment (40%) and a university examination (60%). Key topics include C++ fundamentals, control statements, structured data types, and advanced features like object-oriented programming.

Uploaded by

regan12francis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

EE172_Lecture_1_Introduction_to_C++

EE172 is a Computer Programming course for Engineers, focusing on C++ and MATLAB, with a total course weight of 2 units. The course includes lectures and practical sessions, with assessments comprising continuous assessment (40%) and a university examination (60%). Key topics include C++ fundamentals, control statements, structured data types, and advanced features like object-oriented programming.

Uploaded by

regan12francis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

EE172

Computers Programming for


Engineers

Instructor: Omary, S. Kasinge


Office: CoET Block A – Room A209
1
Mode of Delivery
2

 Course Weight: 2 Units

 Lecture: 2 hours per week


(Thursday, 13:00 -15: 00 hrs)

 Practical/Lab: 2 hours per week (A319)


Course Assessment
3

 Continuous Assessment (40%):


• Test
• Lab
• Assignment
• Quiz

 University Examination (60%)


Course Outline (at glance)
4

Part I: Computer Programming using C++

Part II: Introduction to MATLAB


Course Outline
5

 Introduction to C++: Overview of C++


 Fundamentals of C++:
 keywords, identifiers
 data types, operators
 Standard I/O functions
 Control statements:
 Decision Making: if, if-else, ternary-operator, switch
 Loop Statements: for loop, while-loop, do-while loop
Course Outline
6

 Structured Data Types: Arrays, Structure, Union, Functions,


Pointers
 Advanced features of C++:
 Object Oriented Programming (OOP)
 Classes and Objects
 Encapsulation, Abstraction
 Inheritance and Polymorphism

 Introduction to MATLAB
Text/Reference Books
7

 Pratta, S., “C++ Primer Plus”, 4th Edition. Sams Publishing,


2001.

 Deitel, H. M. & Deitel, P. J., “C++ How to Program”, 5th ed.


Prentice-Hall, 2005.

 MATLAB, Language of Technical Computing, MathWorks


Inc.1997.
Online Study

https://www.studytonight.com/cpp/

https://www.javatpoint.com/cpp-tutorial

8
Compiler / IDE

Codeblocks (GCC Compiler)

Coding C++

9
EE172
Computer Programming for
Engineers

Lecture 1:
Introduction to C++
10
Overview of C++
C versus C++
Structure of C++ Program

Keywords and Identifiers in C++


Data types and Operators in C++
Standard I/O Functions in C++
11
Overview of C++
12

C++ is a general purpose programming language created in 1983 as


an extension to C language.
The original name was “C with classes”
C++ was created for handling complex tasks that C was not able
to perform
C++ supports both procedural and object oriented
programming
Programs written in C language can run in C++ compiler.
C versus C++
C C++

Both are general purpose programming languages.

Programs written in C language can run in C++ compiler.

Supports procedural programming Supports both procedural and object-


only oriented programming features

Offers more features such as error


handling, data security, information
hiding, inheritance and function
overloading
13
Main Features of C++
14

 C++ supports data encapsulation

 C++ supports inheritance

 C++ supports polymorphism

 C++ supports data abstraction


Applications of C++
15

 Software Development: Operating systems, Browsers, Database


systems (MySQL).

 Programming Languages - C++ has been used extensively in


developing new programming languages like C#, Java, PHP and Python.

 Games Development - C++ is used for CPU intensive applications


such as gaming engines.
 Embedded Systems - C++ is being heavily used in developing
embedded software (MRI machines, sensors, IoT)
Basic Structure of a C++ Program

16
17
18
19
20
I/O header file

Identifier scope resolution

Beginning of the program

End of the program

21
Standard I/O Functions in C++
22

 C++ uses the concept of stream for I/O operations


 Stream is the sequence of bytes or flow of data
 If data flows from main memory to devices like printer, display
screen, or a network connection it is called output stream
(ostream).
 If data flows from devices like printer, display screen, or a
network connection to main memory it is called input stream
(istream)
I/O Library Header Files
23

Header File Function and Description

Used to define the cout, cin, endl, width, precision,


<iostream> fill, setf, fixed, scientific, hexfloat and cerr objects,
which correspond to standard input/output streams.

Used to declare services useful for performing


<iomanip>
formatted I/O, such as setprecision, setw, setbase

Used to declare services for user-controlled file


<fstream>
processing
Standard Output Stream (cout)
24

 cout is a predefined object of ostream class.


 cout is connected with the standard output device, which is
usually a screen.
 cout is used in conjunction with stream insertion operator
(<<) to display the output to the screen.
Standard Input Stream (cin)
25

 cin is a predefined object of istream class.


 cin is connected with the standard input device, which is
usually a keyboard.
 cin is used in conjunction with stream extraction operator
(>>) to read the input from the keyboard
What is the essence of the line

“using namespace std”

26
What is
namespace std?

27
28
Error: conflicting declaration of ‘data’
29
30
 In programming, we cannot have variables or functions with
the same name.
 If the program has two identical identifier names, a compiler
has no way of knowing which version of the identifiers is
referred.
 To avoid these names conflict, we use namespaces.
 A namespace is used as additional information to
differentiate similar identifiers with the same name.
 In essence, a namespace defines a scope.
31
32
33
Keywords in C++
34

 Keywords (reserved words) have special meaning to the C++ compiler


 Cannot be used as an identifier
 Must be typed in lower case letters.

auto break case char const continue default do


double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
Keywords in C++…
35

asm dynamic_cast namespace reinterpret_cast bool


explicit new static_cast false catch
operator template friend private class
this inline public throw const_cast
delete mutable protected true try
typeid typename using virtual wchar_t
Identifiers in C++
36

 Identifiers are distinct names given to program elements


such as constants, variables, functions and other user-defined
data types created by a programmer.

 Identifiers consist of letters, digits, and underscore.


 Must begin with a letter or underscore.
 Identifier name must not be a keyword.
 Identifier names are case-sensitive.
Variables and Constants in C++
37

 A variable is a name given to the location in memory


whose content may change during program execution

 A constant is an identifier, which remain unchanged


during the execution of a program
Data Types in C++
38

 Primary Data Types: character, integer, Boolean,


double, floating point, void

 User-defined Data Types: Structure, Union,


Enumeration, Class

 Derived Data Types: Array, Function, Pointer


Operators in C++
39

 Assignment Operator
 Arithmetic Operator
 Relational Operator
 Logical Operator
 Conditional Operator
 Bitwise Operator
Assignment Operator
40

Operator Example Meaning

= A = 5 A = 5

+= A += 5 A = A+5

/= A /= 5 A = A/5

*= A *= 5 A = A*5
Arithmetic Operators
41

Operator Example
a + b Addition
a - b Subtraction
a * b Multiplication
a / b Division
a % b Remainder (modulo division)
++b Add 1 before using a variable
--b Subtract 1 before using a variable
Relational Operators
42

Operator Meaning
== Equivalent
!= Not equivalent
< Less than
> Greater than
<= Less than or Equal to
<= Greater than or Equal to
Logical Operators
43

Operator Meaning Description

&& Logical AND. True only if al the operands are true

Returns TRUE if at least one of the


|| Logical OR.
operands is true.

Returns TRUE only if the operand is


! Logical NOT.
false.
44

You might also like