SlideShare une entreprise Scribd logo
1  sur  20
Object Oriented Programming: 11
Preprocessor Directives and
Program Structure in C++
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
2
Preprocessor Directives
• C++ has a small number of operations
• Many functions and symbols needed to run a
C++ program are provided as collection of
libraries
• Every library has a name and is referred to by a
header file
• Preprocessor directives are commands supplied
to the preprocessor
• All preprocessor commands begin with #
• No semicolon at the end of these commands
3
Preprocessor Directives (continued)
• Syntax to include a header file:
• For example:
#include <iostream>
– Causes the preprocessor to include the header file
iostream in the program
4
namespace and Using cin and
cout in a Program
• cin and cout are declared in the header file
iostream, but within std namespace
• To use cin and cout in a program, use the
following two statements:
#include <iostream>
using namespace std;
5
Using the string Data Type in a
Program
• To use the string type, you need to access
its definition from the header file string
• Include the following preprocessor directive:
#include <string>
6
Creating a C++ Program
• C++ program has two parts:
– Preprocessor directives
– The program
• Preprocessor directives and program
statements constitute C++ source code (.cpp)
• Compiler generates object code (.obj)
• Executable code is produced and saved in a
file with the file extension .exe
7
Creating a C++ Program (continued)
• A C++ program is a collection of functions, one
of which is the function main
• The first line of the function main is called
the heading of the function:
int main()
• The statements enclosed between the curly
braces ({ and }) form the body of the function
– Contains two types of statements:
• Declaration statements
• Executable statements
8
9
Creating a C++ Program (continued)
Sample Run:
Line 9: firstNum = 18
Line 10: Enter an integer: 15
Line 13: secondNum = 15
Line 15: The new value of firstNum = 60
10
Program Style and Form
• Every C++ program has a function main
• It must also follow the syntax rules
• Other rules serve the purpose of giving precise
meaning to the language
11
Syntax
• Errors in syntax are found in compilation
int x; //Line 1
int y //Line 2: error
double z; //Line 3
y = w + x; //Line 4: error
12
Use of Blanks
• In C++, you use one or more blanks to
separate numbers when data is input
• Used to separate reserved words and
identifiers from each other and from other
symbols
• Must never appear within a reserved word
or identifier
13
Use of Semicolons, Brackets, and
Commas
• All C++ statements end with a semicolon
– Also called a statement terminator
• { and } are not C++ statements
• Commas separate items in a list
14
Semantics
• Possible to remove all syntax errors in a
program and still not have it run
• Even if it runs, it may still not do what you
meant it to do
• For example,
2 + 3 * 5 and (2 + 3) * 5
are both syntactically correct expressions, but
have different meanings
15
Naming Identifiers
• Identifiers can be self-documenting:
– CENTIMETERS_PER_INCH
• Avoid run-together words :
– annualsale
– Solution:
• Capitalize the beginning of each new word
– annualSale
• Inserting an underscore just before a new word
– annual_sale
16
Prompt Lines
• Prompt lines: executable statements that
inform the user what to do
cout << "Please enter a number between 1 and 10 and "
<< "press the return key" << endl;
cin >> num;
17
Documentation
• A well-documented program is easier to
understand and modify
• You use comments to document programs
• Comments should appear in a program to:
– Explain the purpose of the program
– Identify who wrote it
– Explain the purpose of particular statements
18
Form and Style
• Consider two ways of declaring variables:
– Method 1
int feet, inch;
double x, y;
– Method 2
int a,b;double x,y;
• Both are correct; however, the second is hard
to read
19
More on Assignment Statements
• C++ has special assignment statements called
compound assignments
+=, -=, *=, /=, and %=
• Example:
x *= y;
Assignment
• What is the role of preprocessor directives in
C++
• Describe the general structure of a C++
program using an example program

Contenu connexe

Tendances

Database , 8 Query Optimization
Database , 8 Query OptimizationDatabase , 8 Query Optimization
Database , 8 Query Optimization
Ali Usman
 
Superscalar & superpipeline processor
Superscalar & superpipeline processorSuperscalar & superpipeline processor
Superscalar & superpipeline processor
Muhammad Ishaq
 
Dma transfer
Dma transferDma transfer
Dma transfer
gmnithya
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
Manoj Patil
 

Tendances (20)

Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
 
