SlideShare a Scribd company logo
By
Salman Khizer
NUML University
Faisalabad Campus
Programming Fundamentals
Week 2
Development Environment
 Bloodshed Dev-C++
Cont…
 Turbo C++
Features of C++
 Case Sensitivity
 Convenient language
 Well structured
 Object oriented
 Speed
 Popular
 Modular programming
 Powerful for Development
Basic Structure of C++
 The format of writing program in C++ is called its/language
structure.
It consist of the following:
1. Preprocessor Directive (Header files)
2. Main() function
3. Program Body
Preprocessor Directive
 Start with # symbol
 This one directs the preprocessor to add some predefined source
code to our existing source code before the compiler begins to
process it.
 The #include directive specifies a file, called a header, that
contains
 the specifications for the library code.
 Name of header file written in angle brackets < > .
 Example
 #include<iostream.h> Basic Header files
 #include<conio.h>
 #include<math.h>
 Etc etc.
Main Function & Program Body
 Main ()
 Declares that start of main program and end of header part.
 void main()
{
}
 Program Body
 Includes instructions for C++ and for execution of program
 void main()
{
Body of Program / Main function (to process)
}
C++ Statements
 Statement in a language is an instruction for the computer to
perform a task.
 It is written in curly braces { … }.
 As before it is mentioned in„body of the main function‟.
 Example
#include<iostream>
Using namespace std;
int main()
{
cout<<“Welcome to Riphah College of Computing.”;
return 0;
}
Debugging in C++
 if you missed out or enter something incorrectly into your
program, the compiler will report a syntax error message
when it tries to compile it.
 An error is known as„Bug‟.
 Finding and removing bugs in a language is known as
„Debugging‟.
 Types of Errors
1. Fatal Syntax error
2. Logical error
3. Run-time error
Identifier
 An identifier is a word used to name things.
 These are the names used to represent variable, constant, function and
labels .
 Identifiers are limited to 31 characters only
 Names such as area, sum, and UserName are much better than the
equally permissible a, s, and u.
 Rules
 Identifiers must contain at least one character.
 The first character must be an alphabetic letter (upper or lower case) or
the (_) underscore.
 Allows only alphabets, numbers and underscore
 Reserved words/keywords cannot be used for this purpose.
 No other characters (including spaces) are permitted in identifiers.
Types of identifiers
 Standard Identifiers
 A type of identifier that has special meaning in C++ is known as
standard identifier.You cannot use such identifier for your own
specific purpose because it is predefined in C++.
 For example cout, void, if, int and float etc. are examples of
standard identifier.
 User-defined Identifiers
 The type of identifier that is defined by the programmer to access
memory location to define his/her own special purpose of thing.
 Such identifiers are used to store data and results of programs.
 For example average, num, result, area etc.
Identifiers or C++ Keywords
Fundamentals of Programming
Constructs
 DataTypes
 Variables
 Variable Declarations and
Initialization
 Constants & its types
 Expression
 Operators
 Assignment Statement
 CompoundAssignment
Operator
 Increment/Decrement
Operator
 Operator Precedence
 Input and Output
 Manipulators
Data Types
 C++ provides built-in data types that correspond to integers,
characters, floating-point values, and Boolean values.
 These are the ways that data is commonly stored and manipulated by a
program.
 At the core of the C++ type system are the seven basic data types
shown here:
 The data type modifiers are
listed here:
 signed
 unsigned
 long
 short
Data Types
 FollowingTable shows all valid combinations of the basic types and the
type modifiers.
 Table below shows typical bit widths and ranges for the C++ data types
in a 32-bit environment, such as that used byWindows XP.
Main Data Types
 We will do mostly exercise related to following four data types
that are frequently used as built in data types:
1. Int
2. Real data types
3. Char
4. bool
 The number four (4) is an example of a numeric value. In
mathematics, 4 is an integer value that has range –2,147,483,648 to
+2,147,483,647..
 Integers are whole numbers, which means they have no fractional
parts, and an integer can be positive, negative, or zero. Examples of
integers include 4, 19, 0, and1005.
 In contrast, 4.5 is not an integer, since it is not a whole number.
#include <iostream.h>
#include <conio.h>
void main ()
{
int x;
x = 15;
cout<<“Value of X = ” ;
cout << x ;
getch ();
}
int data type
Table below shows Characteristics of Visual C++
Integer Data Types
 Following program shows the difference between signed and
