SlideShare a Scribd company logo
C++ Programming Basics
Chapter 2:
Ms. Munazza Mah Jabeen
Assistant Professor of Computer Science
Basic Program Construction:
#include <iostream>
using namespace std;
int main()
{
cout << “Every age has a language of its ownn”;
return 0;
}
Basic Program Construction:
• Directives
• Preprocessor Directives
• Header Files
• Include Two Ways:
• #include< >
• #include “ ”
• The using Directive
• Namespaces
• Always Start with main()
• Functions
• Function Name
• Braces and the Function Body
• Program Statements
• Whitespace
• String Constants
• Statement Terminator
• Comments
• //
• /* … */
Input / Output Statements:
#include <iostream>
using namespace std;
int main()
{
int ftemp; //for temperature in Fahrenheit
cout << “Enter temperature in Fahrenheit: “;
cin >> ftemp;
int ctemp = (ftemp-32) * 5 / 9;
cout << “Equivalent in Celsius is: “ << ctemp << ‘n’;
return 0;
}
Language Basics:
Data Types
• Numeric
• Non-floating point
• Short
• Integer
• Long
• Floating –Point
• Float
• Double
• Non-Numeric
• Character
• String
• Boolean
Language Basics:
• Data Type:
• Conversion
• Casting
• Declarations
• Definitions
• Variable Names
• Initialization
• Assignment Statements
• Variables Defined at Point of Use
• The const Qualifier
• The #define Directive
#include <iostream>
using namespace std;
#define PI 3.142
main()
{
// const float PI = 3.142;
float radius=0.0, area=0.0;
cout << "Enter Radius of the Circle == > ";
cin >> radius;
area = PI * radius * radius ;
cout << " Radius of Circle is " << radius << " Area of the
Circle is " << area << endl;
}
#include<iomanip>
#include<iostream>
using namespace std;
main()
{
cout << "Lahore" << setw(20) << setfill('.') << "500 Km"<<endl;
}
IOMANIP:
• The IOMANIP Header File
• The endl Manipulator
• The setw() Manipulator
• The setfill() Manipulator
Escape Sequences:
Operators:
• Arithmetic Operators ( + , - , / , * , % )
• Increment / Decrement ( ++ , -- )
• Prefix / Postfix ( a++ , ++a , a-- , --a )
• Assignment Operator ( = )
• Arithmetic Assignment Operator ( += , -= , /= , *= , %= )
• Relational operators ( > , < , >= , <= , == , != )
• Logical Operators
• And / Or / Not ( &&, || , ! )
Header Files and Library Files:
#include <iostream> //for cout, etc.
#include <cmath> //for sqrt()
using namespace std;
int main()
{
double number, answer; //sqrt() requires type double
cout << “Enter a number: “;
cin >> number; //get the number
answer = sqrt(number); //find square root
cout << “Square root is “
<< answer << endl; //display it
return 0;
}

More Related Content

PDF
Flamingo in Production
PDF
Flamingo Core Concepts
PDF
Graphql with Flamingo
PPTX
Intro to C++
PPTX
Mca 2nd sem u-4 operator overloading
PDF
Functional Reactive Angular 2
PPTX
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
PDF
Altitude San Francisco 2018: WebAssembly Tools & Applications
Flamingo in Production
Flamingo Core Concepts
Graphql with Flamingo
Intro to C++
Mca 2nd sem u-4 operator overloading
Functional Reactive Angular 2
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Altitude San Francisco 2018: WebAssembly Tools & Applications

What's hot (20)

PDF
Lighthouse: Large-scale graph pattern matching on Giraph
PDF
Ip interface duw
PPTX
Mage Titans - Workshop - UI Components
PDF
Js interpreter interpreted
PDF
Optimizing the Grafana Platform for Flux
RTF
Convertidor de horas en C#
PDF
Regular expressions, Alex Perry, Google, PyCon2014
ODP
Use of django at jolt online v3
ODP
IIUG 2016 Gathering Informix data into R
PDF
Probability of finding a single qubit in a state
PPTX
Functional Programming
PDF
RedisGears
PDF
RedisGears: Meir Shpilraien
PDF
Flux and InfluxDB 2.0 by Paul Dix
PDF
Functional Programming with JavaScript
PPTX
C++Programming Language Tips Tricks Understandings
PDF
Basicsof c make and git for a hello qt application
PDF
Cocoa heads 09112017
PDF
Chapter24 operator-overloading
TXT
Bankers Algo Implementation
Lighthouse: Large-scale graph pattern matching on Giraph
Ip interface duw
Mage Titans - Workshop - UI Components
Js interpreter interpreted
Optimizing the Grafana Platform for Flux
Convertidor de horas en C#
Regular expressions, Alex Perry, Google, PyCon2014
Use of django at jolt online v3
IIUG 2016 Gathering Informix data into R
Probability of finding a single qubit in a state
Functional Programming
RedisGears
RedisGears: Meir Shpilraien
Flux and InfluxDB 2.0 by Paul Dix
Functional Programming with JavaScript
C++Programming Language Tips Tricks Understandings
Basicsof c make and git for a hello qt application
Cocoa heads 09112017
Chapter24 operator-overloading
Bankers Algo Implementation
Ad

Similar to C++ programming basics (20)

