SlideShare a Scribd company logo
1 of 20
Chapter 2
An Overview of C++
Ragia A. Ibrahim, Ph.D. Student
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
‫بحوث‬ ‫مركز‬ ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬
2
Is prime?
Start
“Enter Positive Integer Number”
Store Value In
N
i<n
i=2
prime= true
i++
prime= false
n mod i = 0
print prime
Stop
Introduction
• The programming language C++ was
developed as extension of C.
• C++ provides capabilities for object
oriented programming.
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
C++ is hybrid language which has
structured style, an object-oriented style
or both
Introduction
‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
Programming example: converting
units of measurement
• Problem statement: you work in a store
that imports textile most of the textile you
receive is measured in square meters.
However, the store’s customers want to
know the equivalent amount in square
yards. You need to write an algorithm that
performs this conversion
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
Problem analysis:
• Problem input:
• The textile size in square meters
• Problem output:
• The textile size in square yards
• Relevant formula:
• 1 square yards= 1.196 square meter
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
Program
// this program converts square meters to square yards
# include <iostream.h>
Int main()
{
float m,y;
cout<<“enter the textile size in square meters:n”;
cin>>m;
y = 1.196*m;
cout<<“the textile size in square yards is”<<y;
return 0;
} ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
Output window
Enter the textile size in square meters:
2.0
The textile size in square yards is 2.392
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
Data Types and Variables
Declaration
ExampleDetailsData
type
Ch=‘K’;
ch=‘k’;
char ch;8 bitschar
n=9;Int n;Short 16, 32 bits
long 64 bits (10 digits)
Int
s=4.7float s;(machine Dependent)
float s;
(6 digits).
float
f=0;0
0 false
1 true
bool f;bool f;bool
Sign -1 Magnitude-31
Sign -1 Exponent 23 Fraction-8
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
Arithmetic operators
operation C++ operator expression
Addition + X+y
Subtraction - X-y
Multiplication * X*y
Division / x/y
Modulus % X%y
‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
Assignment operators
• Sum = i = 0;
• Sum = (i=0);
Precedence order
last2nd1st
+ ,-*,/,%()
Associates RIGHT to LEFT
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
Relational Operators
Operation C++
operator
Expression
Equality == X==y
inequality != X!=y
Greater than > X>y
Less than < X<y
Greater than or equal to >= X>=y
Less than or equal to <= X<=y
‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
Logical operators
Operation C++ operator Expression
Logical negation ! !x
Logical and && X && y
Logical or || X || y
‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
Shorthand Assignment Operators
• lhs op = rhs
• +=,-=,*=,/=,%=,>>=,<<=,&=,|=,and ^=
• P *=x;
• lhs = lhs op rhs
e.g. p *=x; p=p*x;
p+=x; p=p+x;
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
Postfix and Prefix Assignment
i++ or ++i is equivalent to i + = 1
i-- or --i is equivalent to i - = 1
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
Postfix and Prefix Assignment
//pre-incrementing and post-incrementing
#include <iostream.h>
Int main()
{ int c=5;
cout<<c;
cout <<c++;
cout <<c<<endle;
c=5;
cout <<c;
cout <<++c;
cout <<c;
return 0;
}
5 5 6
5 6 6
Output
window
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
The Evaluation Order of Operators
Operator type Operation Associativity
Prefix ++, --
Unary ! Left to right
Arithmetic * , / , % , + , - Left to right
Relational < , > , <= , >=,==,!= Left to right
Logical && || Left to right
Assignment
postfix
=, +=, -=, *=, /=, %=
Right to left
++ , --
‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
Expression Value
X>y || z<=y 0||1 1
--x || y&&z 0||1 1
++x + y > !z /w 2 + 3> 0/4 1
E.g.
x=1 y=2 z=3 w=4
‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
Function?.
Function body consists of declaration and
statements enclosed between { }
Variable type f_name(tyep1,type2…)
{
}
e.g.
Int main()
{
}
‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
HW…please try to solve the
following from the text book:
1
4
5
7

More Related Content

Viewers also liked

