SlideShare ist ein Scribd-Unternehmen logo
1 von 18
C++ Basics
Inam Ul Haq
Lecturer in Computer Science
University of Education Okara Campus
inam@ue.edu.pk, inam.bth@gmail.com
Subject: Programming Language for Mathematics
Class: BS(Hons) Mathematics
Header Files
// header files are preprocessor directives that are included to call built-in
functions to be used in the program
// e.g. for keywords: cin and cout, the header file iostream.h is used
#include <iostream.h>
Void main() {
//variable declaration
//read values input from user
//computation and print output to user
return 0;
}
Note: 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
UniversityofEducationOkara
Campus
2
Notes
• // is used for comments (this is not executed)
• indentation is for the convenience of the reader; compiler ignores all spaces and new line ;
the delimiter for the compiler is the semicolon
• E.g.
• Void main()
• {
• Clrscr();
• Int a,b;
• If(a==b)
• {
• Cout<<“a is equal to b”<<endl;
• all statements ended by semicolon
• Lower vs. upper case matters!!
• Void is different than void
• Main is different that main
UniversityofEducationOkara
Campus
3
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>
Void main() {
cout << “Hello world!”;
getch();
}
UniversityofEducationOkara
Campus
4
Variable declaration
Syntax: <variable-name> <type>
e.g:
• int n, average; //integer
• Double m; //real number
• char c, my-character//character
UniversityofEducationOkara
Campus
5
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;
UniversityofEducationOkara
Campus
6
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;
UniversityofEducationOkara
Campus
7
If statements
if (condition) {
S1;
}
else {
S2;
}
S3;
condition
S1 S2
S3
True False
UniversityofEducationOkara
Campus
8
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
UniversityofEducationOkara
Campus
9
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)) …
UniversityofEducationOkara
Campus
10
If Statement
#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;
}
UniversityofEducationOkara
Campus
11
While Loop
while (condition) {
S1;
}
S2;
condition
S1
S2
True False
UniversityofEducationOkara
Campus
12
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;
}
UniversityofEducationOkara
Campus
13
For Loop
• for ( initialization; conidition; increment/decrement)
• {
• Statement 1’
• Statement 2;
}
UniversityofEducationOkara
Campus
14
For Loop Example
• #include <iostream>
• int main ()
• {
• for( int a = 10; a < 20; a = a + 1 )
• {
• cout << "value of a: " << a << endl;
• }
• return 0;
• }
UniversityofEducationOkara
Campus
15
Do While Loop
• do
{
     block of code;
statement 1;
statement 2;
     }
while (condition); //it is called test condition
UniversityofEducationOkara
Campus
16
Do While Loop Example
• #include <iostream> 
• #include <conio.h>
• int main () 
• { 
• int a = 10;
• do 
•     { 
•        cout << "value of a: " << a << endl; 
•        a = a + 1; 
•     }
•   while( a < 20 ); 
• return 0; 
• }
UniversityofEducationOkara
Campus
17
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”. 
UniversityofEducationOkara
Campus
18

Weitere ähnliche Inhalte

Was ist angesagt?

Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4emailharmeet
 
Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions khawajasharif
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Continuations in Ruby (Anton Vasiljev)
Continuations in Ruby (Anton Vasiljev)Continuations in Ruby (Anton Vasiljev)
Continuations in Ruby (Anton Vasiljev)Olga Lavrentieva
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageVincenzo De Florio
 
Introduction to c language by nitesh
Introduction to c language by niteshIntroduction to c language by nitesh
Introduction to c language by niteshniteshcongreja321
 
180 daraga cpp course session-1
180 daraga cpp course session-1180 daraga cpp course session-1
180 daraga cpp course session-1Moustafa Ghoniem
 
Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Ibrahim Elewah
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 solIIUM
 
C and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharC and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharDreamtech Labs
 
Anton Vasiljev: Continuations in Ruby.
Anton Vasiljev: Continuations in Ruby.Anton Vasiljev: Continuations in Ruby.
Anton Vasiljev: Continuations in Ruby.Sphere Consulting Inc
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xiiSyed Zaid Irshad
 