Database , 8 Query Optimization
Database , 8 Query OptimizationDatabase , 8 Query Optimization
Database , 8 Query Optimization
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
Data transfer and manipulation
Data transfer and manipulationData transfer and manipulation
Data transfer and manipulation
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Direct Memory Access
Direct Memory AccessDirect Memory Access
Direct Memory Access
 
Superscalar & superpipeline processor
Superscalar & superpipeline processorSuperscalar & superpipeline processor
Superscalar & superpipeline processor
 
Round robin scheduling
Round robin schedulingRound robin scheduling
Round robin scheduling
 
Time space trade off
Time space trade offTime space trade off
Time space trade off
 
Distributed dbms architectures
Distributed dbms architecturesDistributed dbms architectures
Distributed dbms architectures
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency control
 
Dma transfer
Dma transferDma transfer
Dma transfer
 
Memory Reference Instructions
Memory Reference InstructionsMemory Reference Instructions
Memory Reference Instructions
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
 
Heap Management
Heap ManagementHeap Management
Heap Management
 
Program execution, straight line sequence and branching
Program execution, straight line sequence and branchingProgram execution, straight line sequence and branching
Program execution, straight line sequence and branching
 

Similaire à Object oriented programming 11 preprocessor directives and program structure

Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
Ronaldo Aditya
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
mujeeb memon
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
ANISHYAPIT
 

Similaire à Object oriented programming 11 preprocessor directives and program structure (20)

C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
Structure
StructureStructure
Structure
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
Object oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and exampleObject oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and example
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Object oriented programming 7 first steps in oop using c++
Object oriented programming 7 first steps in oop using  c++Object oriented programming 7 first steps in oop using  c++
Object oriented programming 7 first steps in oop using c++
 
Chap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptxChap_________________1_Introduction.pptx
Chap_________________1_Introduction.pptx
 
Rr
RrRr
Rr
 
Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)Introduction to the c programming language (amazing and easy book for beginners)
Introduction to the c programming language (amazing and easy book for beginners)
 
C pdf
C pdfC pdf
C pdf
 
PPT slide_chapter 02 Basic element of C++.ppt
PPT slide_chapter 02 Basic element of C++.pptPPT slide_chapter 02 Basic element of C++.ppt
PPT slide_chapter 02 Basic element of C++.ppt
 
C++.ppt
C++.pptC++.ppt
C++.ppt
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 

Plus de Vaibhav Khanna

Plus de Vaibhav Khanna (20)

Information and network security 47 authentication applications
Information and network security 47 authentication applicationsInformation and network security 47 authentication applications
Information and network security 47 authentication applications
 
Information and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithmInformation and network security 46 digital signature algorithm
Information and network security 46 digital signature algorithm
 
Information and network security 45 digital signature standard
Information and network security 45 digital signature standardInformation and network security 45 digital signature standard
Information and network security 45 digital signature standard
 
Information and network security 44 direct digital signatures
Information and network security 44 direct digital signaturesInformation and network security 44 direct digital signatures
Information and network security 44 direct digital signatures
 
Information and network security 43 digital signatures
Information and network security 43 digital signaturesInformation and network security 43 digital signatures
Information and network security 43 digital signatures
 
Information and network security 42 security of message authentication code
Information and network security 42 security of message authentication codeInformation and network security 42 security of message authentication code
Information and network security 42 security of message authentication code
 
Information and network security 41 message authentication code
Information and network security 41 message authentication codeInformation and network security 41 message authentication code
Information and network security 41 message authentication code
 
Information and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithmInformation and network security 40 sha3 secure hash algorithm
Information and network security 40 sha3 secure hash algorithm
 
Information and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithmInformation and network security 39 secure hash algorithm
Information and network security 39 secure hash algorithm
 
Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...Information and network security 38 birthday attacks and security of hash fun...
Information and network security 38 birthday attacks and security of hash fun...
 
Information and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authenticationInformation and network security 37 hash functions and message authentication
Information and network security 37 hash functions and message authentication
 
Information and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theoremInformation and network security 35 the chinese remainder theorem
Information and network security 35 the chinese remainder theorem
 
Information and network security 34 primality
Information and network security 34 primalityInformation and network security 34 primality
Information and network security 34 primality
 
Information and network security 33 rsa algorithm
Information and network security 33 rsa algorithmInformation and network security 33 rsa algorithm
Information and network security 33 rsa algorithm
 
Information and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystemsInformation and network security 32 principles of public key cryptosystems
Information and network security 32 principles of public key cryptosystems
 
