SlideShare a Scribd company logo
C++ BASICS
CSCI 107
A C++ PROGRAM
//include headers; these are modules that include functions that you may use in your
//program; we will almost always need to include the header that
// defines cin and cout; the header is called iostream.h
#include <iostream.h>
int main() {
//variable declaration
//read values input from user
//computation and print output to user
return 0;
}
After you write a C++ program you compile it; that is, you run a program called compiler that
checks whether the program follows the C++ syntax
• if it finds errors, it lists them
• If there are no errors, it translates the C++ program into a program in machine language
which you can execute
NOTES
• what follows after // on the same line is considered comment
• indentation is for the convenience of the reader; compiler ignores all spaces and
new line ; the delimiter for the compiler is the semicolon
• all statements ended by semicolon
• Lower vs. upper case matters!!
• Void is different than void
• Main is different that main
THE INFAMOUS
HELLO WORLD PROGRAM
When learning a new language, the first program people usually write
is one that salutes the world :)
Here is the Hello world program in C++.
#include <iostream.h>
int main() {
cout << “Hello world!”;
return 0;
}
VARIABLE DECLARATION
type variable-name;
Meaning: variable <variable-name> will be a variable of type <type>
Where type can be:
• int //integer
• double //real number
• char //character
Example:
int a, b, c;
double x;
int sum;
char my-character;
INPUT STATEMENTS
cin >> variable-name;
Meaning: read the value of the variable called <variable-
name> from the user
Example:
cin >> a;
cin >> b >> c;
cin >> x;
cin >> my-character;
OUTPUT STATEMENTS
cout << variable-name;
Meaning: print the value of variable <variable-name> to the user
cout << “any message “;
Meaning: print the message within quotes to the user
cout << endl;
Meaning: print a new line
Example:
cout << a;
cout << b << c;
cout << “This is my character: “ << my-character << “ he he he”
<< endl;
IF STATEMENTS
if (condition) {
S1;
}
else {
S2;
}
S3;
condition
S1 S2
S3
True False
BOOLEAN CONDITIONS
..are built using
• Comparison operators
== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
• Boolean operators
&& and
|| or
! not
EXAMPLES
Assume we declared the following variables:
int a = 2, b=5, c=10;
Here are some examples of boolean conditions we can use:
• if (a == b) …
• if (a != b) …
• if (a <= b+c) …
• if(a <= b) && (b <= c) …
• if !((a < b) && (b<c)) …
IF EXAMPLE
#include <iostream.h>
void main() {
int a,b,c;
cin >> a >> b >> c;
if (a <=b) {
cout << “min is “ << a << endl;
}
else {
cout << “ min is “ << b << endl;
}
cout << “happy now?” << endl;
}
WHILE STATEMENTS
while (condition) {
S1;
}
S2;
condition
S1
S2
True False
WHILE EXAMPLE
//read 100 numbers from the user and output their sum
#include <iostream.h>
void main() {
int i, sum, x;
sum=0;
i=1;
while (i <= 100) {
cin >> x;
sum = sum + x;
i = i+1;
}
cout << “sum is “ << sum << endl;
}
EXERCISE
• Write a program that asks the user
• Do you want to use this program? (y/n)
• If the user says ‘y’ then the program terminates
• If the user says ‘n’ then the program asks
• Are you really sure you do not want to use this program? (y/n)
• If the user says ‘n’ it terminates, otherwise it prints again the
message
• Are you really really sure you do not want to use this program?
(y/n)
• And so on, every time adding one more “really”.

More Related Content

What's hot

Connecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with EmbindConnecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with Embind
Chad Austin
 
Computer programming k 12
Computer programming k 12Computer programming k 12
Computer programming k 12
lemonmichelangelo
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
Paul Graham
 
escape sequences and substitution markers
escape sequences and substitution markersescape sequences and substitution markers
escape sequences and substitution markers
Micheal Ogundero
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
aeden_brines
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
David Voyles
 
Introduction to C++,Computer Science
Introduction to C++,Computer ScienceIntroduction to C++,Computer Science
Introduction to C++,Computer Science
Abhinav Vishnoi
 
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
Micheal Ogundero
 
C++ basics
C++ basicsC++ basics
C++ basics
husnara mohammad
 
GCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programsGCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programs
Daniel Ilunga
 
Fix: static code analysis into our project
Fix: static code analysis into our project Fix: static code analysis into our project
Fix: static code analysis into our project
noelchris3
 
180 daraga cpp course session-1
180 daraga cpp course session-1180 daraga cpp course session-1
180 daraga cpp course session-1
Moustafa Ghoniem
 
