SlideShare a Scribd company logo
1
Basic terms in coding
• What is programming?
• Programming language is a tool used to create a program by writing human
like language in a specific structure (syntax) using an editor that will translate
the human language to binary language of zeros and ones, which is the
computer language.
• Programming is using a code or source code, which is a sequence of
instructions to develop a program that will provide an output solution using
several tools such as a programming language & programming language
editor.
• output: The messages printed to the user by a program.
• console: The text box onto which output is printed.
• syntax: The set of legal structures and commands that can be used in a particular
programming language. 2
What is the differences between C#, C++,
and C?
• C and C++ differences:
• C++ was built as an extension of C, which means it can run most C code.
• C++ supports reference variables, which C does not.
• C uses functions for input and output, whereas C++ uses objects for input and output.
• C does not provide error or exception handling, but C++ does.
• As an object-oriented language, C++ supports polymorphism, encapsulation, and inheritance, while C does not.
• C++ and C# differences:
• C++ compiles into machine code, while C# compiles to CLR, which is interpreted by ASP.NET.
• C++ can be used on any platform, though it was originally designed for Unix-based systems. C# is standardized but is
rarely used outside of Windows environments.
• C++ can create stand-alone and console applications. C# can create a console, Windows, ASP.NET, and mobile
applications, but cannot create stand-alone apps.
• C++ requires you to handle memory manually, but C# runs in a virtual machine which can automatically handle
memory management. 3
Structure of a C++ Program
4
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World! ";
return (0);
}
Used to group
statements
Comment line
Execution begin
Standard output stream in C++
• Select Execute> Compile,
to compile your program.
• Select Execute> Run, to
run your program.
Hello World!
Output:
Comments
• C++ support two ways to insert comments:
• // line comment
• /* block Comment */
5
/* my second program in C++
With more comment */
#include <iostream>
using namespace std;
int main (){
cout << "Hello World! "; //says Hello World
cout << "I am a C++ program "; // says I am a C++ program
}
Hello World! I am a C++ program
Example: Output:
Good Programming Practice
• Every program should begin with a comment that explains the purpose of
program, author and creation date and last update date.
• Example:
/* Created By: Maryam AlMahdi
Creation Date: 7 July 2021
Last Updated Date: 29 July 2021
Description: ................
*/
6
Output Statement: (cout)
7
cout<<expression<<expression…..;
cout<< “First sentence. ”;
cout<< “Second sentence. Third sentence.”;
Example:
After adding Escape Sequences:
cout<< “First sentence. n ”;
cout<< “Second sentence. n Third sentence.”;
cout<< “First sentence.”;
cout<< “nSecond sentence. t Third sentence.”;
cout<< 123;
cout<< “The result is =“ << 12+14;
Output Statement:
Escape Sequences
8
n New line
r Carriage return
t tabulation
v Vertical tabulation
b backspace
f Page feed
a Alert (beep)
’ Single quote(‘)
” Double quote (“)
? Question (?)
 Inverted slash