R programming Fundamentals
R programming  FundamentalsR programming  Fundamentals
R programming FundamentalsRagia Ibrahim
 
Version Control With GitHub & RStudio
Version Control With GitHub & RStudioVersion Control With GitHub & RStudio
Version Control With GitHub & RStudioRsquared Academy
 
Step by Step Guidance to Study Abroad
Step by Step Guidance to Study AbroadStep by Step Guidance to Study Abroad
Step by Step Guidance to Study AbroadSamaa Hazem Hosny
 
R Programming: First Steps
R Programming: First StepsR Programming: First Steps
R Programming: First StepsRsquared Academy
 
R programming intro with examples
R programming intro with examplesR programming intro with examples
R programming intro with examplesDennis
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to MatricesRsquared Academy
 
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...Revolution Analytics
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRsquared Academy
 

Viewers also liked (9)

R programming Fundamentals
R programming  FundamentalsR programming  Fundamentals
R programming Fundamentals
 
Version Control With GitHub & RStudio
Version Control With GitHub & RStudioVersion Control With GitHub & RStudio
Version Control With GitHub & RStudio
 
Step by Step Guidance to Study Abroad
Step by Step Guidance to Study AbroadStep by Step Guidance to Study Abroad
Step by Step Guidance to Study Abroad
 
R program
R programR program
R program
 
R Programming: First Steps
R Programming: First StepsR Programming: First Steps
R Programming: First Steps
 
R programming intro with examples
R programming intro with examplesR programming intro with examples
R programming intro with examples
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
 
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
 

Similar to Chapter2

شبكات الأعمال.pptx
شبكات الأعمال.pptxشبكات الأعمال.pptx
شبكات الأعمال.pptxadeliaazuva
 
excel total topic.pptx
excel total topic.pptxexcel total topic.pptx
excel total topic.pptxAtefMarzouk1
 
تحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظم
تحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظم
تحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظمNasemAl
 
ماهى مميزات برنامج محاسبة محطات الخرسانة الجاهزة والبلوك.pdf
ماهى مميزات برنامج محاسبة محطات الخرسانة الجاهزة والبلوك.pdfماهى مميزات برنامج محاسبة محطات الخرسانة الجاهزة والبلوك.pdf
ماهى مميزات برنامج محاسبة محطات الخرسانة الجاهزة والبلوك.pdfEgypt
 
java input & output Statments
java input & output Statmentsjava input & output Statments
java input & output StatmentsSalem Adrugi
 
المؤشرات .pptx
المؤشرات .pptxالمؤشرات .pptx
المؤشرات .pptxssuserfcf1ac
 
شرح الوحدة الرابعة
شرح الوحدة الرابعةشرح الوحدة الرابعة
شرح الوحدة الرابعةMohammad Fahad
 

Similar to Chapter2 (11)

البرمجة+ الستركجر
البرمجة+ الستركجرالبرمجة+ الستركجر
البرمجة+ الستركجر
 
شبكات الأعمال.pptx
شبكات الأعمال.pptxشبكات الأعمال.pptx
شبكات الأعمال.pptx
 
excel total topic.pptx
excel total topic.pptxexcel total topic.pptx
excel total topic.pptx
 
تحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظم
تحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظم
تحليل نظم تحليل نظمتحليل نظم تحليل نظمتحليل نظم تحليل نظم
 
ماهى مميزات برنامج محاسبة محطات الخرسانة الجاهزة والبلوك.pdf
ماهى مميزات برنامج محاسبة محطات الخرسانة الجاهزة والبلوك.pdfماهى مميزات برنامج محاسبة محطات الخرسانة الجاهزة والبلوك.pdf
ماهى مميزات برنامج محاسبة محطات الخرسانة الجاهزة والبلوك.pdf
 
الحل
الحلالحل
الحل
 
java input & output Statments
java input & output Statmentsjava input & output Statments
java input & output Statments
 
المؤشرات .pptx
المؤشرات .pptxالمؤشرات .pptx
المؤشرات .pptx
 
شرح الوحدة الرابعة
شرح الوحدة الرابعةشرح الوحدة الرابعة
شرح الوحدة الرابعة
 