Was ist angesagt? (20)

CP Handout#6
CP Handout#6CP Handout#6
CP Handout#6
 
Testing lecture after lec 4
Testing lecture after lec 4Testing lecture after lec 4
Testing lecture after lec 4
 
Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions Beginner C++ easy slide and simple definition with questions
Beginner C++ easy slide and simple definition with questions
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
C programming language
C programming languageC programming language
C programming language
 
Continuations in Ruby (Anton Vasiljev)
Continuations in Ruby (Anton Vasiljev)Continuations in Ruby (Anton Vasiljev)
Continuations in Ruby (Anton Vasiljev)
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Hands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming LanguageHands-on Introduction to the C Programming Language
Hands-on Introduction to the C Programming Language
 
Introduction to c language by nitesh
Introduction to c language by niteshIntroduction to c language by nitesh
Introduction to c language by nitesh
 
180 daraga cpp course session-1
180 daraga cpp course session-1180 daraga cpp course session-1
180 daraga cpp course session-1
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
C programming
C programming C programming
C programming
 
Ppl home assignment_unit2
Ppl home assignment_unit2Ppl home assignment_unit2
Ppl home assignment_unit2
 
Computer programming chapter ( 4 )
Computer programming chapter ( 4 ) Computer programming chapter ( 4 )
Computer programming chapter ( 4 )
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 
C and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharC and C++ Industrial Training Jalandhar
C and C++ Industrial Training Jalandhar
 
Anton Vasiljev: Continuations in Ruby.
Anton Vasiljev: Continuations in Ruby.Anton Vasiljev: Continuations in Ruby.
Anton Vasiljev: Continuations in Ruby.
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 

Ähnlich wie C++ Basics

c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.pptEPORI
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++cpjcollege
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...ANUSUYA S
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************Emad Helal
 
clc02_cpp_presentation_edit3 (1) 1.pptx
clc02_cpp_presentation_edit3 (1) 1.pptxclc02_cpp_presentation_edit3 (1) 1.pptx
clc02_cpp_presentation_edit3 (1) 1.pptxjminrin0212
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
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 JobyGrejoJoby1
 

Ähnlich wie C++ Basics (20)

c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
c++basiccs.ppt
c++basiccs.pptc++basiccs.ppt
c++basiccs.ppt
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
C++basics
C++basicsC++basics
C++basics
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
C++ basics
C++ basicsC++ basics
C++ basics
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
C++ basics
C++ basicsC++ basics
C++ basics
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************
 
C++
C++C++
C++
 
C++ Chapter 3
C++ Chapter 3C++ Chapter 3
C++ Chapter 3
 
clc02_cpp_presentation_edit3 (1) 1.pptx
clc02_cpp_presentation_edit3 (1) 1.pptxclc02_cpp_presentation_edit3 (1) 1.pptx
clc02_cpp_presentation_edit3 (1) 1.pptx
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
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
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 

Mehr von university of education,Lahore

Mehr von university of education,Lahore (20)

Activites and Time Planning
 Activites and Time Planning Activites and Time Planning
Activites and Time Planning
 
Steganography
SteganographySteganography
Steganography
 
Classical Encryption Techniques
Classical Encryption TechniquesClassical Encryption Techniques
Classical Encryption Techniques
 
Activites and Time Planning
Activites and Time PlanningActivites and Time Planning
Activites and Time Planning
 
OSI Security Architecture
OSI Security ArchitectureOSI Security Architecture
OSI Security Architecture
 
Network Security Terminologies
Network Security TerminologiesNetwork Security Terminologies
Network Security Terminologies
 
Project Scheduling, Planning and Risk Management
Project Scheduling, Planning and Risk ManagementProject Scheduling, Planning and Risk Management
Project Scheduling, Planning and Risk Management
 
Software Testing and Debugging
Software Testing and DebuggingSoftware Testing and Debugging
Software Testing and Debugging
 
ePayment Methods
ePayment MethodsePayment Methods
ePayment Methods
 
SEO
SEOSEO
SEO
 