Variables, Constants, Data types
• Variable:
A memory location whose content may change during program execution.
• Constant:
A memory location whose content is not allowed to change during program
execution.
• An Identifier:
is a sequence of one or more letters, digits or underline symbols ( _ ), and must
begin with a letter or underscore.
9
Variables, Constants, Data types:
Identifier
• The length of an identifier is not limited, although for some compilers only the 32
first characters of an identifier are significant (the rest are not considered).
• Neither spaces nor marked letters can be part of an identifier. Only letters, digits
and underline characters are valid.
• Identifier should not match any reserved key word of the C++ language.
• The C++ language is "case sensitive", that means that an identifier written in
capital letters is not equivalent to another one with the same name but written in
small letters.
10
Variables, Constants, Data types:
Declaration of Variable
11
DataType identifier, identifier,….;
Example:
int a;
char ch,x,y;
short NumberOfSons;
int MyAccountBalance;
Variables, Constants, Data types: Data Type
12
Name Bytes* Description Range
char 1 character or integer 8 bits length. signed: -128 to 127 unsigned: 0 to 255
short 2 integer 16 bits length. signed: -32768 to 32767 unsigned: 0
to 65535
long 4 integer 32 bits length. signed:-2147483648 to 2147483647
unsigned: 0 to 4294967295
int * Integer. Its length traditionally depends on the length of the system's Word type,
thus in MSDOS it is 16 bits long, whereas in 32 bit systems (like Windows
9x/2000/NT and systems that work under protected mode in x86 systems) it is 32
bits long (4 bytes).
See short, long
float 4 floating point number. 3.4e + / - 38 (7 digits)
double 8 double precision floating point number. 1.7e + / - 308 (15 digits)
Long double 10 long double precision floating point number. 1.2e + / - 4932 (19 digits)
bool 1 Boolean value. It can take one of two values: true or false NOTE: this is a type
recently added by the ANSI-C++ standard. Not all compilers support it. Consult
section bool
type for compatibility information.
true or false
string 8 stores text, such as "Hello World". String values are surrounded by double quotes.
This is not a built-in type, but it behaves like one in its most basic usage
“text”
Variables, Constants, Data types:
Declaration of Variable
13
// operating with variables
#include <iostream> using namespace std;
int main ()
{ // declaring variables:
int a,b;
int result;
// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;
// print out the result:
cout << result;
// terminate the program:
return(0)
}
output is 4
Variables, Constants, Data types:
Initialization of variables
14
• Example:
int x=0;
int x(0);
int a=5, b=2;
DataType= initial_value;
DataType (initial_value);
// operating with variables
#include <iostream> using namespace std;
int main ()
{// declaring variables:
int result;
// process:
int a(5);
int b(2);
a = a + 1;
result = a - b;
// print out the result:
cout << result;
// terminate the program:
}
Or int a(5),b(2);
Output Statement (Cont’d)
15
• Examples
cout<<expression<<expression..;
cout<<”Results”; //prints Results on screen
cout<<120; //prints number 120 on screen
cout<<a; //prints the content of variable a on screen
cout<<“a-b”<<result;
cout<<a<<“-”<<b<<“=“<<result;
Variables, Constants, Data types:
Declared Constant (const)
• With the const prefix you can declare constants with a specific type
exactly as you would do with a variable:
• Examples:
const int width = 100;
const int zip = 12440;
16
const dataTypes identifier = value;
Operators
• The Assignment (=) operator serves to assign a value to a variable.
• Assignation operation always takes place from right to left and never
at the inverse.
17
Variable = expression ;
Operators: Assignment operator
• Examples:
18
int a,b,c;
a=10;
b=4;
a=b;
b=7;
a=2+(b=5); // is equivalent to b=5;
a=2+b;
a=b=c=5; // assigns 5 to the three variables a, b and c.
cout<<a,b,c;
Operators:
Arithmetic and Relational Operators
• Arithmetic operators ( +, -, *, /, %)
Module (%) is the operation that gives the remainder of a division of two integer values,
• Example:
• Relational operators ( ==, !=, >, <, >=, <= )
• The result of a relational operation is a Boolean value that can only be true(1) or false(0).
19
int a=11%3; //a=2
cout<<a;
int a=(11<3); //will give us 0 as false
cout<<a<<“n”;
int b=(11>3); //will give us 1 as true
cout<<b;
Operators:
Logic operators
• Logic operators ( !, &&, || ).
They correspond with Boolean logic operations NOT, AND and OR Respectively
• Examples:
20
First Operand
a
Second
Operand b
result
a && b
result
a || b
true true true true
true false false true
false true false true
false false false false
int a( (5 == 5) && (3 > 6) ); // returns false ( true && false ).
cout<<a<<”n”;
int b( (5 == 6) || (3 != 6)); // returns true ( true || false ).
cout<<b;
Operators
• Compound assignation operators
(+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=)
• Increase(++) and decrease (--)
• They increase or reduce by 1 the value stored in a variable.
• They are equivalent to +=1 and to -=1, respectively.
• They can be used both as a prefix or (++a) as a suffix(a++).
21
value += increase; // is equivalent to value=value + increase;
a -= 5; // is equivalent to a=a-5;
a /= b; // is equivalent to a=a/b;
price *= units + 1; // is equivalent to price = price * (units + 1);
Operators
• Example 1:
equivalent to equivalent to
• Example 2: Example 3:
22
a++; a=a+1; a+=1;
int B=3;
int A=++B;
// A is 4, B is 4
cout<<A<<“n”<<B;
int B=3;
int A=B++;
// A is 3, B is 4
cout<<A<<“n”<<B;
Operators : Priority of operators
Priority Operator Description Associativity
1 () [ ] Left
2 ++ -- increment/decrement Right
~ Complement to one (bitwise)
! unary NOT
& * Reference and Dereference (pointers)
(type) Type casting
+ - Unary sign
3 * / % arithmetical operations Left
4 + - arithmetical operations Left
5 < <= > >= Relational operators Left
6 == != Relational operators Left
7 && || Logic operators Left
10 = += -= *= /= %=
>>= <<= &= ^= |=
Assignation Right
11 , Comma, Separator Left 23
Input Statement: (cin)
• cin only process the input from the keyboard once the RETURN key
has been pressed.
• Example 1:
• Example 2:
equivalent to
24
cin>> variable >>variable .... ;
int age;
cin >> age;
cin>> a >> b;
cin>> a;
cin>> b;
Input Statement: (cin)
25
#include <iostream>
using namespace std;
/* Created By: Maryam AlMahdi
Creation Date: 29 July 2021
Description: .. */
int main ()
{
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 << "n";
return 0;
}
Please enter an integer value: 702
The value you entered is 702 and its double is 1404.
Control Statements: Single-Selection statement
• It is used to execute an instruction or block of instructions only if a
condition is fulfilled.
• If the condition is false, statement is ignored (not executed) and the
program continues on the next instruction after the conditional
structure.
• Example 1: Example2:
26
If (condition ) statement
if (x == 100)
{
cout << "x is ";
cout << x;
}
if (x == 100)
cout << "x is 100";
Control Statements: Double-Selection statement
• Example1: Example2:
27
If (condition ) statement1 else statement2
if (x == 100)
cout << "x is 100";
else
cout << "x is not 100";
if (x > 0)
cout << "x is positive";
else if (x < 0)
cout << "x is negative";
else
cout << "x is 0";
Let’s review what we’ve learned
• Write a program that includes the following:
x=“Hello”
Name= takes input from the user
Print the statement Hello + the user name.
28
Let’s review what we’ve learned
• Solution:
#include <iostream>
using namespace std;
int main()
{
string x="Hello";
string Name;
cout<<"What is your name?"<<"t";
cin>> Name;
cout<<x<<"t"<<Name;
return 0;
}
29
Quick note:
In C++ every data type
has a specific number of
bytes to store as shown
in this hypertext link of
slide 13.Date Types.
Let’s review what we’ve learned
• Write a program as showing below:
a=2
b=5
c=8
Use if else statement to print “a is less than c”.
30
Let’s review what we’ve learned
• Solution:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
a=2;
b=5;
c=8;
if (a<c)
cout<<"a is less than c";
else
cout<<"a is greater than c";
return 0;
}
31
References
• Information Technology Infrastructure, Dr. Maryam AlOtaibi.
• A Complete guide to Programming in C++ y Ulla Kirch-Prinz & Peter
Prinz.
32
Contact info
• Maryam AlMahdi
• E-mail: mariam.almahdi@outlook.com
• Instagram: @gdgkwt_maryam
33
Variables, Constants, Data types: Data Type
34
Name Bytes* Description Range
char 1 character or integer 8 bits length. signed: -128 to 127 unsigned: 0 to 255
short 2 integer 16 bits length. signed: -32768 to 32767 unsigned: 0
to 65535
long 4 integer 32 bits length. signed:-2147483648 to 2147483647
unsigned: 0 to 4294967295
int * Integer. Its length traditionally depends on the length of the system's Word type,
thus in MSDOS it is 16 bits long, whereas in 32 bit systems (like Windows
9x/2000/NT and systems that work under protected mode in x86 systems) it is 32
bits long (4 bytes).
See short, long
float 4 floating point number. 3.4e + / - 38 (7 digits)
double 8 double precision floating point number. 1.7e + / - 308 (15 digits)
Long double 10 long double precision floating point number. 1.2e + / - 4932 (19 digits)
bool 1 Boolean value. It can take one of two values: true or false NOTE: this is a type
recently added by the ANSI-C++ standard. Not all compilers support it. Consult
section bool
type for compatibility information.
true or false
string 8 stores text, such as "Hello World". String values are surrounded by double quotes.
This is not a built-in type, but it behaves like one in its most basic usage
“text”

