SlideShare a Scribd company logo
1 of 32
Download to read offline
File Structure using C++
Simple Example
#include<iostream>
 #Include
 means read me before you compile and do what I say essentially.
 means that you're signaling the compiler to include some kind of file
or library that is needed in order for some function to execute in your
source file.
 < and >
 just enclosures for the compiler to read between and import
accordingly.
 *stream
 <iostream> is a library for basic input and out put controls since C++
alone contains no facilities for IO.
#include<iostream>
• The #include is a "preprocessor" directive that
tells the compiler to put code from the header
called iostream into our program before
actually creating the executable.
• By including header files, you gain access to
many different functions.
• For example, the cout function requires
iostream
using namespace std;
• This line tells the compiler to use a group of
functions that are part of the standard library
(std).
• By including this line at the top of a file, you
allow the program to use functions such as
cout
int main()
• This line tells the compiler that there is a
function named main, and that the function
returns an integer, hence int.
• The "curly braces" ({ and }) signal the
beginning and end of functions and other
code blocks.
Cout<<“Welcome C++”;
• The cout object is used to display text.
• It uses the << symbols, known as "insertion
operators", to indicate what to output.
Declaring Variables in C++
Variables in C++
• // operating with variables
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• // declaring variables:
• inta, b;
• Int result;
• // process:
• a = 5;
• b = 2;
• a = a + 1;
• result = a - b;
• // print out the result:
• cout << result;
• // terminate the program:
• return0;
• }
Scope of variables
Initialization of variables
• inta = 0;
• int a (0);
Initialization of variables
• // initialization of variables
• #include <iostream>
• using namespace std;
• intmain ()
• {
• inta=5; // initial value = 5
• Int b(2); // initial value = 2
• Int result; // initial value undetermined
• a = a + 3;
• result = a - b;
• cout << result;
• return0;
• }
Introduction to strings
• // my first string
• #include <iostream>
• #include <string>
• using namespace std;
• Int main ()
• {
• string mystring = "This is a string";
• cout << mystring;
• Return 0;
• }
Introduction to strings
• string mystring = "This is a string";
• string mystring ("This is a string");
Constants (#define)
• // defined constants: calculate circumference
• #include <iostream>
• using namespace std;
• #define PI 3.14159
• #define NEWLINE 'n'
• Int main ()
• {
• Double r=5.0; // radius
• Double circle;
• circle = 2 * PI * r;
• cout << circle;
• cout << NEWLINE;
• Return 0;
• }
Declared constants (const)
• const int pathwidth = 100;
• const char tabulator = 't';
Operators: Assignment (=)
• // assignment operator
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• inta, b; // a:?, b:?
• a = 10; // a:10, b:?
• b = 4; // a:10, b:4
• a = b; // a:4, b:4
• b = 7; // a:4, b:7
• cout << "a:";
• cout << a;
• cout << " b:";
• cout << b;
• return0;
• }
Compound assignment
• // compound assignment operators
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• inta, b=3;
• a = b;
• a+=2; // equivalent to a=a+2
• cout << a;
• return0;
• }
Increase and decrease (++, --)
Conditional operator ( ? )
• // conditional operator
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• inta,b,c;
• a=2;
• b=7;
• c = (a>b) ? a : b;
• cout << c;
• return0;
• }
Conditional operator ( ? )
• 7==5 ? 4 : 3 // returns 3, since 7 is not equal
to 5.
• 7==5+2 ? 4 : 3 // returns 4, since 7 is equal to
5+2.
• 5>3 ? a : b // returns the value of a, since 5 is
greater than 3.
• a>b ? a : b // returns whichever is greater, a
or b.
Basic Input/Output
• // i/o example
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• inti;
• cout << "Please enter an integer value: ";
• cin >> i;
• cout << "The value you entered is "<< i;
• cout << " and its double is "<< i*2 << ".n";
• return0;
• }
cin and strings
• // cin with strings
• #include <iostream>
• #include <string>
• using namespacestd;
• intmain ()
• {
• string mystr;
• cout << "What's your name? ";
• getline (cin, mystr);
• cout << "Hello "<< mystr << ".n";
• cout << "What is your favorite team? ";
• getline (cin, mystr);
• cout << "I like "<< mystr << " too!n";
• return0;
• }
Conditional structure: if and else
• if(x > 0)
• cout << "x is positive";
• else if(x < 0)
• cout << "x is negative";
• else
• cout << "x is 0";
The while loop
• // custom countdown using while
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• intn;
• cout << "Enter the starting number > ";
• cin >> n;
• while(n>0) {
• cout << n << ", ";
• --n;
• }
• cout << "FIRE!n";
• return0;
• }
The do-while loop
• // number echoer
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• unsigned longn;
• do{
• cout << "Enter number (0 to end): ";
• cin >> n;
• cout << "You entered: "<< n << "n";
• } while(n != 0);
• return0;
• }
The for loop
• // countdown using a for loop
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• for(intn=10; n>0; n--) {
• cout << n << ", ";
• }
• cout << "FIRE!n";
• return0;
• }
Jump statements (break)
• // break loop example
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• intn;
• for(n=10; n>0; n--)
• {
• cout << n << ", ";
• if(n==3)
• {
• cout << "countdown aborted!";
• break;
• }
• }
• return0;
• }
continue
• // continue loop example
• #include <iostream>
• using namespacestd;
• intmain ()
• {
• for(intn=10; n>0; n--) {
• if(n==5) continue;
• cout << n << ", ";
• }
• cout << "FIRE!n";
• return0;
• }
goto
• // goto loop example
• #include <iostream>
• using namespace std;
• Int main ()
• {
• Int n=10;
• loop:
• cout << n << ", ";
• n--;
• if(n>0) goto loop;
• cout << "FIRE!n";
• return0;
• }