unsigned integers.
#include <iostream.h>
#include <conio.h>
void main ()
{
short int i; // a signed short integer
unsigned short j; // an unsigned short integer
j = 60000; // j has range 0 to 65,535 and i has -32,768 to 32,767
i = j; //
cout << i << “ ” << j ;
getch ();
}
Try this example
 Real data is numeric value with decimal point or fraction. It is also
called floating point number. It also includes both positive and negative
values.
 For example, the formula from mathematics to compute the area of a
circle given the circle‟s radius, involves the value pi, which is
approximately 3.14159.
 The minus sign (–) is used to indicate negative value. If no sign is used,
the value is positive by default.
 Some examples of real values are 11.5, 7. 009 and – 215.798 etc.
#include <iostream.h>
#include <conio.h>
void main ()
{
float x;
x = 25.87;
cout<<“Value of X = ”;
cout << x ;
getch ();
}
Real Data Types
Following example calculate the area of a circle
#include <iostream.h>
#include <conio.h>
void main ()
{
float radius, pi, area_circle;
radius = 5;
pi = 3.14159;
cout<<“Area of Circle is = ”;
cout << pi * radius * radius ;
getch ();
}
Table below shows Characteristics of Floating-point
Numbers on 32-bit Computer Systems
 This data type is used to store character value. It takes 1 bye in memory. It is
