SlideShare a Scribd company logo
1 of 17
Download to read offline
Introduction to Programming in C++
Eight Edition
Lesson 3.1:
Variables and Constants
An Introduction to Programming with C++, Eight Edition
• Distinguish among a variable, a named constant, and a
literal constant
• Explain how data is stored in memory
• Select an appropriate name, data type, and initial value
for a memory location
• Declare a memory location in C++
Objectives
2
An Introduction to Programming with C++, Eight Edition
• After Step 3, programmer has an algorithm and has
desk-checked it
• The fourth step in the process is coding the algorithm
into a program
• The step begins by assigning a descriptive name, data
type, and (optionally) initial value to each unique input,
processing, and output item in the IPO chart
• These are used to store the item in the computer’s
internal memory
Beginning Step 4 in the Problem-
Solving Process
3
An Introduction to Programming with C++, Eight Edition
• Computer’s internal memory is composed of memory
locations, each with a unique numeric address
• Similar to collection of storage bins
• Each address can store one item at a time
• Address can contain numbers, text, or program
instructions
• To use a memory location, programmer must reserve
the address, called declaring
Internal Memory
4
An Introduction to Programming with C++, Eight Edition
• Declaring a memory location is done with an instruction
that assigns a name, data type, and (optional) initial
value
• The name allows the programmer to refer to the
memory location elsewhere in the program using a
descriptive word, rather than the numeric address
• The data type indicates what type of information the
address will store (e.g., number or text)
Internal Memory (cont’d.)
5
An Introduction to Programming with C++, Eight Edition
• Two types of memory locations can be declared:
variables and named constants
• Variables are memory locations whose values can
change during runtime (when the program is running)
• Most memory locations are variables
• Named constants are memory locations whose values
cannot change during program execution
Internal Memory (cont’d.)
6
An Introduction to Programming with C++, Eight Edition
Internal Memory (cont’d.)
7
Figure 3-1 Illustration of show boxes and memory locations
An Introduction to Programming with C++, Eight Edition
• Name (identifier) assigned to a memory location should
be descriptive
• Should help the programmer/other programmers
remember/understand the memory location’s purpose
• Should be as short as possible while still being
descriptive (especially if referenced often)
• Short names are easier to read and result in more
concise code
Selecting a Name for a Memory Location
8
An Introduction to Programming with C++, Eight Edition
• Rules for memory location names/identifiers in C++
– Name must begin with a letter and contain only letters,
numbers, and the underscore character
– No punctuation marks, spaces, or other special characters
(such as $ or %) are allowed
– Cannot be a keyword (word that has special meaning in
C++)
– Names are case sensitive
• Example: discount is different from DISCOUNT
and from Discount
Selecting a Name for a Memory Location (cont’d.)
9
An Introduction to Programming with C++, Eight Edition
• Most programmers use uppercase letters for named
constants and lowercase for variables
– Example: PI (constant), radius (variable)
• If constants contain more than one word, separate
words with underscores
– Example: TAX_RATE
• If variables contain more than one word, capitalize the
first letter of each word after the first (called camel case)
– Example: adjustedGrossIncome
Selecting a Name for a Memory
Location (cont’d.)
10
An Introduction to Programming with C++, Eight Edition
A C++ Keywords
11
An Introduction to Programming with C++, Eight Edition
A C++ Keywords
12
An Introduction to Programming with C++, Eight Edition
Selecting a Name for a Memory
Location (cont’d.)
13
An Introduction to Programming with C++, Eight Edition
Revisiting the Addison O’Reilly Problem
14
Figure 3-3 Problem specification, IPO chart, and desk-check table from Chapter 2
An Introduction to Programming with C++, Eight Edition
• IPO chart contains four input, processing, and output
items
• Four memory locations are needed to store the values of
the items
• Memory locations will be variables since their values will
change during runtime
Revisiting the Addison O’Reilly Problem
(cont’d.)
15
An Introduction to Programming with C++, Eight Edition
Revisiting the Addison O’Reilly
Problem (cont’d.)
16
An Introduction to Programming with C++, Eight Edition
The End ♥ ♥ ♥
17

More Related Content

What's hot

Programming in c (importance of c)
Programming in c (importance of c)Programming in c (importance of c)
Programming in c (importance of c)ViswanathanS21
 
test(3)arithmetic in c
test(3)arithmetic in ctest(3)arithmetic in c
test(3)arithmetic in cJaya Malathy
 
Code Optimization
Code OptimizationCode Optimization
Code OptimizationAkhil Kaushik
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14IIUM
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14IIUM
 
Chapter 02 - Problem Solving
Chapter 02 - Problem SolvingChapter 02 - Problem Solving
Chapter 02 - Problem SolvingLuis Daniel Serrano
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generatorvinithapanneer
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
CIS110 Computer Programming Design Chapter (6)
CIS110 Computer Programming Design Chapter  (6)CIS110 Computer Programming Design Chapter  (6)
CIS110 Computer Programming Design Chapter (6)Dr. Ahmed Al Zaidy
 