More Related Content

What's hot

Python Coroutines, Present and Future
Python Coroutines, Present and FuturePython Coroutines, Present and Future
Python Coroutines, Present and Futureemptysquare
 
LvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncioLvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncioRoman Rader
 
Learning C++ - Functions in C++ 3
Learning C++ - Functions  in C++ 3Learning C++ - Functions  in C++ 3
Learning C++ - Functions in C++ 3Ali Aminian
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd StudyChris Ohk
 
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱Mohammad Reza Kamalifard
 
Dataflow: Declarative concurrency in Ruby
Dataflow: Declarative concurrency in RubyDataflow: Declarative concurrency in Ruby
Dataflow: Declarative concurrency in RubyLarry Diehl
 
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
Of Harmony and Stinginess: Applicative, Monad, and iterative library designOf Harmony and Stinginess: Applicative, Monad, and iterative library design
Of Harmony and Stinginess: Applicative, Monad, and iterative library designjspha
 
Finch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with FinagleFinch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with FinagleVladimir Kostyukov
 
Python Yield
Python YieldPython Yield
Python Yieldyangjuven
 
Advanced functional programing in Swift
Advanced functional programing in SwiftAdvanced functional programing in Swift
Advanced functional programing in SwiftVincent Pradeilles
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleSaúl Ibarra Corretgé
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th StudyChris Ohk
 
GoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGautam Rege
 

What's hot (20)

Python Coroutines, Present and Future
Python Coroutines, Present and FuturePython Coroutines, Present and Future
Python Coroutines, Present and Future
 
LvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncioLvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncio
 
Finch + Finagle OAuth2
Finch + Finagle OAuth2Finch + Finagle OAuth2
Finch + Finagle OAuth2
 
Learning C++ - Functions in C++ 3
Learning C++ - Functions  in C++ 3Learning C++ - Functions  in C++ 3
Learning C++ - Functions in C++ 3
 
C++ programming basics
C++ programming basicsC++ programming basics
C++ programming basics
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd Study
 
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
 
Number
NumberNumber
Number
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Dataflow: Declarative concurrency in Ruby
Dataflow: Declarative concurrency in RubyDataflow: Declarative concurrency in Ruby
Dataflow: Declarative concurrency in Ruby
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
Of Harmony and Stinginess: Applicative, Monad, and iterative library designOf Harmony and Stinginess: Applicative, Monad, and iterative library design
Of Harmony and Stinginess: Applicative, Monad, and iterative library design
 