used to represent a letter, number or punctuation mark and a few other
symbols.
 In C++ source code, characters are enclosed by single quotes ('),
for example char ch = 'A„;
 It can represent single character such as„a‟,„x‟,„9‟, and„#‟.The character„9‟
is manipulated differently than integer 9. however it is possible to perform
mathematical operation on character values.
 Standard ASCII can represent 128 different characters.
#include <iostream>
#include <conio.h>
void main ()
{
char ch1, ch2;
ch1 = „M‟;
ch2 = „N‟;
cout<<“character are: ” << ch1 << <<“and ” << ch2 „n‟ ;
getch ();
}
Character data type
ASCII codes for characters
Try this example
#include <iostream>
#include <conio.h>
void main ()
{
char ch1, ch2;
ch1 = 65;
ch2 = „A‟;
cout << ch1 << ", " << ch2 << ", " << 'A' << 'n';
getch ();
}
Try to guess the output of program
Explanation
 The program will display following output.
A,A,A
 The first A is printed because the statement ch1 = 65; which
assigns theASCII code forA to ch1.
 The second A is printed because the statement ch2 = 'A';
assigns the literal character A to ch2.
 The third A is printed because the literal character 'A' is sent
directly to the output stream.
 Standard (double) quotes (") are reserved for strings, which are
composed of characters, but strings and chars are very different.
bool data type
 The bool type is a relatively recent addition to C++. It stores
Boolean (that is, true/false) values.
 C++ defines two Boolean constants, true and false, which are the
only two values that a bool value can have.
 it is important to understand how true and false are defined by
C++. One of the fundamental concepts in C++ is that any nonzero
value is interpreted as true and zero is false.
 This concept is fully compatible with the bool data type because
when used in a Boolean expression, C++ automatically converts any
nonzero value into true. It automatically converts zero into false.
 The reverse is also true.
bool data type
#include <iostream>
#include <conio.h>
void main ()
{
bool b;
b = false;
cout<< "b is " << b << „n‟;
b = true;
cout<< "b is " << b << „n‟;
if (b)
cout<< "This is executed. n " ;
b = false;
cout<< "This is not executed. n " ;
cout<< "10 > 9 is " << (10 > 9) << " n " ;;
getch ();
}
Try to guess the output of program
Variables
 A variable is a named memory location or memory cell.
 It is used to hold program‟s input and computational results.
 Variable value may change, however name can‟t be changed.
 In algebra, variables are used to represent numbers.The same
is true in C++, except C++ variables also can represent
values other than numbers.
 C++ is a case sensitive language uppercase and lower case
are different: number is different from Number or nUmber.
 Valid identifiers: int abc, char aBc, int first_var, float
_first
 Invalid identifiers: int 3bc, int a*b, int #a, int void
Variables
 The variable are created in RAM, that‟s why any value stored in
it is also temporary because RAM is temporary memory.
 When program ends, data in variable is automatically removed.
 Following things are associated with any variable.
1. Name of variable
2. Address of variable
3. Computer memory
Marks
25 Content of variable
Variable Naming Conventions
 PascalCase and camelCase
 camelCase variable names examples:
number, firstName, dateOfBirth
 PascalCase variable names examples:
Number, FirstName, DateOfBirth
Variable Declaration & Initialization
 The process of specifying variable name and its type is called
variable declaration.
 It can be declared anywhere in the program before its use
 The syntax of declaring variables is as follows:
data_type variable_name;
 data_type: it indicates type of data can be stored and size of variable.
 variable_name: it refers to the memory location of variable.
 The process of assigning a value to a variable at the time of
declaration is known as variable initialization.
 The equal sign = is used
 The syntax of intializing a variable is as follows:
type_name variable_name = value;
Examples of Variable Declarations &
Initialization
 int myAge, char countryName;
 int a, b, c;
 int firstNumber =10;
 int secondNumber=11;
 int thirdNumber;
 thirdNumber=23;
 float fnumber;
 fnumber=19.8;
Constants & its types
 A quantity or number that cannot be changed.
 Two types of constants in C++.
1. Literal constant
 Types of literal constant (according to data types)
 Integer constant
 Floating point constant
 Character constant
 String constant
2. Symbolic constant is a name given to values that can‟t be
changed.A constant must be initialized. e.g. PI can be used
to indicate value of 3.141593.
Week 02_Development Environment of C++.pdf
Ad

More Related Content

Similar to Week 02_Development Environment of C++.pdf (20)

Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
programming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptxprogramming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptx
BamaSivasubramanianP
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
20EUEE018DEEPAKM
 
C intro
C introC intro
C intro
SHIKHA GAUTAM
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
Manzoor ALam
 
C and C++ programming basics for Beginners.pptx
C and C++ programming basics for Beginners.pptxC and C++ programming basics for Beginners.pptx
C and C++ programming basics for Beginners.pptx
renuvprajapati
 
C Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdfC Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdf
poongothai11
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
Widad Jamaluddin
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 
Ch02
Ch02Ch02
Ch02
Arriz San Juan
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptxKMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
JessylyneSophia
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
Kuntal Bhowmick
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
Shankar Gangaju
 
C program
C programC program
C program
AJAL A J
 
C programming language
C programming languageC programming language
C programming language
Abin Rimal
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.pptCPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
abdurrahimk182
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
kiranrajat
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
programming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptxprogramming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptx
BamaSivasubramanianP
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
Manzoor ALam
 
C and C++ programming basics for Beginners.pptx
C and C++ programming basics for Beginners.pptxC and C++ programming basics for Beginners.pptx
C and C++ programming basics for Beginners.pptx
renuvprajapati
 
C Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdfC Programming Language Introduction and C Tokens.pdf
C Programming Language Introduction and C Tokens.pdf
poongothai11
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
Hattori Sidek
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
Rokonuzzaman Rony
 
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptxKMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
JessylyneSophia
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
Kuntal Bhowmick
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
Shankar Gangaju
 
C programming language
C programming languageC programming language
C programming language
Abin Rimal
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.pptCPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
CPLUSPLUS UET PESHAWAR BS ELECTRICAL 2ND SEMSTER Lecture02.ppt
abdurrahimk182
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
kiranrajat
 

Recently uploaded (20)

The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Ad

Week 02_Development Environment of C++.pdf

  • 1. By Salman Khizer NUML University Faisalabad Campus Programming Fundamentals Week 2
  • 4. Features of C++  Case Sensitivity  Convenient language  Well structured  Object oriented  Speed  Popular  Modular programming  Powerful for Development
  • 5. Basic Structure of C++  The format of writing program in C++ is called its/language structure. It consist of the following: 1. Preprocessor Directive (Header files) 2. Main() function 3. Program Body
  • 6. Preprocessor Directive  Start with # symbol  This one directs the preprocessor to add some predefined source code to our existing source code before the compiler begins to process it.  The #include directive specifies a file, called a header, that contains  the specifications for the library code.  Name of header file written in angle brackets < > .  Example  #include<iostream.h> Basic Header files  #include<conio.h>  #include<math.h>  Etc etc.
  • 7. Main Function & Program Body  Main ()  Declares that start of main program and end of header part.  void main() { }  Program Body  Includes instructions for C++ and for execution of program  void main() { Body of Program / Main function (to process) }
  • 8. C++ Statements  Statement in a language is an instruction for the computer to perform a task.  It is written in curly braces { … }.  As before it is mentioned in„body of the main function‟.  Example #include<iostream> Using namespace std; int main() { cout<<“Welcome to Riphah College of Computing.”; return 0; }
  • 9. Debugging in C++  if you missed out or enter something incorrectly into your program, the compiler will report a syntax error message when it tries to compile it.  An error is known as„Bug‟.  Finding and removing bugs in a language is known as „Debugging‟.  Types of Errors 1. Fatal Syntax error 2. Logical error 3. Run-time error
  • 10. Identifier  An identifier is a word used to name things.  These are the names used to represent variable, constant, function and labels .  Identifiers are limited to 31 characters only  Names such as area, sum, and UserName are much better than the equally permissible a, s, and u.  Rules  Identifiers must contain at least one character.  The first character must be an alphabetic letter (upper or lower case) or the (_) underscore.  Allows only alphabets, numbers and underscore  Reserved words/keywords cannot be used for this purpose.  No other characters (including spaces) are permitted in identifiers.
  • 11. Types of identifiers  Standard Identifiers  A type of identifier that has special meaning in C++ is known as standard identifier.You cannot use such identifier for your own specific purpose because it is predefined in C++.  For example cout, void, if, int and float etc. are examples of standard identifier.  User-defined Identifiers  The type of identifier that is defined by the programmer to access memory location to define his/her own special purpose of thing.  Such identifiers are used to store data and results of programs.  For example average, num, result, area etc.
  • 12. Identifiers or C++ Keywords
  • 13. Fundamentals of Programming Constructs  DataTypes  Variables  Variable Declarations and Initialization  Constants & its types  Expression  Operators  Assignment Statement  CompoundAssignment Operator  Increment/Decrement Operator  Operator Precedence  Input and Output  Manipulators
  • 14. Data Types  C++ provides built-in data types that correspond to integers, characters, floating-point values, and Boolean values.  These are the ways that data is commonly stored and manipulated by a program.  At the core of the C++ type system are the seven basic data types shown here:  The data type modifiers are listed here:  signed  unsigned  long  short
  • 15. Data Types  FollowingTable shows all valid combinations of the basic types and the type modifiers.
  • 16.  Table below shows typical bit widths and ranges for the C++ data types in a 32-bit environment, such as that used byWindows XP.
  • 17. Main Data Types  We will do mostly exercise related to following four data types that are frequently used as built in data types: 1. Int 2. Real data types 3. Char 4. bool
  • 18.  The number four (4) is an example of a numeric value. In mathematics, 4 is an integer value that has range –2,147,483,648 to +2,147,483,647..  Integers are whole numbers, which means they have no fractional parts, and an integer can be positive, negative, or zero. Examples of integers include 4, 19, 0, and1005.  In contrast, 4.5 is not an integer, since it is not a whole number. #include <iostream.h> #include <conio.h> void main () { int x; x = 15; cout<<“Value of X = ” ; cout << x ; getch (); } int data type
  • 19. Table below shows Characteristics of Visual C++ Integer Data Types
  • 20.  Following program shows the difference between signed and unsigned integers. #include <iostream.h> #include <conio.h> void main () { short int i; // a signed short integer unsigned short j; // an unsigned short integer j = 60000; // j has range 0 to 65,535 and i has -32,768 to 32,767 i = j; // cout << i << “ ” << j ; getch (); } Try this example
  • 21.  Real data is numeric value with decimal point or fraction. It is also called floating point number. It also includes both positive and negative values.  For example, the formula from mathematics to compute the area of a circle given the circle‟s radius, involves the value pi, which is approximately 3.14159.  The minus sign (–) is used to indicate negative value. If no sign is used, the value is positive by default.  Some examples of real values are 11.5, 7. 009 and – 215.798 etc. #include <iostream.h> #include <conio.h> void main () { float x; x = 25.87; cout<<“Value of X = ”; cout << x ; getch (); } Real Data Types
  • 22. Following example calculate the area of a circle #include <iostream.h> #include <conio.h> void main () { float radius, pi, area_circle; radius = 5; pi = 3.14159; cout<<“Area of Circle is = ”; cout << pi * radius * radius ; getch (); }
  • 23. Table below shows Characteristics of Floating-point Numbers on 32-bit Computer Systems
  • 24.  This data type is used to store character value. It takes 1 bye in memory. It is used to represent a letter, number or punctuation mark and a few other symbols.  In C++ source code, characters are enclosed by single quotes ('), for example char ch = 'A„;  It can represent single character such as„a‟,„x‟,„9‟, and„#‟.The character„9‟ is manipulated differently than integer 9. however it is possible to perform mathematical operation on character values.  Standard ASCII can represent 128 different characters. #include <iostream> #include <conio.h> void main () { char ch1, ch2; ch1 = „M‟; ch2 = „N‟; cout<<“character are: ” << ch1 << <<“and ” << ch2 „n‟ ; getch (); } Character data type
  • 25. ASCII codes for characters
  • 26. Try this example #include <iostream> #include <conio.h> void main () { char ch1, ch2; ch1 = 65; ch2 = „A‟; cout << ch1 << ", " << ch2 << ", " << 'A' << 'n'; getch (); } Try to guess the output of program
  • 27. Explanation  The program will display following output. A,A,A  The first A is printed because the statement ch1 = 65; which assigns theASCII code forA to ch1.  The second A is printed because the statement ch2 = 'A'; assigns the literal character A to ch2.  The third A is printed because the literal character 'A' is sent directly to the output stream.  Standard (double) quotes (") are reserved for strings, which are composed of characters, but strings and chars are very different.
  • 28. bool data type  The bool type is a relatively recent addition to C++. It stores Boolean (that is, true/false) values.  C++ defines two Boolean constants, true and false, which are the only two values that a bool value can have.  it is important to understand how true and false are defined by C++. One of the fundamental concepts in C++ is that any nonzero value is interpreted as true and zero is false.  This concept is fully compatible with the bool data type because when used in a Boolean expression, C++ automatically converts any nonzero value into true. It automatically converts zero into false.  The reverse is also true.
  • 29. bool data type #include <iostream> #include <conio.h> void main () { bool b; b = false; cout<< "b is " << b << „n‟; b = true; cout<< "b is " << b << „n‟; if (b) cout<< "This is executed. n " ; b = false; cout<< "This is not executed. n " ; cout<< "10 > 9 is " << (10 > 9) << " n " ;; getch (); } Try to guess the output of program
  • 30. Variables  A variable is a named memory location or memory cell.  It is used to hold program‟s input and computational results.  Variable value may change, however name can‟t be changed.  In algebra, variables are used to represent numbers.The same is true in C++, except C++ variables also can represent values other than numbers.  C++ is a case sensitive language uppercase and lower case are different: number is different from Number or nUmber.  Valid identifiers: int abc, char aBc, int first_var, float _first  Invalid identifiers: int 3bc, int a*b, int #a, int void
  • 31. Variables  The variable are created in RAM, that‟s why any value stored in it is also temporary because RAM is temporary memory.  When program ends, data in variable is automatically removed.  Following things are associated with any variable. 1. Name of variable 2. Address of variable 3. Computer memory Marks 25 Content of variable
  • 32. Variable Naming Conventions  PascalCase and camelCase  camelCase variable names examples: number, firstName, dateOfBirth  PascalCase variable names examples: Number, FirstName, DateOfBirth
  • 33. Variable Declaration & Initialization  The process of specifying variable name and its type is called variable declaration.  It can be declared anywhere in the program before its use  The syntax of declaring variables is as follows: data_type variable_name;  data_type: it indicates type of data can be stored and size of variable.  variable_name: it refers to the memory location of variable.  The process of assigning a value to a variable at the time of declaration is known as variable initialization.  The equal sign = is used  The syntax of intializing a variable is as follows: type_name variable_name = value;
  • 34. Examples of Variable Declarations & Initialization  int myAge, char countryName;  int a, b, c;  int firstNumber =10;  int secondNumber=11;  int thirdNumber;  thirdNumber=23;  float fnumber;  fnumber=19.8;
  • 35. Constants & its types  A quantity or number that cannot be changed.  Two types of constants in C++. 1. Literal constant  Types of literal constant (according to data types)  Integer constant  Floating point constant  Character constant  String constant 2. Symbolic constant is a name given to values that can‟t be changed.A constant must be initialized. e.g. PI can be used to indicate value of 3.141593.
  翻译: