SlideShare a Scribd company logo
1 of 21
Unit 2:
Understand the basic structure of C++
   Objectives
   Evolution of C++
   Structure of C++ program
    • Preprocessor directives
    • Header files
    • Main() function
    • Return statement
   Hands On!
   At the end of this presentation, you will
    be able to:
    • Describe the general structure of C++ programs
    • Write a simple C++ programme
   Bjarne Stroustrup founded C++ in mid
    80’s.
   C++ was developed at AT&T Bell
    laboratories.
   Additional features than C.
   Features are closer to the real world
    solution.
Include File
         (must have)
       Class declaration
           (if any)
Class Member Function definition
           (if any)
         Main function
         (must have)
Header file   Description
<cassert>     Contains macros and information for adding
              diagnostic that aid program debugging
<cstring>     Contains function prototype for C-style string
              processing
<cmath>       Contains function prototype for math library
              function
<iostream>    Contains function prototype for standard input
              and standard output function
<iomanip>     Contains function prototype for stream
              manipulator that enable formatting of streams of
              data
<fstream>     Contains function prototype for functions that
              perform input from files on disk and output to files
              on disk.
<preprocessor directive>

<main function>
  {
  <variable declaration>
 ….
  <C++ statement>
 ….
  <return statement(if any)>
  }
//First C++ Program                 Comment
#include <iostream>        Preprocessor Directive
using namespace std;
int main()        Main Function
 {
 int a;      Variable Declaration
 cout << “Hello World!”;
 cin >> a;                            Statement
 return 0;
 }
   Line 1: // First C++ program
    • comment line.
    • ignored by the compiler and do not have any
      effect on the executable.
    • comments in programs help the programmer
      (and users) to understand what the program (or
      section) does.
    • C++ supports two types of comments:
      // line comment

      /* block comment */
   Line 2: #include <iostream>
    • lines beginning with a hash (or pound) sign (#) are
      directives for the preprocessor.
    • runs before the compiler each time the compiler is
      invoked.
    • translates any line that begins with a hash symbol
      (#) into a special command, getting your code file
      ready for the compiler.
    • #include <iostream> tells the preprocessor to
      include the iostream standard file which contains the
      declarations of the basic standard input-output
      library in C++.
   Line 3: using namespace std;
    • namespace allows to group entities like variables,
      classes, objects and functions under a name.
    • elements belonging to the standard C++ library are
      declared in what is called a std namespace.
    • example: cout is defined under std namespace
      where you can see the details in the file <iostream>.
    • if you omit this line, in order to use cout, you need to
      write the name of the namespace (std) followed by
      scope operator (::) before cout.
      Eg: std::cout << "Hello world!";.
   Line 4: empty line
    • An empty line does nothing except for help the
     programmer to view the source code more
     clearly.

   Line 5: int main()
    • actual program starts must start with a function
      named main().
    • every C++ program has only one main()
      function.
 Lines 6 and 11:
    The body of the main() function is enclosed in braces ({ }).

 Line   8: cout << "Hello World!";
   this line is a C++ statement which performs the only
    action that generates a visible effect in our first program.
   Each statement must end with a semicolon character (;).
   Here's how cout is used: type the word cout, followed by
    the output insertion (or redirection) operator (<<).
   Whatever follows the output insertion operator is output
    to the screen.
   If you want to output a string of characters be sure to
    enclose them in double quotes (" "), as shown on line 7,
    "Hello World!".
   Line 10: return 0;
    • return statement causes the main() function (i.e.
     the program) to finish.
   Write a program that outputs following
    lines to the screen:

    Welcome to the world of C++
#include <iostream>
using namespace std;

void main( )
 {
 cout << “Welcome to the world
 of C++”
 }
   Why does the following program fail?

    #include <iostreams>
    using namespace std;

    void main()
      {
      cout << “Is there a bug
    here?”;
      }
   Because of the typo error for the
    preprocessor directive
   Wrong : iostreams
   Correct: iostream
   Explain why we use std:: in the following program.
    What is the output of program?
    #include <iostream>
    void main()
      {
      std::cout << " ## # # "<< std::endl;
      std::cout << "# ### ###"<<std::endl;
      std::cout << " ## # # "<< std::endl;
      }
   Refer to slide 11
Fp201 unit2 1

More Related Content

What's hot

C introduction
C introductionC introduction
C introductionKamran
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of Ceducationfront
 
Structure of C program
Structure of C programStructure of C program
Structure of C programPavan prasad
 
What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013Paulo Morgado
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++ Bharat Kalia
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programmingMalikaJoya
 
Function in C and C++
Function in C and C++Function in C and C++
Function in C and C++Rahul Sahu
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program executionRumman Ansari
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Rumman Ansari
 
What's new in c# 5.0 net ponto
What's new in c# 5.0   net pontoWhat's new in c# 5.0   net ponto
What's new in c# 5.0 net pontoPaulo Morgado
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo dattaApurbo Datta
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++cpjcollege
 

What's hot (20)

C introduction
C introductionC introduction
C introduction
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Lesson 7 io statements
Lesson 7 io statementsLesson 7 io statements
Lesson 7 io statements
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 
Structure of C program
Structure of C programStructure of C program
Structure of C program
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
C++
C++C++
C++
 
What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Function in C and C++
Function in C and C++Function in C and C++
Function in C and C++
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
 
C Programming
C ProgrammingC Programming
C Programming
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
What's new in c# 5.0 net ponto
What's new in c# 5.0   net pontoWhat's new in c# 5.0   net ponto
What's new in c# 5.0 net ponto
 
C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo datta
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 

Viewers also liked

Viewers also liked (20)

Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Fp201 unit1 1
Fp201 unit1 1Fp201 unit1 1
Fp201 unit1 1
 
FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3FP 201 Unit 2 - Part 3
FP 201 Unit 2 - Part 3
 
FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2FP 201 - Unit4 Part 2
FP 201 - Unit4 Part 2
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
Unit 1
Unit 1Unit 1
Unit 1
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 2
Unit 2Unit 2
Unit 2
 
098ca session7 c++
098ca session7 c++098ca session7 c++
098ca session7 c++
 
Intro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm ReviewIntro To C++ - Class 14 - Midterm Review
Intro To C++ - Class 14 - Midterm Review
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
C++ And Object in lecture3
C++  And Object in lecture3C++  And Object in lecture3
C++ And Object in lecture3
 
OOP
OOPOOP
OOP
 
class c++
class c++class c++
class c++
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 

Similar to Fp201 unit2 1 (20)

Introduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to itIntroduction to cpp language and all the required information relating to it
Introduction to cpp language and all the required information relating to it
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Intro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample ProgramIntro To C++ - Class 3 - Sample Program
Intro To C++ - Class 3 - Sample Program
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
 
Workshop1
Workshop1Workshop1
Workshop1
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Common Programming Errors
Common Programming ErrorsCommon Programming Errors
Common Programming Errors
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Parm
ParmParm
Parm
 
Parm
ParmParm
Parm
 
basic program
basic programbasic program
basic program
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
C++ basics
C++ basicsC++ basics
C++ basics
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 

More from rohassanie

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012rohassanie
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5rohassanie
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2rohassanie
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1rohassanie
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3rohassanie
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2) rohassanie
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201rohassanie
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201rohassanie
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012rohassanie
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1rohassanie
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 studrohassanie
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 studrohassanie
 
Chapter 1 part 3
Chapter 1 part 3Chapter 1 part 3
Chapter 1 part 3rohassanie
 
Chapter 1 part 2
Chapter 1 part 2Chapter 1 part 2
Chapter 1 part 2rohassanie
 
Chapter 1 part 1
Chapter 1 part 1Chapter 1 part 1
Chapter 1 part 1rohassanie
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++rohassanie
 

More from rohassanie (20)

Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012Course outline FP202 - Dis 2012
Course outline FP202 - Dis 2012
 
FP 202 - Chapter 5
FP 202 - Chapter 5FP 202 - Chapter 5
FP 202 - Chapter 5
 
Chapter 3 part 2
Chapter 3 part 2Chapter 3 part 2
Chapter 3 part 2
 
Chapter 3 part 1
Chapter 3 part 1Chapter 3 part 1
Chapter 3 part 1
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
 
Lab ex 1
Lab ex 1Lab ex 1
Lab ex 1
 
Chapter 2 (Part 2)
Chapter 2 (Part 2) Chapter 2 (Part 2)
Chapter 2 (Part 2)
 
Labsheet 7 FP 201
Labsheet 7 FP 201Labsheet 7 FP 201
Labsheet 7 FP 201
 
Labsheet 6 - FP 201
Labsheet 6 - FP 201Labsheet 6 - FP 201
Labsheet 6 - FP 201
 
Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012Jadual Waktu Sesi JUN 2012
Jadual Waktu Sesi JUN 2012
 
Labsheet 5
Labsheet 5Labsheet 5
Labsheet 5
 
Labsheet 4
Labsheet 4Labsheet 4
Labsheet 4
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
 
Labsheet_3
Labsheet_3Labsheet_3
Labsheet_3
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
 
Labsheet1 stud
Labsheet1 studLabsheet1 stud
Labsheet1 stud
 
Chapter 1 part 3
Chapter 1 part 3Chapter 1 part 3
Chapter 1 part 3
 
Chapter 1 part 2
Chapter 1 part 2Chapter 1 part 2
Chapter 1 part 2
 
Chapter 1 part 1
Chapter 1 part 1Chapter 1 part 1
Chapter 1 part 1
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 

Recently uploaded

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Fp201 unit2 1

  • 1. Unit 2: Understand the basic structure of C++
  • 2. Objectives  Evolution of C++  Structure of C++ program • Preprocessor directives • Header files • Main() function • Return statement  Hands On!
  • 3. At the end of this presentation, you will be able to: • Describe the general structure of C++ programs • Write a simple C++ programme
  • 4. Bjarne Stroustrup founded C++ in mid 80’s.  C++ was developed at AT&T Bell laboratories.  Additional features than C.  Features are closer to the real world solution.
  • 5. Include File (must have) Class declaration (if any) Class Member Function definition (if any) Main function (must have)
  • 6. Header file Description <cassert> Contains macros and information for adding diagnostic that aid program debugging <cstring> Contains function prototype for C-style string processing <cmath> Contains function prototype for math library function <iostream> Contains function prototype for standard input and standard output function <iomanip> Contains function prototype for stream manipulator that enable formatting of streams of data <fstream> Contains function prototype for functions that perform input from files on disk and output to files on disk.
  • 7. <preprocessor directive> <main function> { <variable declaration> …. <C++ statement> …. <return statement(if any)> }
  • 8. //First C++ Program Comment #include <iostream> Preprocessor Directive using namespace std; int main() Main Function { int a; Variable Declaration cout << “Hello World!”; cin >> a; Statement return 0; }
  • 9. Line 1: // First C++ program • comment line. • ignored by the compiler and do not have any effect on the executable. • comments in programs help the programmer (and users) to understand what the program (or section) does. • C++ supports two types of comments:  // line comment  /* block comment */
  • 10. Line 2: #include <iostream> • lines beginning with a hash (or pound) sign (#) are directives for the preprocessor. • runs before the compiler each time the compiler is invoked. • translates any line that begins with a hash symbol (#) into a special command, getting your code file ready for the compiler. • #include <iostream> tells the preprocessor to include the iostream standard file which contains the declarations of the basic standard input-output library in C++.
  • 11. Line 3: using namespace std; • namespace allows to group entities like variables, classes, objects and functions under a name. • elements belonging to the standard C++ library are declared in what is called a std namespace. • example: cout is defined under std namespace where you can see the details in the file <iostream>. • if you omit this line, in order to use cout, you need to write the name of the namespace (std) followed by scope operator (::) before cout.  Eg: std::cout << "Hello world!";.
  • 12. Line 4: empty line • An empty line does nothing except for help the programmer to view the source code more clearly.  Line 5: int main() • actual program starts must start with a function named main(). • every C++ program has only one main() function.
  • 13.  Lines 6 and 11:  The body of the main() function is enclosed in braces ({ }).  Line 8: cout << "Hello World!";  this line is a C++ statement which performs the only action that generates a visible effect in our first program.  Each statement must end with a semicolon character (;).  Here's how cout is used: type the word cout, followed by the output insertion (or redirection) operator (<<).  Whatever follows the output insertion operator is output to the screen.  If you want to output a string of characters be sure to enclose them in double quotes (" "), as shown on line 7, "Hello World!".
  • 14. Line 10: return 0; • return statement causes the main() function (i.e. the program) to finish.
  • 15. Write a program that outputs following lines to the screen: Welcome to the world of C++
  • 16. #include <iostream> using namespace std; void main( ) { cout << “Welcome to the world of C++” }
  • 17. Why does the following program fail? #include <iostreams> using namespace std; void main() { cout << “Is there a bug here?”; }
  • 18. Because of the typo error for the preprocessor directive  Wrong : iostreams  Correct: iostream
  • 19. Explain why we use std:: in the following program. What is the output of program? #include <iostream> void main() { std::cout << " ## # # "<< std::endl; std::cout << "# ### ###"<<std::endl; std::cout << " ## # # "<< std::endl; }
  • 20. Refer to slide 11