SlideShare una empresa de Scribd logo
1 de 13
Babatunde Salaam

C++ tutorials
Contents
Introduction ………………………………………………………………………………………

Programme structure ………………………………………………………………………….

Variables ……………………………………………………………………………………………

Assignments ……………………………………………………………………………………….

Input and output…………………………………………………………………………………

Loops …………………………………………………………………………………………………

Functions ……………………………………………………………………………………………

Arrays …………………………………………………………………………………………………

Recursion …………………………………………………………………………………………….

Selection………………………………………………………………………………………………..
Babatunde Salaam

Introduction
This tutorial is for people who want to learn C++ programing from scratch or who has
limited understanding about C++.
In the past few years programming in C++ has change and this tutorial will update people
on the new futures that have being added to C++ in the past years.
This tutorial can also be useful for other language users as the difference is not massive.
The tutorial is divided into various parts that’s will help leaners to understand the
language in a very easy way
All programs code that will be presented in this tutorial can be modify by readers and can
also be change into any form that best suits the reader as this is a very good way for
readers to learn.
At the end of this tutorial you should have full understanding about C++ programme and
be able to write a full C++ program.
Babatunde Salaam

Programme structure

#includes<iostream>: this is writing at the beginning of every C++ code and it and
authoritative instruction. The #includes<iostream> tells the pre-processor to include to
include the iostream standard file. The #includes<iostream>: is like a header file that has the
rules of how the code you have writing works, it also contains everything needed for
input/output
Using namespace std; all codes in C++ are declared within namespace. The name space
allows the programmer to declare cout without retyping std before every count. For
example, if the programmer does not put using namespace at the beginning of the code
then he or she has to put STD at the beginning of every in and out put.
Int main () this is the line where the main function is being declared. This is the point where
every C++ programme starts their execution. Any other function writing before or after this
does not affect the job of the int main(), and the () stands for function declaration.
Cout << “Happy birthday”: the happy birthday is a statement and that is how every
statement is wringing in C++. And this statement must be visible after the code has being
declared. Cout shows the output of the statement. The purpose of cout in this code is to
output happy birthday and also the cout is already declared iostream.
endle; the endle means end of line which tells the reader that the line has ended and every
statement in C++ must always end with semicolon (;) because it shows the end of
statement.
return 0; this shows the end of function and also declaring the programme completed with
no error.
Babatunde Salaam

Variables (int)

In programming we want to be able to perform other task rather than just writing simple
programmes like “happy birthday”. As a programmer we should be able to write
programmes that will be useful to everyone in their day to day life activity. For example,
writing a programme that allows people to calculate.
This type of programmes can be done by using variable. Variable in C++ allows programmer
to store data instead of repeating it again. For example, in the programme above I was able
to save my “price”, “paid” and “change” as a variable using int.
The two programmes are the same but written in a different way, the second programme
allows users to input their own values unlike the first one which already has the value
inputted to it by the programmer.
Int: the int can be describe as a variable where the values are stored. For example in the
first programme I was able to declare the value for price and paid using int.
Babatunde Salaam

In the first programme, the programmer did not use cin because he/she did not request the
user to input any value and also because the input has already been giving as a variable with
the value unlike the second programme.
cout: this shows the output of a statement as describe in the previous topic.
change = paid-price; this is the formula that is used to calculate the change.
Babatunde Salaam

Assignment (=)
Assignment is part of the C++ operators and since we understand how variables work and
the usefulness in the previous chapter we can now start learning assignment and their
usefulness.
In C++ most operators that are used are mostly sings which can be found on keyboard which
is better because it safes time typing up and also can be used in any country especially none
English countries.

In the programme above, the statement assign 20 to the variable boy and also the same for
the variable girl (boy = 20, girl = 10) the equal (=) sign is the sign that enables the variables
to be assign to each value. When using the assignment sign a variable has to be declared, for
example, the boy and girl are variable because they were already declared as an integer.
The assignment operation always takes place from right to left, and never the other way.
Babatunde Salaam

Cin (Input) and cout (output)
As a programmer, we want to be able to interact with the users by enabling them to be able
to Input values or letter into the code, this means we have to trust them not to change the
programme. To be able to allow users to input letters or value of their choice into a
programme we have to make use of the cout and cin which means input and out.
Basically programmers let user input values or letter of their choice.
A perfect example is a calculator; users can input any number or value of their choice into a
calculator and get a calculated output.

The programme above is an example of cin(input) and cout (output) . The programme
allows users to input the value of their choice which allows them to have an out value they
have entered.
The cin is already inputted by the programmer (cin>>boy, cin>> girl)
Babatunde Salaam