Verilog operators
Verilog operatorsVerilog operators
Verilog operatorsDr.YNM
 
Data structures algorithms basics
Data structures   algorithms basicsData structures   algorithms basics
Data structures algorithms basicsayeshasafdar8
 
Basic Algorithm @PPSC(1)
Basic Algorithm @PPSC(1)Basic Algorithm @PPSC(1)
Basic Algorithm @PPSC(1)Amiya Bhusan
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazationSiva Sathya
 
Ch02
Ch02Ch02
Ch02laffy14
 

What's hot (20)

Programming in c (importance of c)
Programming in c (importance of c)Programming in c (importance of c)
Programming in c (importance of c)
 
test(3)arithmetic in c
test(3)arithmetic in ctest(3)arithmetic in c
test(3)arithmetic in c
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
 
Chapter 02 - Problem Solving
Chapter 02 - Problem SolvingChapter 02 - Problem Solving
Chapter 02 - Problem Solving
 
Issues in design_of_code_generator
Issues in design_of_code_generatorIssues in design_of_code_generator
Issues in design_of_code_generator
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Compiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent OptimizationsCompiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent Optimizations
 
Ppl
PplPpl
Ppl
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Lesson 10
Lesson 10Lesson 10
Lesson 10
 
CIS110 Computer Programming Design Chapter (6)
CIS110 Computer Programming Design Chapter  (6)CIS110 Computer Programming Design Chapter  (6)
CIS110 Computer Programming Design Chapter (6)
 
Verilog operators
Verilog operatorsVerilog operators
Verilog operators
 
Data structures algorithms basics
Data structures   algorithms basicsData structures   algorithms basics
Data structures algorithms basics
 
Functions
FunctionsFunctions
Functions
 
Basic Algorithm @PPSC(1)
Basic Algorithm @PPSC(1)Basic Algorithm @PPSC(1)
Basic Algorithm @PPSC(1)
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
 
Ch02
Ch02Ch02
Ch02
 

Similar to Lesson 3.1 variables and constant

Chapter 3 - Variables and Constants
Chapter 3 - Variables and ConstantsChapter 3 - Variables and Constants
Chapter 3 - Variables and Constantsmshellman
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfAbrehamKassa
 
Rr
RrRr
RrVK AG
 
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
 
C pdf
C pdfC pdf
C pdfamit9765
 
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 pptANISHYAPIT
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDFSuraj Das
 
Presentation c++
Presentation c++Presentation c++
Presentation c++JosephAlex21
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptxChapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptxrajinevitable05
 
Aniket tore
Aniket toreAniket tore
Aniket toreanikettore1
 
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 REDDYMalikireddy Bramhananda Reddy
 

Similar to Lesson 3.1 variables and constant (20)

Chapter 3 - Variables and Constants
Chapter 3 - Variables and ConstantsChapter 3 - Variables and Constants
Chapter 3 - Variables and Constants
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Chap 2 c++
Chap 2 c++Chap 2 c++
Chap 2 c++
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdf
 
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
 
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
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptxChapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
 
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
 

More from MLG College of Learning, Inc (20)

PC111.Lesson2
PC111.Lesson2PC111.Lesson2
PC111.Lesson2
 
PC111.Lesson1
PC111.Lesson1PC111.Lesson1
PC111.Lesson1
 
PC111-lesson1.pptx
PC111-lesson1.pptxPC111-lesson1.pptx
PC111-lesson1.pptx
 
PC LEESOON 6.pptx
PC LEESOON 6.pptxPC LEESOON 6.pptx
PC LEESOON 6.pptx
 
PC 106 PPT-09.pptx
PC 106 PPT-09.pptxPC 106 PPT-09.pptx
PC 106 PPT-09.pptx
 
PC 106 PPT-07
PC 106 PPT-07PC 106 PPT-07
PC 106 PPT-07
 
PC 106 PPT-01
PC 106 PPT-01PC 106 PPT-01
PC 106 PPT-01
 
PC 106 PPT-06
PC 106 PPT-06PC 106 PPT-06
PC 106 PPT-06
 
PC 106 PPT-05
PC 106 PPT-05PC 106 PPT-05
PC 106 PPT-05
 
PC 106 Slide 04
PC 106 Slide 04PC 106 Slide 04
PC 106 Slide 04
 
PC 106 Slide no.02
PC 106 Slide no.02PC 106 Slide no.02
PC 106 Slide no.02
 
pc-106-slide-3
pc-106-slide-3pc-106-slide-3
pc-106-slide-3
 
PC 106 Slide 2
PC 106 Slide 2PC 106 Slide 2
PC 106 Slide 2
 