PPTX
CP 04.pptx
PDF
C++ L01-Variables
PDF
CP MATERIAL.pdf Computer Programming Material
PPTX
PPTX
Lec 2.pptx
PPTX
Begin with c++ Fekra Course #1
PDF
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
PPTX
Programming using c++ tool
PPT
Fp201 unit2 1
PPTX
C++ Functions
PPT
Practical basics on c++
PPTX
C++ Functions.pptx
PDF
Software Engineering
PPTX
Structure of a C++ Program in computer programming .pptx
PPT
c++ Lecture 2
PDF
Cse115 lecture04introtoc programming
PPTX
Nitin Mishra 0301EC201039 Internship PPT.pptx
DOCX
Tugas praktikukm pemrograman c++
PPTX
C++ basics
CP 04.pptx
C++ L01-Variables
CP MATERIAL.pdf Computer Programming Material
Lec 2.pptx
Begin with c++ Fekra Course #1
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
Programming using c++ tool
Fp201 unit2 1
C++ Functions
Practical basics on c++
C++ Functions.pptx
Software Engineering
Structure of a C++ Program in computer programming .pptx
c++ Lecture 2
Cse115 lecture04introtoc programming
Nitin Mishra 0301EC201039 Internship PPT.pptx
Tugas praktikukm pemrograman c++
C++ basics
Ad

More from Munazza-Mah-Jabeen (20)

PPTX
Virtual Functions
PPTX
The Standard Template Library
PPTX
Object-Oriented Software
PPTX
Templates and Exceptions
PPTX
Dictionaries and Sets
PPTX
More About Strings
PPTX
Streams and Files
PPTX
Lists and Tuples
PPT
Files and Exceptions
PPT
PPTX
PPT
Repitition Structure
PPTX
Inheritance
PPTX
Operator Overloading
PPT
Memory Management
PPTX
Arrays and Strings
PPTX
Objects and Classes
PPTX
PPTX
Structures
PPTX
Loops and Decisions
Virtual Functions
The Standard Template Library
Object-Oriented Software
Templates and Exceptions
Dictionaries and Sets
More About Strings
Streams and Files
Lists and Tuples
Files and Exceptions
Repitition Structure
Inheritance
Operator Overloading
Memory Management
Arrays and Strings
Objects and Classes
Structures
Loops and Decisions

Recently uploaded (20)

PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Pharma ospi slides which help in ospi learning
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Lesson notes of climatology university.
PDF
RMMM.pdf make it easy to upload and study
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Final Presentation General Medicine 03-08-2024.pptx
Microbial diseases, their pathogenesis and prophylaxis
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Microbial disease of the cardiovascular and lymphatic systems
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
A systematic review of self-coping strategies used by university students to ...
Pharma ospi slides which help in ospi learning
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Cell Types and Its function , kingdom of life
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
2.FourierTransform-ShortQuestionswithAnswers.pdf
Lesson notes of climatology university.
RMMM.pdf make it easy to upload and study
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf

C++ programming basics

  • 1. C++ Programming Basics Chapter 2: Ms. Munazza Mah Jabeen Assistant Professor of Computer Science
  • 2. Basic Program Construction: #include <iostream> using namespace std; int main() { cout << “Every age has a language of its ownn”; return 0; }
  • 3. Basic Program Construction: • Directives • Preprocessor Directives • Header Files • Include Two Ways: • #include< > • #include “ ” • The using Directive • Namespaces • Always Start with main() • Functions • Function Name • Braces and the Function Body • Program Statements • Whitespace • String Constants • Statement Terminator • Comments • // • /* … */
  • 4. Input / Output Statements: #include <iostream> using namespace std; int main() { int ftemp; //for temperature in Fahrenheit cout << “Enter temperature in Fahrenheit: “; cin >> ftemp; int ctemp = (ftemp-32) * 5 / 9; cout << “Equivalent in Celsius is: “ << ctemp << ‘n’; return 0; }
  • 5. Language Basics: Data Types • Numeric • Non-floating point • Short • Integer • Long • Floating –Point • Float • Double • Non-Numeric • Character • String • Boolean
  • 6. Language Basics: • Data Type: • Conversion • Casting • Declarations • Definitions • Variable Names • Initialization • Assignment Statements • Variables Defined at Point of Use • The const Qualifier • The #define Directive #include <iostream> using namespace std; #define PI 3.142 main() { // const float PI = 3.142; float radius=0.0, area=0.0; cout << "Enter Radius of the Circle == > "; cin >> radius; area = PI * radius * radius ; cout << " Radius of Circle is " << radius << " Area of the Circle is " << area << endl; }
  • 7. #include<iomanip> #include<iostream> using namespace std; main() { cout << "Lahore" << setw(20) << setfill('.') << "500 Km"<<endl; } IOMANIP: • The IOMANIP Header File • The endl Manipulator • The setw() Manipulator • The setfill() Manipulator
  • 9. Operators: • Arithmetic Operators ( + , - , / , * , % ) • Increment / Decrement ( ++ , -- ) • Prefix / Postfix ( a++ , ++a , a-- , --a ) • Assignment Operator ( = ) • Arithmetic Assignment Operator ( += , -= , /= , *= , %= ) • Relational operators ( > , < , >= , <= , == , != ) • Logical Operators • And / Or / Not ( &&, || , ! )
  • 10. Header Files and Library Files: #include <iostream> //for cout, etc. #include <cmath> //for sqrt() using namespace std; int main() { double number, answer; //sqrt() requires type double cout << “Enter a number: “; cin >> number; //get the number answer = sqrt(number); //find square root cout << “Square root is “ << answer << endl; //display it return 0; }