Loops (while and do-while loop)
As a programmer, there are statements that we would like to repeat and typing them over
and over again can take time. Using loop can help programmer avoid situations like this
because loop can help repeat a statement as many times as possible.
There two different types of loops.
The while loop
The main function of a while loop is to statement while the condition set in expression is
true.

The program enable the user to input numbers and the while loop enables them to reapet
the calculation process if they want. The program has given them the option to press yes if
they wish to try the calculation again or no if they do not want to.
At the start of the statement, while (running) was included in the program so as to enable
the statement to repeat every time the user wishes to repeat the calculation.
if (userInput == ‘n’) this is statement means that if the use input no then the programme
should stop running (running = false ;)
Babatunde Salaam

The do while-loop

The do while loop execute the code that the while loop contains without checking if the
condition I true. The do while-loop has same function as a while loop except that it gives
the programme conditions. For example the above program tells the user to input any
number between 10 and 50. Any time a number between those two values are entered the
program keeps running until the value 10 is entered.
The do-while loop is usually used when the condition that has to determine the end of the
loop is determined within the loop statement itself, for example entering a value between
10 and 50 is a condition that has already been determine in the loop statement so the user
has to stick with it.
Babatunde Salaam

Functions
When writing code in C++ it often occurs that their few codes in which we use more than
once in our program. Repeating them often consumes time so therefore we use function
which is a block of code which can be named and can be reuse anywhere in our code.

int area (int pi, int r) is an example of a function in the program above. The value for pi has
being declared before writing the function. This was done because pi has a fixed value so it
has to be declared first.
The functions where later used in the statement when the formula to calculate the area was
declared.
We can keep using this pi and r because they are already declared as a function at the
beginning of the code.
Babatunde Salaam

Arrays
An array is used to store data collection of data. An array can also be refer to as collection of
variable stored using int. different values can be saved In an array without having to declare
different variables every time. For example we can save 10 different numbers in an array.
An example of how an array can be declared can be seen in the program below.

Float number [6] ={2,4,6,8,9,10} this is an example of an array been declared, the [6] stands
for the number of arrays that been declared and the number{2,4,6,8,9,10} are the numbers
stored in the array which can later be refer to in the program.

Recursion
Babatunde Salaam

Recursion in C++ is when a function calls itself. Sometimes when writing a recursion
programme or code, it seems like the function will never end, but this can be change
sometimes. Therefore we can control the amount of time we want our function to reoccur.
The case in which we end our recursion is called a base case.
Recursion is similar to loop because it repeat the same code, but it is easer to express ideas
in recursion.

This is an example of a simple recursion programme that’s counts for ever until it stop by
the user.
Recurse (count +1); this tells the user the increment you want the recursion to be in. for
example, in this programme I want the increment to be 1.
Recurse (10); this tells the user where the count is going to start from. For example, in this
programme I want the count to start form 10.
Babatunde Salaam

This is an example of recursion with base, this programme helps to find the factor of a doll.
This is similar to the first recursion programme that was writing except that this has an end
to its calculation.

Más contenido relacionado

La actualidad más candente (20)

Intro to c++
Intro to c++Intro to c++
Intro to c++
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
Deep C
Deep CDeep C
Deep C
 
C Programming
C ProgrammingC Programming
C Programming
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
C language
C languageC language
C language
 
C language for Semester Exams for Engineers
C language for Semester Exams for Engineers C language for Semester Exams for Engineers
C language for Semester Exams for Engineers
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
C programming
C programmingC programming
C programming
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
4. programing 101
4. programing 1014. programing 101
4. programing 101
 
Learn Java Part 2
Learn Java Part 2Learn Java Part 2
Learn Java Part 2
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Function in c program
Function in c programFunction in c program
Function in c program
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 

Destacado

What should be the Term of my Term Plan
What should be the Term of my Term PlanWhat should be the Term of my Term Plan
What should be the Term of my Term PlanPolicyBoss
 
Matematicas 101005134856-phpapp02
Matematicas 101005134856-phpapp02Matematicas 101005134856-phpapp02
Matematicas 101005134856-phpapp02muero3
 
Convocatoria premio guamán poma guaraní
Convocatoria premio guamán poma guaraníConvocatoria premio guamán poma guaraní
Convocatoria premio guamán poma guaraníErbol Digital
 
Signs for Places of Worship UDO Amendment
Signs for Places of Worship UDO AmendmentSigns for Places of Worship UDO Amendment
Signs for Places of Worship UDO AmendmentCity of College Station
 