More Related Content

PPTX
Unit ii
sathisaran
 
PPTX
C Programming basics
Jitin Pillai
 
PPT
Basics of c++
Huba Akhtar
 
PPTX
C languaGE UNIT-1
Malikireddy Bramhananda Reddy
 
PPTX
C++ PROGRAMMING BASICS
Aami Kakakhel
 
ODP
Basic C Programming language
Abhishek Soni
 
DOCX
C-PROGRAM
shahzadebaujiti
 
PPTX
Introduction of c programming unit-ii ppt
JStalinAsstProfessor
 
Unit ii
sathisaran
 
C Programming basics
Jitin Pillai
 
Basics of c++
Huba Akhtar
 
C++ PROGRAMMING BASICS
Aami Kakakhel
 
Basic C Programming language
Abhishek Soni
 
C-PROGRAM
shahzadebaujiti
 
Introduction of c programming unit-ii ppt
JStalinAsstProfessor
 

What's hot (19)

ODP
(2) cpp imperative programming
Nico Ludwig
 
ODP
CProgrammingTutorial
Muthuselvam RS
 
PPT
Unit 4 Foc
JAYA
 
PPTX
C tokens
Manu1325
 
PDF
Learning c - An extensive guide to learn the C Language
Abhishek Dwivedi
 
