SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

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
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
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
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 

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
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
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
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
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
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
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
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 

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; }