selection structures
selection structuresselection structures
selection structures
Micheal Ogundero
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
Jomel Penalba
 
Chp1(c 2 c++)
Chp1(c 2 c++)Chp1(c 2 c++)
Chp1(c 2 c++)
Mohd Effandi
 
Designing and coding for cloud-native applications using Python, Harjinder Mi...
Designing and coding for cloud-native applications using Python, Harjinder Mi...Designing and coding for cloud-native applications using Python, Harjinder Mi...
Designing and coding for cloud-native applications using Python, Harjinder Mi...
Pôle Systematic Paris-Region
 
Class7
Class7Class7
Class7
guestb45499
 
Functions in C++ (OOP)
Functions in C++ (OOP)Functions in C++ (OOP)
Functions in C++ (OOP)
Faizan Janjua
 
Output
OutputOutput
人力
人力人力
人力
emasaka
 

What's hot (20)

Connecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with EmbindConnecting C++ and JavaScript on the Web with Embind
Connecting C++ and JavaScript on the Web with Embind
 
Computer programming k 12
Computer programming k 12Computer programming k 12
Computer programming k 12
 
C# 6.0
C# 6.0C# 6.0
C# 6.0
 
escape sequences and substitution markers
escape sequences and substitution markersescape sequences and substitution markers
escape sequences and substitution markers
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 
Introduction to C++,Computer Science
Introduction to C++,Computer ScienceIntroduction to C++,Computer Science
Introduction to C++,Computer Science
 
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
 
C++ basics
C++ basicsC++ basics
C++ basics
 
GCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programsGCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programs
 
Fix: static code analysis into our project
Fix: static code analysis into our project Fix: static code analysis into our project
Fix: static code analysis into our project
 
180 daraga cpp course session-1
180 daraga cpp course session-1180 daraga cpp course session-1
180 daraga cpp course session-1
 
selection structures
selection structuresselection structures
selection structures
 
05 control structures 2
05 control structures 205 control structures 2
05 control structures 2
 
Chp1(c 2 c++)
Chp1(c 2 c++)Chp1(c 2 c++)
Chp1(c 2 c++)
 
Designing and coding for cloud-native applications using Python, Harjinder Mi...
Designing and coding for cloud-native applications using Python, Harjinder Mi...Designing and coding for cloud-native applications using Python, Harjinder Mi...
Designing and coding for cloud-native applications using Python, Harjinder Mi...
 
Class7
Class7Class7
Class7
 
Functions in C++ (OOP)
Functions in C++ (OOP)Functions in C++ (OOP)
Functions in C++ (OOP)
 
Output
OutputOutput
Output
 
人力
人力人力
人力
 

Viewers also liked

How did you use media technologies in the planning and research, construction...
How did you use media technologies in the planning and research, construction...How did you use media technologies in the planning and research, construction...
How did you use media technologies in the planning and research, construction...
Madzipan
 
Evaluation
EvaluationEvaluation
Evaluation
Madzipan
 
Tralukya Hazarika
Tralukya HazarikaTralukya Hazarika
Tralukya Hazarika
Tralukya Hazarika
 
“EMBARAZOS EN LA ADOLESCENCIA “
“EMBARAZOS EN LA ADOLESCENCIA ““EMBARAZOS EN LA ADOLESCENCIA “
“EMBARAZOS EN LA ADOLESCENCIA “
sandibel garcia
 
Scott Moore relevant accomplishments bio
Scott Moore relevant accomplishments bioScott Moore relevant accomplishments bio
Scott Moore relevant accomplishments bio
Scott Moore
 
Susan Rep SS 2013
Susan Rep SS 2013Susan Rep SS 2013
Susan Rep SS 2013
Steven Bonamassa
 
Lookbook ss13 lmc-updated showrooms
Lookbook ss13 lmc-updated showroomsLookbook ss13 lmc-updated showrooms
Lookbook ss13 lmc-updated showrooms
Steven Bonamassa
 
La integración de españa
La integración de españaLa integración de españa
La integración de españa
jorgeghistoria
 
Los gobiernos democráticos
Los gobiernos democráticosLos gobiernos democráticos
Los gobiernos democráticos
jorgeghistoria
 
Franquismo (1939 1957)
Franquismo (1939 1957)Franquismo (1939 1957)
Franquismo (1939 1957)
jorgeghistoria
 
Propuestas y proyectos de intervencion docente
Propuestas y proyectos de intervencion docentePropuestas y proyectos de intervencion docente
Propuestas y proyectos de intervencion docente
Karen Canto Bocanegra
 
