SlideShare una empresa de Scribd logo
1 de 16
Lecture 03



 C++ Programming Basics


Comparison between C++ & C:
i) input/output statement
ii) data type
iii) arithmetic operators
iv) header files
C++ vs C




C++ is a superset of C.
C++ was originally called “C with classes”.
Basic C++ Program Construct
Basic C++ Program Construct
              A Sample Program
// first.cpp
#include <iostream>
//preprocessor
using namespace std;         //directive

int main()
{
  int ftemp; // temperature in Fahrenheit
  cout << "Enter temperature in Fahr.: ";
  cin >> ftemp;
  int ctemp = (ftemp - 32) * 5 / 9;
  cout << "Equivalent in Celsius is: "
       << ctemp << endl;
  return 0;
Comments

C Style:
/* This program demonstrate
    function overloading */

C++ Style:
// This program demonstrate
// function overloading
Preprocessor Directive
                    #include

C Style:
#include<stdio.h>

C++ Style:
#include<iostream.h>

 OR THE FOLLOWING ANSI STANDARD

#include<iostream>
using namespace std;
Input and Output

C Input and Ouput:
#include<stdio.h>
scanf(“%i”, &num);
printf(“The number is %in“, num);

C++ Input and Ouput:
#include<iostream.h>
cin >> num;
cout << “The number is “, num << endl;
Stream I/O
Insertion and Extraction
Constants

C-Style Symbolic Constant:
#define PI 3.14159

We can’t specify the data type!
                               What is a Variable ?
C++ const Qualifier:      What is an
const float PI = 3.14159; Identifier?
                          Rules for declaring
                          an identifier?
Recommended !
                               Int Sum1 ;
                               Float 1Salaray
Boolean Type

• Integer, character, and floating-point types are available
  both in C and C++.

• Boolean type is available in C++, but not in C.

• Variables of type bool can have only two possible
  values: true and false (Boolean Values).

• Even though a single bit is enough to store variables of
  type bool, compilers often store them as integers for
  ease of processing.
Boolean Type
                                        Void Main( )
                                        { int num; bool flag = true;
void main()
                                        Cin>> num;
{
                                        if (num > 0 )
  bool flag = true;
                                                flag = true;
                                        else
    if (flag)                                   flag = false;
         cout<<“Hello Halizah”<<endl;   if (flag == true )
                                                  cout<<“positive
    else                                          number”;
         cout<<“Hello World!”<<endl;    else
}                                               cout “negative
                                                number”;
                                        }
Type Conversion : Order of Data Types



 Data Type      Order

 long double Highest
 double
 float
 long
 int
 short
 char        Lowest
Automatic Type Conversion

• When two operands of different types are encountered in
  the same expression, the lower-type variable is
  automatically converted to the higher type variable.

      int denominator;
      float numerator, quotient;
      ...
      quotient = numerator/denominator;

• denominator is converted from int to float before
  the division.
The   setw Manipulator
#include <iostream.h>
#include <iomanip.h>     // for setw

int main()
{
  long pop=2425785;
  cout << setw(8) << "LOCATION" << setw(12)
       << "POPULATION" << endl
       << setw(8) << "Portcity" << setw(12) << pop
       << endl
return 0;
}

Output of the program:
LOCATION   POPULATION
Portcity      2425785
The <cmath>
                Standard Library Functions
// sqrt.cpp
// demonstrate sqrt() library function
#include <iostream> // for cout, etc.
#include <cmath>     // for sqrt()
using namespace std;

int main()
{
  double number, answer;
  cout << "Enter a number: ";
  cin >> number;
  answer = sqrt(number);
  cout << "Square root is " << answer << endl;
  return 0;
}
Header and Library Files

Más contenido relacionado

La actualidad más candente

Lab 9 sem ii_12_13
Lab 9 sem ii_12_13Lab 9 sem ii_12_13
Lab 9 sem ii_12_13alish sha
 
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...yaevents
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_eShikshak
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c languageMomenMostafa
 
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
[C++ korea] effective modern c++ study   item 3 understand decltype +이동우[C++ korea] effective modern c++ study   item 3 understand decltype +이동우
[C++ korea] effective modern c++ study item 3 understand decltype +이동우Seok-joon Yun
 
Extending Python - EuroPython 2014
Extending Python - EuroPython 2014Extending Python - EuroPython 2014
Extending Python - EuroPython 2014fcofdezc
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th StudyChris Ohk
 

La actualidad más candente (20)

Lab 9 sem ii_12_13
Lab 9 sem ii_12_13Lab 9 sem ii_12_13
Lab 9 sem ii_12_13
 
Lab 6
Lab 6Lab 6
Lab 6
 
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
C++11 (formerly known as C++0x) is the new C++ language standard. Dave Abraha...
 
Storage classes
Storage classesStorage classes
Storage classes
 
C++ via C#
C++ via C#C++ via C#
C++ via C#
 
C Theory
C TheoryC Theory
C Theory
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Lecture20
Lecture20Lecture20
Lecture20
 
C language
C languageC language
C language
 
Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_Lecture 3 getting_started_with__c_
Lecture 3 getting_started_with__c_
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
Vcs14
Vcs14Vcs14
Vcs14
 
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
[C++ korea] effective modern c++ study   item 3 understand decltype +이동우[C++ korea] effective modern c++ study   item 3 understand decltype +이동우
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
 
C++11
C++11C++11
C++11
 
Storage classes
Storage classesStorage classes
Storage classes
 
Extending Python - EuroPython 2014
Extending Python - EuroPython 2014Extending Python - EuroPython 2014
Extending Python - EuroPython 2014
 
Storage classes
Storage classesStorage classes
Storage classes
 
string , pointer
string , pointerstring , pointer
string , pointer
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 

Destacado

Destacado (19)

Function class in c++
Function class in c++Function class in c++
Function class in c++
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
QtQuick Day 3
QtQuick Day 3QtQuick Day 3
QtQuick Day 3
 
3 intro basic_elements
3 intro basic_elements3 intro basic_elements
3 intro basic_elements
 
(2) cpp imperative programming
(2) cpp imperative programming(2) cpp imperative programming
(2) cpp imperative programming
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
C++ loop
C++ loop C++ loop
C++ loop
 
Loops c++
Loops c++Loops c++
Loops c++
 
Rectifiers new
Rectifiers newRectifiers new
Rectifiers new
 
An introduction to software engineering
An introduction to software engineeringAn introduction to software engineering
An introduction to software engineering
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Presentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.pptPresentation on half and full wave ractifier.ppt
Presentation on half and full wave ractifier.ppt
 
Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computer
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 

Similar a Lecture03

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
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ toolAbdullah Jan
 
introductiontoc-140704113737-phpapp01.pdf
introductiontoc-140704113737-phpapp01.pdfintroductiontoc-140704113737-phpapp01.pdf
introductiontoc-140704113737-phpapp01.pdfSameerKhanPathan7
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - ReferenceMohammed Sikander
 
2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++kinan keshkeh
 
C++ Tutorial.docx
C++ Tutorial.docxC++ Tutorial.docx
C++ Tutorial.docxPinkiVats1
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxWatchDog13
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++cpjcollege
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
 
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,imtiazalijoono
 

Similar a Lecture03 (20)

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
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
C++ Chapter I
C++ Chapter IC++ Chapter I
C++ Chapter I
 
introductiontoc-140704113737-phpapp01.pdf
introductiontoc-140704113737-phpapp01.pdfintroductiontoc-140704113737-phpapp01.pdf
introductiontoc-140704113737-phpapp01.pdf
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Chp1(c 2 c++)
Chp1(c 2 c++)Chp1(c 2 c++)
Chp1(c 2 c++)
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
C++basics
C++basicsC++basics
C++basics
 
C++ basic.ppt
C++ basic.pptC++ basic.ppt
C++ basic.ppt
 
BASIC C++ PROGRAMMING
BASIC C++ PROGRAMMINGBASIC C++ PROGRAMMING
BASIC C++ PROGRAMMING
 
2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++
 
C++ Tutorial.docx
C++ Tutorial.docxC++ Tutorial.docx
C++ Tutorial.docx
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptx
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 

Más de elearning_portal (12)

Lecture21
Lecture21Lecture21
Lecture21
 
Lecture19
Lecture19Lecture19
Lecture19
 
Lecture18
Lecture18Lecture18
Lecture18
 
Lecture17
Lecture17Lecture17
Lecture17
 
Lecture16
Lecture16Lecture16
Lecture16
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture09
Lecture09Lecture09
Lecture09
 
Lecture07
Lecture07Lecture07
Lecture07
 
Lecture06
Lecture06Lecture06
Lecture06
 
Lecture02
Lecture02Lecture02
Lecture02
 
Lecture01
Lecture01Lecture01
Lecture01
 
Lecture04
Lecture04Lecture04
Lecture04
 

Último

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 

Último (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 

Lecture03

  • 1. Lecture 03 C++ Programming Basics Comparison between C++ & C: i) input/output statement ii) data type iii) arithmetic operators iv) header files
  • 2. C++ vs C C++ is a superset of C. C++ was originally called “C with classes”.
  • 3. Basic C++ Program Construct
  • 4. Basic C++ Program Construct A Sample Program // first.cpp #include <iostream> //preprocessor using namespace std; //directive int main() { int ftemp; // temperature in Fahrenheit cout << "Enter temperature in Fahr.: "; cin >> ftemp; int ctemp = (ftemp - 32) * 5 / 9; cout << "Equivalent in Celsius is: " << ctemp << endl; return 0;
  • 5. Comments C Style: /* This program demonstrate function overloading */ C++ Style: // This program demonstrate // function overloading
  • 6. Preprocessor Directive #include C Style: #include<stdio.h> C++ Style: #include<iostream.h> OR THE FOLLOWING ANSI STANDARD #include<iostream> using namespace std;
  • 7. Input and Output C Input and Ouput: #include<stdio.h> scanf(“%i”, &num); printf(“The number is %in“, num); C++ Input and Ouput: #include<iostream.h> cin >> num; cout << “The number is “, num << endl;
  • 9. Constants C-Style Symbolic Constant: #define PI 3.14159 We can’t specify the data type! What is a Variable ? C++ const Qualifier: What is an const float PI = 3.14159; Identifier? Rules for declaring an identifier? Recommended ! Int Sum1 ; Float 1Salaray
  • 10. Boolean Type • Integer, character, and floating-point types are available both in C and C++. • Boolean type is available in C++, but not in C. • Variables of type bool can have only two possible values: true and false (Boolean Values). • Even though a single bit is enough to store variables of type bool, compilers often store them as integers for ease of processing.
  • 11. Boolean Type Void Main( ) { int num; bool flag = true; void main() Cin>> num; { if (num > 0 ) bool flag = true; flag = true; else if (flag) flag = false; cout<<“Hello Halizah”<<endl; if (flag == true ) cout<<“positive else number”; cout<<“Hello World!”<<endl; else } cout “negative number”; }
  • 12. Type Conversion : Order of Data Types Data Type Order long double Highest double float long int short char Lowest
  • 13. Automatic Type Conversion • When two operands of different types are encountered in the same expression, the lower-type variable is automatically converted to the higher type variable. int denominator; float numerator, quotient; ... quotient = numerator/denominator; • denominator is converted from int to float before the division.
  • 14. The setw Manipulator #include <iostream.h> #include <iomanip.h> // for setw int main() { long pop=2425785; cout << setw(8) << "LOCATION" << setw(12) << "POPULATION" << endl << setw(8) << "Portcity" << setw(12) << pop << endl return 0; } Output of the program: LOCATION POPULATION Portcity 2425785
  • 15. The <cmath> Standard Library Functions // sqrt.cpp // demonstrate sqrt() library function #include <iostream> // for cout, etc. #include <cmath> // for sqrt() using namespace std; int main() { double number, answer; cout << "Enter a number: "; cin >> number; answer = sqrt(number); cout << "Square root is " << answer << endl; return 0; }