شرح الوحدة الرابعة
شرح الوحدة الرابعةشرح الوحدة الرابعة
شرح الوحدة الرابعة
 
شرح الوحدة الرابعة
شرح الوحدة الرابعةشرح الوحدة الرابعة
شرح الوحدة الرابعة
 

Chapter2

  • 1. Chapter 2 An Overview of C++ Ragia A. Ibrahim, Ph.D. Student ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 2. ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ 2 Is prime? Start “Enter Positive Integer Number” Store Value In N i<n i=2 prime= true i++ prime= false n mod i = 0 print prime Stop
  • 3. Introduction • The programming language C++ was developed as extension of C. • C++ provides capabilities for object oriented programming. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 4. C++ is hybrid language which has structured style, an object-oriented style or both Introduction ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
  • 5. Programming example: converting units of measurement • Problem statement: you work in a store that imports textile most of the textile you receive is measured in square meters. However, the store’s customers want to know the equivalent amount in square yards. You need to write an algorithm that performs this conversion ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 6. Problem analysis: • Problem input: • The textile size in square meters • Problem output: • The textile size in square yards • Relevant formula: • 1 square yards= 1.196 square meter ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 7. Program // this program converts square meters to square yards # include <iostream.h> Int main() { float m,y; cout<<“enter the textile size in square meters:n”; cin>>m; y = 1.196*m; cout<<“the textile size in square yards is”<<y; return 0; } ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 8. Output window Enter the textile size in square meters: 2.0 The textile size in square yards is 2.392 ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 9. Data Types and Variables Declaration ExampleDetailsData type Ch=‘K’; ch=‘k’; char ch;8 bitschar n=9;Int n;Short 16, 32 bits long 64 bits (10 digits) Int s=4.7float s;(machine Dependent) float s; (6 digits). float f=0;0 0 false 1 true bool f;bool f;bool Sign -1 Magnitude-31 Sign -1 Exponent 23 Fraction-8 ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 10. Arithmetic operators operation C++ operator expression Addition + X+y Subtraction - X-y Multiplication * X*y Division / x/y Modulus % X%y ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
  • 11. Assignment operators • Sum = i = 0; • Sum = (i=0); Precedence order last2nd1st + ,-*,/,%() Associates RIGHT to LEFT ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 12. Relational Operators Operation C++ operator Expression Equality == X==y inequality != X!=y Greater than > X>y Less than < X<y Greater than or equal to >= X>=y Less than or equal to <= X<=y ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
  • 13. Logical operators Operation C++ operator Expression Logical negation ! !x Logical and && X && y Logical or || X || y ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
  • 14. Shorthand Assignment Operators • lhs op = rhs • +=,-=,*=,/=,%=,>>=,<<=,&=,|=,and ^= • P *=x; • lhs = lhs op rhs e.g. p *=x; p=p*x; p+=x; p=p+x; ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 15. Postfix and Prefix Assignment i++ or ++i is equivalent to i + = 1 i-- or --i is equivalent to i - = 1 ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 16. Postfix and Prefix Assignment //pre-incrementing and post-incrementing #include <iostream.h> Int main() { int c=5; cout<<c; cout <<c++; cout <<c<<endle; c=5; cout <<c; cout <<++c; cout <<c; return 0; } 5 5 6 5 6 6 Output window ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
  • 17. The Evaluation Order of Operators Operator type Operation Associativity Prefix ++, -- Unary ! Left to right Arithmetic * , / , % , + , - Left to right Relational < , > , <= , >=,==,!= Left to right Logical && || Left to right Assignment postfix =, +=, -=, *=, /=, %= Right to left ++ , -- ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
  • 18. Expression Value X>y || z<=y 0||1 1 --x || y&&z 0||1 1 ++x + y > !z /w 2 + 3> 0/4 1 E.g. x=1 y=2 z=3 w=4 ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬
  • 19. ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬ Function?. Function body consists of declaration and statements enclosed between { } Variable type f_name(tyep1,type2…) { } e.g. Int main() { }
  • 20. ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ ‫االحصائيه‬ HW…please try to solve the following from the text book: 1 4 5 7