PC 106 Slide 1.pptx
PC 106 Slide 1.pptxPC 106 Slide 1.pptx
PC 106 Slide 1.pptx
 
Db2 characteristics of db ms
Db2 characteristics of db msDb2 characteristics of db ms
Db2 characteristics of db ms
 
Db1 introduction
Db1 introductionDb1 introduction
Db1 introduction
 
Lesson 3.2
Lesson 3.2Lesson 3.2
Lesson 3.2
 
Lesson 3.1
Lesson 3.1Lesson 3.1
Lesson 3.1
 
Lesson 1.6
Lesson 1.6Lesson 1.6
Lesson 1.6
 
Lesson 3.2
Lesson 3.2Lesson 3.2
Lesson 3.2
 

Recently uploaded

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 

Lesson 3.1 variables and constant

  • 1. Introduction to Programming in C++ Eight Edition Lesson 3.1: Variables and Constants
  • 2. An Introduction to Programming with C++, Eight Edition • Distinguish among a variable, a named constant, and a literal constant • Explain how data is stored in memory • Select an appropriate name, data type, and initial value for a memory location • Declare a memory location in C++ Objectives 2
  • 3. An Introduction to Programming with C++, Eight Edition • After Step 3, programmer has an algorithm and has desk-checked it • The fourth step in the process is coding the algorithm into a program • The step begins by assigning a descriptive name, data type, and (optionally) initial value to each unique input, processing, and output item in the IPO chart • These are used to store the item in the computer’s internal memory Beginning Step 4 in the Problem- Solving Process 3
  • 4. An Introduction to Programming with C++, Eight Edition • Computer’s internal memory is composed of memory locations, each with a unique numeric address • Similar to collection of storage bins • Each address can store one item at a time • Address can contain numbers, text, or program instructions • To use a memory location, programmer must reserve the address, called declaring Internal Memory 4
  • 5. An Introduction to Programming with C++, Eight Edition • Declaring a memory location is done with an instruction that assigns a name, data type, and (optional) initial value • The name allows the programmer to refer to the memory location elsewhere in the program using a descriptive word, rather than the numeric address • The data type indicates what type of information the address will store (e.g., number or text) Internal Memory (cont’d.) 5
  • 6. An Introduction to Programming with C++, Eight Edition • Two types of memory locations can be declared: variables and named constants • Variables are memory locations whose values can change during runtime (when the program is running) • Most memory locations are variables • Named constants are memory locations whose values cannot change during program execution Internal Memory (cont’d.) 6
  • 7. An Introduction to Programming with C++, Eight Edition Internal Memory (cont’d.) 7 Figure 3-1 Illustration of show boxes and memory locations
  • 8. An Introduction to Programming with C++, Eight Edition • Name (identifier) assigned to a memory location should be descriptive • Should help the programmer/other programmers remember/understand the memory location’s purpose • Should be as short as possible while still being descriptive (especially if referenced often) • Short names are easier to read and result in more concise code Selecting a Name for a Memory Location 8
  • 9. An Introduction to Programming with C++, Eight Edition • Rules for memory location names/identifiers in C++ – Name must begin with a letter and contain only letters, numbers, and the underscore character – No punctuation marks, spaces, or other special characters (such as $ or %) are allowed – Cannot be a keyword (word that has special meaning in C++) – Names are case sensitive • Example: discount is different from DISCOUNT and from Discount Selecting a Name for a Memory Location (cont’d.) 9
  • 10. An Introduction to Programming with C++, Eight Edition • Most programmers use uppercase letters for named constants and lowercase for variables – Example: PI (constant), radius (variable) • If constants contain more than one word, separate words with underscores – Example: TAX_RATE • If variables contain more than one word, capitalize the first letter of each word after the first (called camel case) – Example: adjustedGrossIncome Selecting a Name for a Memory Location (cont’d.) 10
  • 11. An Introduction to Programming with C++, Eight Edition A C++ Keywords 11
  • 12. An Introduction to Programming with C++, Eight Edition A C++ Keywords 12
  • 13. An Introduction to Programming with C++, Eight Edition Selecting a Name for a Memory Location (cont’d.) 13
  • 14. An Introduction to Programming with C++, Eight Edition Revisiting the Addison O’Reilly Problem 14 Figure 3-3 Problem specification, IPO chart, and desk-check table from Chapter 2
  • 15. An Introduction to Programming with C++, Eight Edition • IPO chart contains four input, processing, and output items • Four memory locations are needed to store the values of the items • Memory locations will be variables since their values will change during runtime Revisiting the Addison O’Reilly Problem (cont’d.) 15
  • 16. An Introduction to Programming with C++, Eight Edition Revisiting the Addison O’Reilly Problem (cont’d.) 16
  • 17. An Introduction to Programming with C++, Eight Edition The End ♥ ♥ ♥ 17