Gestão de Varejo Ambiental no Varejo e Supermercados
Gestão de Varejo Ambiental no Varejo e SupermercadosGestão de Varejo Ambiental no Varejo e Supermercados
Gestão de Varejo Ambiental no Varejo e Supermercados
Alain Winandy
 
Supportive Periodontal Treatment
Supportive Periodontal TreatmentSupportive Periodontal Treatment
Supportive Periodontal Treatment
Dr. Suhasis Mondal
 
Criteris geo juny2015
Criteris geo juny2015Criteris geo juny2015
Criteris geo juny2015
Txema Gs
 
Anthony Cronin
Anthony CroninAnthony Cronin
Anthony Cronin
Anthony Cronin
 

Viewers also liked (16)

How did you use media technologies in the planning and research, construction...
How did you use media technologies in the planning and research, construction...How did you use media technologies in the planning and research, construction...
How did you use media technologies in the planning and research, construction...
 
Evaluation
EvaluationEvaluation
Evaluation
 
Tralukya Hazarika
Tralukya HazarikaTralukya Hazarika
Tralukya Hazarika
 
“EMBARAZOS EN LA ADOLESCENCIA “
“EMBARAZOS EN LA ADOLESCENCIA ““EMBARAZOS EN LA ADOLESCENCIA “
“EMBARAZOS EN LA ADOLESCENCIA “
 
Scott Moore relevant accomplishments bio
Scott Moore relevant accomplishments bioScott Moore relevant accomplishments bio
Scott Moore relevant accomplishments bio
 
AttesterIngmar
AttesterIngmarAttesterIngmar
AttesterIngmar
 
Susan Rep SS 2013
Susan Rep SS 2013Susan Rep SS 2013
Susan Rep SS 2013
 
Lookbook ss13 lmc-updated showrooms
Lookbook ss13 lmc-updated showroomsLookbook ss13 lmc-updated showrooms
Lookbook ss13 lmc-updated showrooms
 
La integración de españa
La integración de españaLa integración de españa
La integración de españa
 
Los gobiernos democráticos
Los gobiernos democráticosLos gobiernos democráticos
Los gobiernos democráticos
 
Franquismo (1939 1957)
Franquismo (1939 1957)Franquismo (1939 1957)
Franquismo (1939 1957)
 
Propuestas y proyectos de intervencion docente
Propuestas y proyectos de intervencion docentePropuestas y proyectos de intervencion docente
Propuestas y proyectos de intervencion docente
 
Gestão de Varejo Ambiental no Varejo e Supermercados
Gestão de Varejo Ambiental no Varejo e SupermercadosGestão de Varejo Ambiental no Varejo e Supermercados
Gestão de Varejo Ambiental no Varejo e Supermercados
 
Supportive Periodontal Treatment
Supportive Periodontal TreatmentSupportive Periodontal Treatment
Supportive Periodontal Treatment
 
Criteris geo juny2015
Criteris geo juny2015Criteris geo juny2015
Criteris geo juny2015
 
Anthony Cronin
Anthony CroninAnthony Cronin
Anthony Cronin
 

Similar to C++basics

c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
TatyaTope4
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
EPORI
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
Infotech27
 
c++basiccs.ppt
c++basiccs.pptc++basiccs.ppt
c++basiccs.ppt
RaghavendraMR5
 
C++ Basics
C++ BasicsC++ Basics
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
cpjcollege
 
introductiontoc-140704113737-phpapp01.pdf
introductiontoc-140704113737-phpapp01.pdfintroductiontoc-140704113737-phpapp01.pdf
introductiontoc-140704113737-phpapp01.pdf
SameerKhanPathan7
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
Himanshu Kaushik
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
Marco Izzotti
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
Mohammad Shaker
 
Oops presentation
Oops presentationOops presentation
Oops presentation
sushamaGavarskar1
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
Abdullah Jan
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
C++
C++C++
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
rohassanie
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************
Emad Helal
 
Lesson 2 starting output
Lesson 2 starting outputLesson 2 starting output
Lesson 2 starting output
WayneJones104
 
C++ Chapter 3
C++ Chapter 3C++ Chapter 3
C++ Chapter 3
SHRIRANG PINJARKAR
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
GrejoJoby1
 

Similar to C++basics (20)

c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
c++basiccs.ppt
c++basiccs.pptc++basiccs.ppt
c++basiccs.ppt
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
introductiontoc-140704113737-phpapp01.pdf
introductiontoc-140704113737-phpapp01.pdfintroductiontoc-140704113737-phpapp01.pdf
introductiontoc-140704113737-phpapp01.pdf
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
C++
C++C++
C++
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************
 