PPT
Beginner C++ easy slide and simple definition with questions
khawajasharif
 
PPT
Introduction to C
Janani Satheshkumar
 
PPS
basics of C and c++ by eteaching
eteaching
 
PPT
Javascript by Yahoo
birbal
 
PPSX
Complete C++ programming Language Course
Vivek Singh Chandel
 
PDF
Introduction to C programming
Kathmandu University
 
PPTX
Introduction to C Programming
Aniket Patne
 
PPTX
C++ Basics introduction to typecasting Webinar Slides 1
Ali Raza Jilani
 
PPTX
C++ lecture 01
HNDE Labuduwa Galle
 
ODP
OpenGurukul : Language : C Programming
Open Gurukul
 
PPT
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
PPT
C program
AJAL A J
 
PPTX
C++ programming language basic to advance level
sajjad ali khan
 
PPTX
C++ Basics
Himanshu Sharma
 
(2) cpp imperative programming
Nico Ludwig
 
CProgrammingTutorial
Muthuselvam RS
 
Unit 4 Foc
JAYA
 
C tokens
Manu1325
 
Learning c - An extensive guide to learn the C Language
Abhishek Dwivedi
 
Beginner C++ easy slide and simple definition with questions
khawajasharif
 
Introduction to C
Janani Satheshkumar
 
basics of C and c++ by eteaching
eteaching
 
Javascript by Yahoo
birbal
 
Complete C++ programming Language Course
Vivek Singh Chandel
 
Introduction to C programming
Kathmandu University
 
Introduction to C Programming
Aniket Patne
 
C++ Basics introduction to typecasting Webinar Slides 1
Ali Raza Jilani
 
C++ lecture 01
HNDE Labuduwa Galle
 
OpenGurukul : Language : C Programming
Open Gurukul
 
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
C program
AJAL A J
 
C++ programming language basic to advance level
sajjad ali khan
 
C++ Basics
Himanshu Sharma
 
Ad

Similar to #Code2 create c++ for beginners (20)

PPTX
POLITEKNIK MALAYSIA
Aiman Hud
 
PPT
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
PPSX
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
PDF
Lecture1
Amisha Dalal
 
PPTX
Lecture 2 variables
Tony Apreku
 
PPT
Basics of C.ppt
8759000398
 
PPTX
Fundamentals of computers - C Programming
MSridhar18
 
PPTX
C Programming Unit-1
Vikram Nandini
 
PPTX
C programming language
Abin Rimal
 
PDF
CP c++ programing project Unit 1 intro.pdf
ShivamYadav886008
 
PPT
Introduction to C Programming
MOHAMAD NOH AHMAD
 
PPTX
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
PPTX
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
PDF
C-PPT.pdf
chaithracs3
 
PPT
Ch2 introduction to c
Hattori Sidek
 
PDF
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
kiranrajat
 
PPT
Ffghhhhfghhfffhjdsdhjkgffjjjkfdghhftgdhhhggg didi ucch JFK bcom
GauravKumar295392
 