Hoja de reflexión picasso
Hoja de reflexión picassoHoja de reflexión picasso
Hoja de reflexión picassoborjadm1997
 
Jillena RoseCV2014
Jillena RoseCV2014Jillena RoseCV2014
Jillena RoseCV2014Jillena Rose
 
Portfolyomu inceleyebilirsiniz
Portfolyomu inceleyebilirsinizPortfolyomu inceleyebilirsiniz
Portfolyomu inceleyebilirsinizFatma Kaya
 
Biomitosismeiosis
BiomitosismeiosisBiomitosismeiosis
BiomitosismeiosisAhmed Ali
 
Edu 225 102 syllabus spring 2014 brockman
Edu 225 102 syllabus spring 2014 brockmanEdu 225 102 syllabus spring 2014 brockman
Edu 225 102 syllabus spring 2014 brockmanCarolyn Brockman
 
El efecto de levantar capital en tu startup
El efecto de levantar capital en tu startupEl efecto de levantar capital en tu startup
El efecto de levantar capital en tu startupThe Pool MX
 
How to make homemade polymer clay
How to make homemade polymer clayHow to make homemade polymer clay
How to make homemade polymer clayJao Rosas
 
Comprehensive Plan – 5 Year Report Subcommittee Appointments
Comprehensive Plan – 5 Year Report Subcommittee Appointments Comprehensive Plan – 5 Year Report Subcommittee Appointments
Comprehensive Plan – 5 Year Report Subcommittee Appointments City of College Station
 
Session 4
Session 4Session 4
Session 4broo209
 
Distribution Company: StudioCanal
Distribution Company: StudioCanalDistribution Company: StudioCanal
Distribution Company: StudioCanal12cms2013
 
Session 4
Session 4Session 4
Session 4broo209
 

Destacado (20)

What should be the Term of my Term Plan
What should be the Term of my Term PlanWhat should be the Term of my Term Plan
What should be the Term of my Term Plan
 
Matematicas 101005134856-phpapp02
Matematicas 101005134856-phpapp02Matematicas 101005134856-phpapp02
Matematicas 101005134856-phpapp02
 
Convocatoria premio guamán poma guaraní
Convocatoria premio guamán poma guaraníConvocatoria premio guamán poma guaraní
Convocatoria premio guamán poma guaraní
 
Chamber of Commerce Funding Agreement
Chamber of Commerce Funding AgreementChamber of Commerce Funding Agreement
Chamber of Commerce Funding Agreement
 
Signs for Places of Worship UDO Amendment
Signs for Places of Worship UDO AmendmentSigns for Places of Worship UDO Amendment
Signs for Places of Worship UDO Amendment
 
Hoja de reflexión picasso
Hoja de reflexión picassoHoja de reflexión picasso
Hoja de reflexión picasso
 
Presentacion1
Presentacion1Presentacion1
Presentacion1
 
Jillena RoseCV2014
Jillena RoseCV2014Jillena RoseCV2014
Jillena RoseCV2014
 
Portfolyomu inceleyebilirsiniz
Portfolyomu inceleyebilirsinizPortfolyomu inceleyebilirsiniz
Portfolyomu inceleyebilirsiniz
 
Gateway Subdivision Rezoning
Gateway Subdivision RezoningGateway Subdivision Rezoning
Gateway Subdivision Rezoning
 
Biomitosismeiosis
BiomitosismeiosisBiomitosismeiosis
Biomitosismeiosis
 
Edu 225 102 syllabus spring 2014 brockman
Edu 225 102 syllabus spring 2014 brockmanEdu 225 102 syllabus spring 2014 brockman
Edu 225 102 syllabus spring 2014 brockman
 
El efecto de levantar capital en tu startup
El efecto de levantar capital en tu startupEl efecto de levantar capital en tu startup
El efecto de levantar capital en tu startup
 
Vietnam Saigon Travel Package
Vietnam Saigon Travel PackageVietnam Saigon Travel Package
Vietnam Saigon Travel Package
 
How to make homemade polymer clay
How to make homemade polymer clayHow to make homemade polymer clay
How to make homemade polymer clay
 
Comprehensive Plan – 5 Year Report Subcommittee Appointments
Comprehensive Plan – 5 Year Report Subcommittee Appointments Comprehensive Plan – 5 Year Report Subcommittee Appointments
Comprehensive Plan – 5 Year Report Subcommittee Appointments
 
Session 4
Session 4Session 4
Session 4
 