Lesson 2 starting output
Lesson 2 starting outputLesson 2 starting output
Lesson 2 starting output
 
C++ Chapter 3
C++ Chapter 3C++ Chapter 3
C++ Chapter 3
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 

More from amna izzat

1 introduction ddbms
1 introduction ddbms1 introduction ddbms
1 introduction ddbms
amna izzat
 
Byte division
Byte divisionByte division
Byte division
amna izzat
 
Avl trees
Avl treesAvl trees
Avl trees
amna izzat
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)
amna izzat
 
Selection sort
Selection sortSelection sort
Selection sort
amna izzat
 
Bubble sort
Bubble sortBubble sort
Bubble sort
amna izzat
 

More from amna izzat (6)

1 introduction ddbms
1 introduction ddbms1 introduction ddbms
1 introduction ddbms
 
Byte division
Byte divisionByte division
Byte division
 
Avl trees
Avl treesAvl trees
Avl trees
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)
 
Selection sort
Selection sortSelection sort
Selection sort
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 

Recently uploaded

South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 

Recently uploaded (20)

South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 

C++basics

  • 2. A C++ PROGRAM //include headers; these are modules that include functions that you may use in your //program; we will almost always need to include the header that // defines cin and cout; the header is called iostream.h #include <iostream.h> int main() { //variable declaration //read values input from user //computation and print output to user return 0; } After you write a C++ program you compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax • if it finds errors, it lists them • If there are no errors, it translates the C++ program into a program in machine language which you can execute
  • 3. NOTES • what follows after // on the same line is considered comment • indentation is for the convenience of the reader; compiler ignores all spaces and new line ; the delimiter for the compiler is the semicolon • all statements ended by semicolon • Lower vs. upper case matters!! • Void is different than void • Main is different that main
  • 4. THE INFAMOUS HELLO WORLD PROGRAM When learning a new language, the first program people usually write is one that salutes the world :) Here is the Hello world program in C++. #include <iostream.h> int main() { cout << “Hello world!”; return 0; }
  • 5. VARIABLE DECLARATION type variable-name; Meaning: variable <variable-name> will be a variable of type <type> Where type can be: • int //integer • double //real number • char //character Example: int a, b, c; double x; int sum; char my-character;
  • 6. INPUT STATEMENTS cin >> variable-name; Meaning: read the value of the variable called <variable- name> from the user Example: cin >> a; cin >> b >> c; cin >> x; cin >> my-character;
  • 7. OUTPUT STATEMENTS cout << variable-name; Meaning: print the value of variable <variable-name> to the user cout << “any message “; Meaning: print the message within quotes to the user cout << endl; Meaning: print a new line Example: cout << a; cout << b << c; cout << “This is my character: “ << my-character << “ he he he” << endl;
  • 8. IF STATEMENTS if (condition) { S1; } else { S2; } S3; condition S1 S2 S3 True False
  • 9. BOOLEAN CONDITIONS ..are built using • Comparison operators == equal != not equal < less than > greater than <= less than or equal >= greater than or equal • Boolean operators && and || or ! not
  • 10. EXAMPLES Assume we declared the following variables: int a = 2, b=5, c=10; Here are some examples of boolean conditions we can use: • if (a == b) … • if (a != b) … • if (a <= b+c) … • if(a <= b) && (b <= c) … • if !((a < b) && (b<c)) …
  • 11. IF EXAMPLE #include <iostream.h> void main() { int a,b,c; cin >> a >> b >> c; if (a <=b) { cout << “min is “ << a << endl; } else { cout << “ min is “ << b << endl; } cout << “happy now?” << endl; }
  • 12. WHILE STATEMENTS while (condition) { S1; } S2; condition S1 S2 True False
  • 13. WHILE EXAMPLE //read 100 numbers from the user and output their sum #include <iostream.h> void main() { int i, sum, x; sum=0; i=1; while (i <= 100) { cin >> x; sum = sum + x; i = i+1; } cout << “sum is “ << sum << endl; }
  • 14. EXERCISE • Write a program that asks the user • Do you want to use this program? (y/n) • If the user says ‘y’ then the program terminates • If the user says ‘n’ then the program asks • Are you really sure you do not want to use this program? (y/n) • If the user says ‘n’ it terminates, otherwise it prints again the message • Are you really really sure you do not want to use this program? (y/n) • And so on, every time adding one more “really”.