PPTX
C programming tutorial for Beginner
sophoeutsen2
 
PPTX
computer ppt group22222222222222222222 (1).pptx
JoyLedda3
 
PPTX
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
JessylyneSophia
 
POLITEKNIK MALAYSIA
Aiman Hud
 
M.Florence Dayana / Basics of C Language
Dr.Florence Dayana
 
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
Lecture1
Amisha Dalal
 
Lecture 2 variables
Tony Apreku
 
Basics of C.ppt
8759000398
 
Fundamentals of computers - C Programming
MSridhar18
 
C Programming Unit-1
Vikram Nandini
 
C programming language
Abin Rimal
 
CP c++ programing project Unit 1 intro.pdf
ShivamYadav886008
 
Introduction to C Programming
MOHAMAD NOH AHMAD
 
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
 
BCP_u2.pptxBCP_u2.pptxBCP_u2.pptxBCP_u2.pptx
RutviBaraiya
 
C-PPT.pdf
chaithracs3
 
Ch2 introduction to c
Hattori Sidek
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
kiranrajat
 
Ffghhhhfghhfffhjdsdhjkgffjjjkfdghhftgdhhhggg didi ucch JFK bcom
GauravKumar295392
 
C programming tutorial for Beginner
sophoeutsen2
 
computer ppt group22222222222222222222 (1).pptx
JoyLedda3
 
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
JessylyneSophia
 
Ad

More from GDGKuwaitGoogleDevel (11)

PDF
معسكر أساسيات البرمجة في لغة بايثون.pdf
GDGKuwaitGoogleDevel
 
PPTX
i/o extended: Intro to <UX> Design
GDGKuwaitGoogleDevel
 
PDF
#Code2Create:: Introduction to App Development in Flutter with Dart
GDGKuwaitGoogleDevel
 
PPTX
#Code2Create: Python Basics
GDGKuwaitGoogleDevel
 
PPTX
Building arcade game using python workshop
GDGKuwaitGoogleDevel
 
PDF
Wordpress website development workshop by Seham Abdlnaeem
GDGKuwaitGoogleDevel
 
PPTX
WTM/IWD 202: Introduction to digital accessibility by Dr. Zainab AlMeraj
GDGKuwaitGoogleDevel
 
PPTX
GDG Kuwait - Modern android development
GDGKuwaitGoogleDevel
 
PDF
DevFest Kuwait 2020 - Building (Progressive) Web Apps
GDGKuwaitGoogleDevel
 
PPTX
DevFest Kuwait 2020- Cloud Study Jam: Kubernetes on Google Cloud
GDGKuwaitGoogleDevel
 
PPTX
DevFest Kuwait 2020 - GDG Kuwait
GDGKuwaitGoogleDevel
 
معسكر أساسيات البرمجة في لغة بايثون.pdf
GDGKuwaitGoogleDevel
 
i/o extended: Intro to <UX> Design
GDGKuwaitGoogleDevel
 
#Code2Create:: Introduction to App Development in Flutter with Dart
GDGKuwaitGoogleDevel
 
#Code2Create: Python Basics
GDGKuwaitGoogleDevel
 
Building arcade game using python workshop
GDGKuwaitGoogleDevel
 
Wordpress website development workshop by Seham Abdlnaeem
GDGKuwaitGoogleDevel
 
WTM/IWD 202: Introduction to digital accessibility by Dr. Zainab AlMeraj
GDGKuwaitGoogleDevel
 
GDG Kuwait - Modern android development
GDGKuwaitGoogleDevel
 
DevFest Kuwait 2020 - Building (Progressive) Web Apps
GDGKuwaitGoogleDevel
 
DevFest Kuwait 2020- Cloud Study Jam: Kubernetes on Google Cloud
GDGKuwaitGoogleDevel
 
DevFest Kuwait 2020 - GDG Kuwait
GDGKuwaitGoogleDevel
 

Recently uploaded (20)

PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Software Development Company | KodekX
KodekX
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
Stamford - Community User Group Leaders_ Agentblazer Status, AI Sustainabilit...
Amol Dixit
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
PDF
Doc9.....................................
SofiaCollazos
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Software Development Company | KodekX
KodekX
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Stamford - Community User Group Leaders_ Agentblazer Status, AI Sustainabilit...
Amol Dixit
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
Doc9.....................................
SofiaCollazos
 