Distribution Company: StudioCanal
Distribution Company: StudioCanalDistribution Company: StudioCanal
Distribution Company: StudioCanal
 
Session 4
Session 4Session 4
Session 4
 
On-Street Parking – Toni Court
On-Street Parking – Toni CourtOn-Street Parking – Toni Court
On-Street Parking – Toni Court
 

Similar a Project two c++ tutorial

Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdfziyadaslanbey
 
Functions in c++
Functions in c++Functions in c++
Functions in c++Asaye Dilbo
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
Computer science principals in terms of Programming
Computer science principals in terms of ProgrammingComputer science principals in terms of Programming
Computer science principals in terms of ProgrammingUmair Jameel
 
Visual Basic Review - ICA
Visual Basic Review - ICAVisual Basic Review - ICA
Visual Basic Review - ICAemtrajano
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiSowmya Jyothi
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxrajkumar490591
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfAbrehamKassa
 
Programming basics
Programming basicsProgramming basics
Programming basicsillidari
 

Similar a Project two c++ tutorial (20)

Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
Presentation 2.pptx
Presentation 2.pptxPresentation 2.pptx
Presentation 2.pptx
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
Book management system
Book management systemBook management system
Book management system
 
Computer science principals in terms of Programming
Computer science principals in terms of ProgrammingComputer science principals in terms of Programming
Computer science principals in terms of Programming
 
Visual Basic Review - ICA
Visual Basic Review - ICAVisual Basic Review - ICA
Visual Basic Review - ICA
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
C++
C++C++
C++
 
Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Chapter 1.ppt
Chapter 1.pptChapter 1.ppt
Chapter 1.ppt
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdf
 
Programming basics
Programming basicsProgramming basics
Programming basics
 