Finch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with FinagleFinch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with Finagle
 
Python Yield
Python YieldPython Yield
Python Yield
 
Advanced functional programing in Swift
Advanced functional programing in SwiftAdvanced functional programing in Swift
Advanced functional programing in Swift
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
 
Queue oop
Queue   oopQueue   oop
Queue oop
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
 
GoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPH
 

Similar to Intro to C++

Similar to Intro to C++ (20)

Lec 2.pptx
Lec 2.pptxLec 2.pptx
Lec 2.pptx
 
C++ Functions.pptx
C++ Functions.pptxC++ Functions.pptx
C++ Functions.pptx
 
C++Basics.pdf
C++Basics.pdfC++Basics.pdf
C++Basics.pdf
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
Friend this-new&delete
Friend this-new&deleteFriend this-new&delete
Friend this-new&delete
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
C++basics
C++basicsC++basics
C++basics
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
 
C++ examples &revisions
C++ examples &revisionsC++ examples &revisions
C++ examples &revisions
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
C
CC
C
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 

More from Ahmed Farag

Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part IAhmed Farag
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operatorsAhmed Farag
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingAhmed Farag
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBAhmed Farag
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP conceptsAhmed Farag
 
Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Ahmed Farag
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams Ahmed Farag
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++Ahmed Farag
 

More from Ahmed Farag (14)

Intro to php
Intro to phpIntro to php
Intro to php
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
 
Normalization
NormalizationNormalization
Normalization
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part I
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
OOP C++
OOP C++OOP C++
OOP C++
 
Functions C++
Functions C++Functions C++
Functions C++
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...Nguyen Thanh Tu Collection
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroomSamsung Business USA
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...HetalPathak10
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsArubSultan
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Osopher
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Celine George
 
DiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfDiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfChristalin Nelson
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...Nguyen Thanh Tu Collection
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfChristalin Nelson
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
 
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
Satirical Depths - A Study of Gabriel Okara's Poem - 'You Laughed and Laughed...
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristics
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 
Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17Tree View Decoration Attribute in the Odoo 17
Tree View Decoration Attribute in the Odoo 17
 
DiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfDiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdf
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN THEO CÂU CHO HỌC SINH LỚP 12 ĐỂ ĐẠT ĐIỂM 5+ THI TỐT NGHIỆP THPT ...
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 