A Star Search
A Star SearchA Star Search
A Star Search
 
Enterprise Application Integration
Enterprise Application IntegrationEnterprise Application Integration
Enterprise Application Integration
 
Uml Diagrams
Uml DiagramsUml Diagrams
Uml Diagrams
 
eDras Max
eDras MaxeDras Max
eDras Max
 
RAD Model
RAD ModelRAD Model
RAD Model
 
Microsoft Project
Microsoft ProjectMicrosoft Project
Microsoft Project
 
Itertaive Process Development
Itertaive Process DevelopmentItertaive Process Development
Itertaive Process Development
 
Computer Aided Software Engineering Nayab Awan
Computer Aided Software Engineering Nayab AwanComputer Aided Software Engineering Nayab Awan
Computer Aided Software Engineering Nayab Awan
 
Lect 2 assessing the technology landscape
Lect 2 assessing the technology landscapeLect 2 assessing the technology landscape
Lect 2 assessing the technology landscape
 
system level requirements gathering and analysis
system level requirements gathering and analysissystem level requirements gathering and analysis
system level requirements gathering and analysis
 

Kürzlich hochgeladen

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 

Kürzlich hochgeladen (20)

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 

C++ Basics

  • 1. C++ Basics Inam Ul Haq Lecturer in Computer Science University of Education Okara Campus inam@ue.edu.pk, inam.bth@gmail.com Subject: Programming Language for Mathematics Class: BS(Hons) Mathematics
  • 2. Header Files // header files are preprocessor directives that are included to call built-in functions to be used in the program // e.g. for keywords: cin and cout, the header file iostream.h is used #include <iostream.h> Void main() { //variable declaration //read values input from user //computation and print output to user return 0; } Note: 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 UniversityofEducationOkara Campus 2
  • 3. Notes • // is used for comments (this is not executed) • indentation is for the convenience of the reader; compiler ignores all spaces and new line ; the delimiter for the compiler is the semicolon • E.g. • Void main() • { • Clrscr(); • Int a,b; • If(a==b) • { • Cout<<“a is equal to b”<<endl; • all statements ended by semicolon • Lower vs. upper case matters!! • Void is different than void • Main is different that main UniversityofEducationOkara Campus 3
  • 4. 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> Void main() { cout << “Hello world!”; getch(); } UniversityofEducationOkara Campus 4
  • 5. Variable declaration Syntax: <variable-name> <type> e.g: • int n, average; //integer • Double m; //real number • char c, my-character//character UniversityofEducationOkara Campus 5
  • 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; UniversityofEducationOkara Campus 6
  • 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; UniversityofEducationOkara Campus 7
  • 8. If statements if (condition) { S1; } else { S2; } S3; condition S1 S2 S3 True False UniversityofEducationOkara Campus 8
  • 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 UniversityofEducationOkara Campus 9
  • 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)) … UniversityofEducationOkara Campus 10
  • 11. If Statement #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; } UniversityofEducationOkara Campus 11
  • 12. While Loop while (condition) { S1; } S2; condition S1 S2 True False UniversityofEducationOkara Campus 12
  • 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; } UniversityofEducationOkara Campus 13
  • 14. For Loop • for ( initialization; conidition; increment/decrement) • { • Statement 1’ • Statement 2; } UniversityofEducationOkara Campus 14
  • 15. For Loop Example • #include <iostream> • int main () • { • for( int a = 10; a < 20; a = a + 1 ) • { • cout << "value of a: " << a << endl; • } • return 0; • } UniversityofEducationOkara Campus 15
  • 16. Do While Loop • do {      block of code; statement 1; statement 2;      } while (condition); //it is called test condition UniversityofEducationOkara Campus 16
  • 17. Do While Loop Example • #include <iostream>  • #include <conio.h> • int main ()  • {  • int a = 10; • do  •     {  •        cout << "value of a: " << a << endl;  •        a = a + 1;  •     } •   while( a < 20 );  • return 0;  • } UniversityofEducationOkara Campus 17
  • 18. 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”.  UniversityofEducationOkara Campus 18