Último

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Último (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

Project two c++ tutorial

  • 1. Babatunde Salaam C++ tutorials Contents Introduction ……………………………………………………………………………………… Programme structure …………………………………………………………………………. Variables …………………………………………………………………………………………… Assignments ………………………………………………………………………………………. Input and output………………………………………………………………………………… Loops ………………………………………………………………………………………………… Functions …………………………………………………………………………………………… Arrays ………………………………………………………………………………………………… Recursion ……………………………………………………………………………………………. Selection………………………………………………………………………………………………..
  • 2. Babatunde Salaam Introduction This tutorial is for people who want to learn C++ programing from scratch or who has limited understanding about C++. In the past few years programming in C++ has change and this tutorial will update people on the new futures that have being added to C++ in the past years. This tutorial can also be useful for other language users as the difference is not massive. The tutorial is divided into various parts that’s will help leaners to understand the language in a very easy way All programs code that will be presented in this tutorial can be modify by readers and can also be change into any form that best suits the reader as this is a very good way for readers to learn. At the end of this tutorial you should have full understanding about C++ programme and be able to write a full C++ program.
  • 3. Babatunde Salaam Programme structure #includes<iostream>: this is writing at the beginning of every C++ code and it and authoritative instruction. The #includes<iostream> tells the pre-processor to include to include the iostream standard file. The #includes<iostream>: is like a header file that has the rules of how the code you have writing works, it also contains everything needed for input/output Using namespace std; all codes in C++ are declared within namespace. The name space allows the programmer to declare cout without retyping std before every count. For example, if the programmer does not put using namespace at the beginning of the code then he or she has to put STD at the beginning of every in and out put. Int main () this is the line where the main function is being declared. This is the point where every C++ programme starts their execution. Any other function writing before or after this does not affect the job of the int main(), and the () stands for function declaration. Cout << “Happy birthday”: the happy birthday is a statement and that is how every statement is wringing in C++. And this statement must be visible after the code has being declared. Cout shows the output of the statement. The purpose of cout in this code is to output happy birthday and also the cout is already declared iostream. endle; the endle means end of line which tells the reader that the line has ended and every statement in C++ must always end with semicolon (;) because it shows the end of statement. return 0; this shows the end of function and also declaring the programme completed with no error.
  • 4. Babatunde Salaam Variables (int) In programming we want to be able to perform other task rather than just writing simple programmes like “happy birthday”. As a programmer we should be able to write programmes that will be useful to everyone in their day to day life activity. For example, writing a programme that allows people to calculate. This type of programmes can be done by using variable. Variable in C++ allows programmer to store data instead of repeating it again. For example, in the programme above I was able to save my “price”, “paid” and “change” as a variable using int. The two programmes are the same but written in a different way, the second programme allows users to input their own values unlike the first one which already has the value inputted to it by the programmer. Int: the int can be describe as a variable where the values are stored. For example in the first programme I was able to declare the value for price and paid using int.
  • 5. Babatunde Salaam In the first programme, the programmer did not use cin because he/she did not request the user to input any value and also because the input has already been giving as a variable with the value unlike the second programme. cout: this shows the output of a statement as describe in the previous topic. change = paid-price; this is the formula that is used to calculate the change.
  • 6. Babatunde Salaam Assignment (=) Assignment is part of the C++ operators and since we understand how variables work and the usefulness in the previous chapter we can now start learning assignment and their usefulness. In C++ most operators that are used are mostly sings which can be found on keyboard which is better because it safes time typing up and also can be used in any country especially none English countries. In the programme above, the statement assign 20 to the variable boy and also the same for the variable girl (boy = 20, girl = 10) the equal (=) sign is the sign that enables the variables to be assign to each value. When using the assignment sign a variable has to be declared, for example, the boy and girl are variable because they were already declared as an integer. The assignment operation always takes place from right to left, and never the other way.
  • 7. Babatunde Salaam Cin (Input) and cout (output) As a programmer, we want to be able to interact with the users by enabling them to be able to Input values or letter into the code, this means we have to trust them not to change the programme. To be able to allow users to input letters or value of their choice into a programme we have to make use of the cout and cin which means input and out. Basically programmers let user input values or letter of their choice. A perfect example is a calculator; users can input any number or value of their choice into a calculator and get a calculated output. The programme above is an example of cin(input) and cout (output) . The programme allows users to input the value of their choice which allows them to have an out value they have entered. The cin is already inputted by the programmer (cin>>boy, cin>> girl)
  • 8. Babatunde Salaam Loops (while and do-while loop) As a programmer, there are statements that we would like to repeat and typing them over and over again can take time. Using loop can help programmer avoid situations like this because loop can help repeat a statement as many times as possible. There two different types of loops. The while loop The main function of a while loop is to statement while the condition set in expression is true. The program enable the user to input numbers and the while loop enables them to reapet the calculation process if they want. The program has given them the option to press yes if they wish to try the calculation again or no if they do not want to. At the start of the statement, while (running) was included in the program so as to enable the statement to repeat every time the user wishes to repeat the calculation. if (userInput == ‘n’) this is statement means that if the use input no then the programme should stop running (running = false ;)
  • 9. Babatunde Salaam The do while-loop The do while loop execute the code that the while loop contains without checking if the condition I true. The do while-loop has same function as a while loop except that it gives the programme conditions. For example the above program tells the user to input any number between 10 and 50. Any time a number between those two values are entered the program keeps running until the value 10 is entered. The do-while loop is usually used when the condition that has to determine the end of the loop is determined within the loop statement itself, for example entering a value between 10 and 50 is a condition that has already been determine in the loop statement so the user has to stick with it.
  • 10. Babatunde Salaam Functions When writing code in C++ it often occurs that their few codes in which we use more than once in our program. Repeating them often consumes time so therefore we use function which is a block of code which can be named and can be reuse anywhere in our code. int area (int pi, int r) is an example of a function in the program above. The value for pi has being declared before writing the function. This was done because pi has a fixed value so it has to be declared first. The functions where later used in the statement when the formula to calculate the area was declared. We can keep using this pi and r because they are already declared as a function at the beginning of the code.
  • 11. Babatunde Salaam Arrays An array is used to store data collection of data. An array can also be refer to as collection of variable stored using int. different values can be saved In an array without having to declare different variables every time. For example we can save 10 different numbers in an array. An example of how an array can be declared can be seen in the program below. Float number [6] ={2,4,6,8,9,10} this is an example of an array been declared, the [6] stands for the number of arrays that been declared and the number{2,4,6,8,9,10} are the numbers stored in the array which can later be refer to in the program. Recursion
  • 12. Babatunde Salaam Recursion in C++ is when a function calls itself. Sometimes when writing a recursion programme or code, it seems like the function will never end, but this can be change sometimes. Therefore we can control the amount of time we want our function to reoccur. The case in which we end our recursion is called a base case. Recursion is similar to loop because it repeat the same code, but it is easer to express ideas in recursion. This is an example of a simple recursion programme that’s counts for ever until it stop by the user. Recurse (count +1); this tells the user the increment you want the recursion to be in. for example, in this programme I want the increment to be 1. Recurse (10); this tells the user where the count is going to start from. For example, in this programme I want the count to start form 10.
  • 13. Babatunde Salaam This is an example of recursion with base, this programme helps to find the factor of a doll. This is similar to the first recursion programme that was writing except that this has an end to its calculation.