Information and network security 31 public key cryptography
Information and network security 31 public key cryptographyInformation and network security 31 public key cryptography
Information and network security 31 public key cryptography
 
Information and network security 30 random numbers
Information and network security 30 random numbersInformation and network security 30 random numbers
Information and network security 30 random numbers
 
Information and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithmInformation and network security 29 international data encryption algorithm
Information and network security 29 international data encryption algorithm
 
Information and network security 28 blowfish
Information and network security 28 blowfishInformation and network security 28 blowfish
Information and network security 28 blowfish
 
Information and network security 27 triple des
Information and network security 27 triple desInformation and network security 27 triple des
Information and network security 27 triple des
 

Dernier

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Dernier (20)

tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

Object oriented programming 11 preprocessor directives and program structure

  • 1. Object Oriented Programming: 11 Preprocessor Directives and Program Structure in C++ Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. 2 Preprocessor Directives • C++ has a small number of operations • Many functions and symbols needed to run a C++ program are provided as collection of libraries • Every library has a name and is referred to by a header file • Preprocessor directives are commands supplied to the preprocessor • All preprocessor commands begin with # • No semicolon at the end of these commands
  • 3. 3 Preprocessor Directives (continued) • Syntax to include a header file: • For example: #include <iostream> – Causes the preprocessor to include the header file iostream in the program
  • 4. 4 namespace and Using cin and cout in a Program • cin and cout are declared in the header file iostream, but within std namespace • To use cin and cout in a program, use the following two statements: #include <iostream> using namespace std;
  • 5. 5 Using the string Data Type in a Program • To use the string type, you need to access its definition from the header file string • Include the following preprocessor directive: #include <string>
  • 6. 6 Creating a C++ Program • C++ program has two parts: – Preprocessor directives – The program • Preprocessor directives and program statements constitute C++ source code (.cpp) • Compiler generates object code (.obj) • Executable code is produced and saved in a file with the file extension .exe
  • 7. 7 Creating a C++ Program (continued) • A C++ program is a collection of functions, one of which is the function main • The first line of the function main is called the heading of the function: int main() • The statements enclosed between the curly braces ({ and }) form the body of the function – Contains two types of statements: • Declaration statements • Executable statements
  • 8. 8
  • 9. 9 Creating a C++ Program (continued) Sample Run: Line 9: firstNum = 18 Line 10: Enter an integer: 15 Line 13: secondNum = 15 Line 15: The new value of firstNum = 60
  • 10. 10 Program Style and Form • Every C++ program has a function main • It must also follow the syntax rules • Other rules serve the purpose of giving precise meaning to the language
  • 11. 11 Syntax • Errors in syntax are found in compilation int x; //Line 1 int y //Line 2: error double z; //Line 3 y = w + x; //Line 4: error
  • 12. 12 Use of Blanks • In C++, you use one or more blanks to separate numbers when data is input • Used to separate reserved words and identifiers from each other and from other symbols • Must never appear within a reserved word or identifier
  • 13. 13 Use of Semicolons, Brackets, and Commas • All C++ statements end with a semicolon – Also called a statement terminator • { and } are not C++ statements • Commas separate items in a list
  • 14. 14 Semantics • Possible to remove all syntax errors in a program and still not have it run • Even if it runs, it may still not do what you meant it to do • For example, 2 + 3 * 5 and (2 + 3) * 5 are both syntactically correct expressions, but have different meanings
  • 15. 15 Naming Identifiers • Identifiers can be self-documenting: – CENTIMETERS_PER_INCH • Avoid run-together words : – annualsale – Solution: • Capitalize the beginning of each new word – annualSale • Inserting an underscore just before a new word – annual_sale
  • 16. 16 Prompt Lines • Prompt lines: executable statements that inform the user what to do cout << "Please enter a number between 1 and 10 and " << "press the return key" << endl; cin >> num;
  • 17. 17 Documentation • A well-documented program is easier to understand and modify • You use comments to document programs • Comments should appear in a program to: – Explain the purpose of the program – Identify who wrote it – Explain the purpose of particular statements
  • 18. 18 Form and Style • Consider two ways of declaring variables: – Method 1 int feet, inch; double x, y; – Method 2 int a,b;double x,y; • Both are correct; however, the second is hard to read
  • 19. 19 More on Assignment Statements • C++ has special assignment statements called compound assignments +=, -=, *=, /=, and %= • Example: x *= y;
  • 20. Assignment • What is the role of preprocessor directives in C++ • Describe the general structure of a C++ program using an example program