Intro to C++

  • 3. #include<iostream>  #Include  means read me before you compile and do what I say essentially.  means that you're signaling the compiler to include some kind of file or library that is needed in order for some function to execute in your source file.  < and >  just enclosures for the compiler to read between and import accordingly.  *stream  <iostream> is a library for basic input and out put controls since C++ alone contains no facilities for IO.
  • 4. #include<iostream> • The #include is a "preprocessor" directive that tells the compiler to put code from the header called iostream into our program before actually creating the executable. • By including header files, you gain access to many different functions. • For example, the cout function requires iostream
  • 5. using namespace std; • This line tells the compiler to use a group of functions that are part of the standard library (std). • By including this line at the top of a file, you allow the program to use functions such as cout
  • 6. int main() • This line tells the compiler that there is a function named main, and that the function returns an integer, hence int. • The "curly braces" ({ and }) signal the beginning and end of functions and other code blocks.
  • 7. Cout<<“Welcome C++”; • The cout object is used to display text. • It uses the << symbols, known as "insertion operators", to indicate what to output.
  • 9. Variables in C++ • // operating with variables • #include <iostream> • using namespacestd; • intmain () • { • // declaring variables: • inta, b; • Int result; • // process: • a = 5; • b = 2; • a = a + 1; • result = a - b; • // print out the result: • cout << result; • // terminate the program: • return0; • }
  • 11. Initialization of variables • inta = 0; • int a (0);
  • 12. Initialization of variables • // initialization of variables • #include <iostream> • using namespace std; • intmain () • { • inta=5; // initial value = 5 • Int b(2); // initial value = 2 • Int result; // initial value undetermined • a = a + 3; • result = a - b; • cout << result; • return0; • }
  • 13. Introduction to strings • // my first string • #include <iostream> • #include <string> • using namespace std; • Int main () • { • string mystring = "This is a string"; • cout << mystring; • Return 0; • }
  • 14. Introduction to strings • string mystring = "This is a string"; • string mystring ("This is a string");
  • 15. Constants (#define) • // defined constants: calculate circumference • #include <iostream> • using namespace std; • #define PI 3.14159 • #define NEWLINE 'n' • Int main () • { • Double r=5.0; // radius • Double circle; • circle = 2 * PI * r; • cout << circle; • cout << NEWLINE; • Return 0; • }
  • 16. Declared constants (const) • const int pathwidth = 100; • const char tabulator = 't';
  • 17. Operators: Assignment (=) • // assignment operator • #include <iostream> • using namespacestd; • intmain () • { • inta, b; // a:?, b:? • a = 10; // a:10, b:? • b = 4; // a:10, b:4 • a = b; // a:4, b:4 • b = 7; // a:4, b:7 • cout << "a:"; • cout << a; • cout << " b:"; • cout << b; • return0; • }
  • 19. • // compound assignment operators • #include <iostream> • using namespacestd; • intmain () • { • inta, b=3; • a = b; • a+=2; // equivalent to a=a+2 • cout << a; • return0; • }
  • 21. Conditional operator ( ? ) • // conditional operator • #include <iostream> • using namespacestd; • intmain () • { • inta,b,c; • a=2; • b=7; • c = (a>b) ? a : b; • cout << c; • return0; • }
  • 22. Conditional operator ( ? ) • 7==5 ? 4 : 3 // returns 3, since 7 is not equal to 5. • 7==5+2 ? 4 : 3 // returns 4, since 7 is equal to 5+2. • 5>3 ? a : b // returns the value of a, since 5 is greater than 3. • a>b ? a : b // returns whichever is greater, a or b.
  • 23. Basic Input/Output • // i/o example • #include <iostream> • using namespacestd; • intmain () • { • inti; • cout << "Please enter an integer value: "; • cin >> i; • cout << "The value you entered is "<< i; • cout << " and its double is "<< i*2 << ".n"; • return0; • }
  • 24. cin and strings • // cin with strings • #include <iostream> • #include <string> • using namespacestd; • intmain () • { • string mystr; • cout << "What's your name? "; • getline (cin, mystr); • cout << "Hello "<< mystr << ".n"; • cout << "What is your favorite team? "; • getline (cin, mystr); • cout << "I like "<< mystr << " too!n"; • return0; • }
  • 25. Conditional structure: if and else • if(x > 0) • cout << "x is positive"; • else if(x < 0) • cout << "x is negative"; • else • cout << "x is 0";
  • 26. The while loop • // custom countdown using while • #include <iostream> • using namespacestd; • intmain () • { • intn; • cout << "Enter the starting number > "; • cin >> n; • while(n>0) { • cout << n << ", "; • --n; • } • cout << "FIRE!n"; • return0; • }
  • 27. The do-while loop • // number echoer • #include <iostream> • using namespacestd; • intmain () • { • unsigned longn; • do{ • cout << "Enter number (0 to end): "; • cin >> n; • cout << "You entered: "<< n << "n"; • } while(n != 0); • return0; • }
  • 28. The for loop • // countdown using a for loop • #include <iostream> • using namespacestd; • intmain () • { • for(intn=10; n>0; n--) { • cout << n << ", "; • } • cout << "FIRE!n"; • return0; • }
  • 29.
  • 30. Jump statements (break) • // break loop example • #include <iostream> • using namespacestd; • intmain () • { • intn; • for(n=10; n>0; n--) • { • cout << n << ", "; • if(n==3) • { • cout << "countdown aborted!"; • break; • } • } • return0; • }
  • 31. continue • // continue loop example • #include <iostream> • using namespacestd; • intmain () • { • for(intn=10; n>0; n--) { • if(n==5) continue; • cout << n << ", "; • } • cout << "FIRE!n"; • return0; • }
  • 32. goto • // goto loop example • #include <iostream> • using namespace std; • Int main () • { • Int n=10; • loop: • cout << n << ", "; • n--; • if(n>0) goto loop; • cout << "FIRE!n"; • return0; • }