#Code2 create c++ for beginners

  • 1. 1
  • 2. Basic terms in coding • What is programming? • Programming language is a tool used to create a program by writing human like language in a specific structure (syntax) using an editor that will translate the human language to binary language of zeros and ones, which is the computer language. • Programming is using a code or source code, which is a sequence of instructions to develop a program that will provide an output solution using several tools such as a programming language & programming language editor. • output: The messages printed to the user by a program. • console: The text box onto which output is printed. • syntax: The set of legal structures and commands that can be used in a particular programming language. 2
  • 3. What is the differences between C#, C++, and C? • C and C++ differences: • C++ was built as an extension of C, which means it can run most C code. • C++ supports reference variables, which C does not. • C uses functions for input and output, whereas C++ uses objects for input and output. • C does not provide error or exception handling, but C++ does. • As an object-oriented language, C++ supports polymorphism, encapsulation, and inheritance, while C does not. • C++ and C# differences: • C++ compiles into machine code, while C# compiles to CLR, which is interpreted by ASP.NET. • C++ can be used on any platform, though it was originally designed for Unix-based systems. C# is standardized but is rarely used outside of Windows environments. • C++ can create stand-alone and console applications. C# can create a console, Windows, ASP.NET, and mobile applications, but cannot create stand-alone apps. • C++ requires you to handle memory manually, but C# runs in a virtual machine which can automatically handle memory management. 3
  • 4. Structure of a C++ Program 4 // my first program in C++ #include <iostream> using namespace std; int main () { cout << "Hello World! "; return (0); } Used to group statements Comment line Execution begin Standard output stream in C++ • Select Execute> Compile, to compile your program. • Select Execute> Run, to run your program. Hello World! Output:
  • 5. Comments • C++ support two ways to insert comments: • // line comment • /* block Comment */ 5 /* my second program in C++ With more comment */ #include <iostream> using namespace std; int main (){ cout << "Hello World! "; //says Hello World cout << "I am a C++ program "; // says I am a C++ program } Hello World! I am a C++ program Example: Output:
  • 6. Good Programming Practice • Every program should begin with a comment that explains the purpose of program, author and creation date and last update date. • Example: /* Created By: Maryam AlMahdi Creation Date: 7 July 2021 Last Updated Date: 29 July 2021 Description: ................ */ 6
  • 7. Output Statement: (cout) 7 cout<<expression<<expression…..; cout<< “First sentence. ”; cout<< “Second sentence. Third sentence.”; Example: After adding Escape Sequences: cout<< “First sentence. n ”; cout<< “Second sentence. n Third sentence.”; cout<< “First sentence.”; cout<< “nSecond sentence. t Third sentence.”; cout<< 123; cout<< “The result is =“ << 12+14;
  • 8. Output Statement: Escape Sequences 8 n New line r Carriage return t tabulation v Vertical tabulation b backspace f Page feed a Alert (beep) ’ Single quote(‘) ” Double quote (“) ? Question (?) Inverted slash
  • 9. Variables, Constants, Data types • Variable: A memory location whose content may change during program execution. • Constant: A memory location whose content is not allowed to change during program execution. • An Identifier: is a sequence of one or more letters, digits or underline symbols ( _ ), and must begin with a letter or underscore. 9
  • 10. Variables, Constants, Data types: Identifier • The length of an identifier is not limited, although for some compilers only the 32 first characters of an identifier are significant (the rest are not considered). • Neither spaces nor marked letters can be part of an identifier. Only letters, digits and underline characters are valid. • Identifier should not match any reserved key word of the C++ language. • The C++ language is "case sensitive", that means that an identifier written in capital letters is not equivalent to another one with the same name but written in small letters. 10
  • 11. Variables, Constants, Data types: Declaration of Variable 11 DataType identifier, identifier,….; Example: int a; char ch,x,y; short NumberOfSons; int MyAccountBalance;
  • 12. Variables, Constants, Data types: Data Type 12 Name Bytes* Description Range char 1 character or integer 8 bits length. signed: -128 to 127 unsigned: 0 to 255 short 2 integer 16 bits length. signed: -32768 to 32767 unsigned: 0 to 65535 long 4 integer 32 bits length. signed:-2147483648 to 2147483647 unsigned: 0 to 4294967295 int * Integer. Its length traditionally depends on the length of the system's Word type, thus in MSDOS it is 16 bits long, whereas in 32 bit systems (like Windows 9x/2000/NT and systems that work under protected mode in x86 systems) it is 32 bits long (4 bytes). See short, long float 4 floating point number. 3.4e + / - 38 (7 digits) double 8 double precision floating point number. 1.7e + / - 308 (15 digits) Long double 10 long double precision floating point number. 1.2e + / - 4932 (19 digits) bool 1 Boolean value. It can take one of two values: true or false NOTE: this is a type recently added by the ANSI-C++ standard. Not all compilers support it. Consult section bool type for compatibility information. true or false string 8 stores text, such as "Hello World". String values are surrounded by double quotes. This is not a built-in type, but it behaves like one in its most basic usage “text”
  • 13. Variables, Constants, Data types: Declaration of Variable 13 // operating with variables #include <iostream> using namespace std; int main () { // declaring variables: int a,b; int result; // process: a = 5; b = 2; a = a + 1; result = a - b; // print out the result: cout << result; // terminate the program: return(0) } output is 4
  • 14. Variables, Constants, Data types: Initialization of variables 14 • Example: int x=0; int x(0); int a=5, b=2; DataType= initial_value; DataType (initial_value); // operating with variables #include <iostream> using namespace std; int main () {// declaring variables: int result; // process: int a(5); int b(2); a = a + 1; result = a - b; // print out the result: cout << result; // terminate the program: } Or int a(5),b(2);
  • 15. Output Statement (Cont’d) 15 • Examples cout<<expression<<expression..; cout<<”Results”; //prints Results on screen cout<<120; //prints number 120 on screen cout<<a; //prints the content of variable a on screen cout<<“a-b”<<result; cout<<a<<“-”<<b<<“=“<<result;
  • 16. Variables, Constants, Data types: Declared Constant (const) • With the const prefix you can declare constants with a specific type exactly as you would do with a variable: • Examples: const int width = 100; const int zip = 12440; 16 const dataTypes identifier = value;
  • 17. Operators • The Assignment (=) operator serves to assign a value to a variable. • Assignation operation always takes place from right to left and never at the inverse. 17 Variable = expression ;
  • 18. Operators: Assignment operator • Examples: 18 int a,b,c; a=10; b=4; a=b; b=7; a=2+(b=5); // is equivalent to b=5; a=2+b; a=b=c=5; // assigns 5 to the three variables a, b and c. cout<<a,b,c;
  • 19. Operators: Arithmetic and Relational Operators • Arithmetic operators ( +, -, *, /, %) Module (%) is the operation that gives the remainder of a division of two integer values, • Example: • Relational operators ( ==, !=, >, <, >=, <= ) • The result of a relational operation is a Boolean value that can only be true(1) or false(0). 19 int a=11%3; //a=2 cout<<a; int a=(11<3); //will give us 0 as false cout<<a<<“n”; int b=(11>3); //will give us 1 as true cout<<b;
  • 20. Operators: Logic operators • Logic operators ( !, &&, || ). They correspond with Boolean logic operations NOT, AND and OR Respectively • Examples: 20 First Operand a Second Operand b result a && b result a || b true true true true true false false true false true false true false false false false int a( (5 == 5) && (3 > 6) ); // returns false ( true && false ). cout<<a<<”n”; int b( (5 == 6) || (3 != 6)); // returns true ( true || false ). cout<<b;
  • 21. Operators • Compound assignation operators (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=) • Increase(++) and decrease (--) • They increase or reduce by 1 the value stored in a variable. • They are equivalent to +=1 and to -=1, respectively. • They can be used both as a prefix or (++a) as a suffix(a++). 21 value += increase; // is equivalent to value=value + increase; a -= 5; // is equivalent to a=a-5; a /= b; // is equivalent to a=a/b; price *= units + 1; // is equivalent to price = price * (units + 1);
  • 22. Operators • Example 1: equivalent to equivalent to • Example 2: Example 3: 22 a++; a=a+1; a+=1; int B=3; int A=++B; // A is 4, B is 4 cout<<A<<“n”<<B; int B=3; int A=B++; // A is 3, B is 4 cout<<A<<“n”<<B;
  • 23. Operators : Priority of operators Priority Operator Description Associativity 1 () [ ] Left 2 ++ -- increment/decrement Right ~ Complement to one (bitwise) ! unary NOT & * Reference and Dereference (pointers) (type) Type casting + - Unary sign 3 * / % arithmetical operations Left 4 + - arithmetical operations Left 5 < <= > >= Relational operators Left 6 == != Relational operators Left 7 && || Logic operators Left 10 = += -= *= /= %= >>= <<= &= ^= |= Assignation Right 11 , Comma, Separator Left 23
  • 24. Input Statement: (cin) • cin only process the input from the keyboard once the RETURN key has been pressed. • Example 1: • Example 2: equivalent to 24 cin>> variable >>variable .... ; int age; cin >> age; cin>> a >> b; cin>> a; cin>> b;
  • 25. Input Statement: (cin) 25 #include <iostream> using namespace std; /* Created By: Maryam AlMahdi Creation Date: 29 July 2021 Description: .. */ int main () { int i; cout << "Please enter an integer value: "; cin >> i; cout << "The value you entered is " << i; cout << " and its double is " << i*2 << "n"; return 0; } Please enter an integer value: 702 The value you entered is 702 and its double is 1404.
  • 26. Control Statements: Single-Selection statement • It is used to execute an instruction or block of instructions only if a condition is fulfilled. • If the condition is false, statement is ignored (not executed) and the program continues on the next instruction after the conditional structure. • Example 1: Example2: 26 If (condition ) statement if (x == 100) { cout << "x is "; cout << x; } if (x == 100) cout << "x is 100";
  • 27. Control Statements: Double-Selection statement • Example1: Example2: 27 If (condition ) statement1 else statement2 if (x == 100) cout << "x is 100"; else cout << "x is not 100"; if (x > 0) cout << "x is positive"; else if (x < 0) cout << "x is negative"; else cout << "x is 0";
  • 28. Let’s review what we’ve learned • Write a program that includes the following: x=“Hello” Name= takes input from the user Print the statement Hello + the user name. 28
  • 29. Let’s review what we’ve learned • Solution: #include <iostream> using namespace std; int main() { string x="Hello"; string Name; cout<<"What is your name?"<<"t"; cin>> Name; cout<<x<<"t"<<Name; return 0; } 29 Quick note: In C++ every data type has a specific number of bytes to store as shown in this hypertext link of slide 13.Date Types.
  • 30. Let’s review what we’ve learned • Write a program as showing below: a=2 b=5 c=8 Use if else statement to print “a is less than c”. 30
  • 31. Let’s review what we’ve learned • Solution: #include <iostream> using namespace std; int main() { int a,b,c; a=2; b=5; c=8; if (a<c) cout<<"a is less than c"; else cout<<"a is greater than c"; return 0; } 31
  • 32. References • Information Technology Infrastructure, Dr. Maryam AlOtaibi. • A Complete guide to Programming in C++ y Ulla Kirch-Prinz & Peter Prinz. 32
  • 33. Contact info • Maryam AlMahdi • E-mail: [email protected] • Instagram: @gdgkwt_maryam 33
  • 34. Variables, Constants, Data types: Data Type 34 Name Bytes* Description Range char 1 character or integer 8 bits length. signed: -128 to 127 unsigned: 0 to 255 short 2 integer 16 bits length. signed: -32768 to 32767 unsigned: 0 to 65535 long 4 integer 32 bits length. signed:-2147483648 to 2147483647 unsigned: 0 to 4294967295 int * Integer. Its length traditionally depends on the length of the system's Word type, thus in MSDOS it is 16 bits long, whereas in 32 bit systems (like Windows 9x/2000/NT and systems that work under protected mode in x86 systems) it is 32 bits long (4 bytes). See short, long float 4 floating point number. 3.4e + / - 38 (7 digits) double 8 double precision floating point number. 1.7e + / - 308 (15 digits) Long double 10 long double precision floating point number. 1.2e + / - 4932 (19 digits) bool 1 Boolean value. It can take one of two values: true or false NOTE: this is a type recently added by the ANSI-C++ standard. Not all compilers support it. Consult section bool type for compatibility information. true or false string 8 stores text, such as "Hello World". String values are surrounded by double quotes. This is not a built-in type, but it behaves like one in its most basic usage “text”