SlideShare a Scribd company logo
1 of 24
Download to read offline
Introduction to Programming in C++
Eight Edition
Lesson 4.1:
Completing the Problem-Solving
Process
An Introduction to Programming with C++, Eight Edition
• Get numeric and character data from the keyboard
• Display information on the computer screen
• Write arithmetic expressions
• Type cast a value
• Write an assignment statement
• Code the algorithm into a program
• Desk-check a program
• Evaluate and modify a program
Objectives
2
An Introduction to Programming with C++, Eight Edition
• The fourth step in the problem-solving process is to
code algorithm into a program
• Begin by declaring a memory location for each input,
processing, and output value in IPO chart
• Optionally initialize each value (highly preferred)
• Next, you code the instructions for the algorithm
Finishing Step 4 in the Problem-
Solving Process
3
An Introduction to Programming with C++, Eight Edition
Getting Data from the Keyboard
4
• C++ uses stream objects to perform input/output
operations
• A stream is a sequence of characters
• The cin object is used to obtain information from the
keyboard (program pauses while user enters data)
• The extraction operator (>>) takes information out of
cin object and stores it in internal memory
– Syntax: cin >> variableName;
An Introduction to Programming with C++, Eight Edition
Getting Data from the Keyboard
(cont’d.)
5
An Introduction to Programming with C++, Eight Edition
Getting Data from the Keyboard
(cont’d.)
6
An Introduction to Programming with C++, Eight Edition
Displaying Messages on the Computer
Screen
7
• You use a prompt (message) to let the user know what
data is to be entered
• The cout object is used with the insertion operator (<<)
To display information on the screen.
• Information can be any combination of literal constants,
named constants , and variables.
• Multiple items can be printed in the same statement
- Systax : cout << item1 [<<item2 << itemN];
- Part in brackets is optional
An Introduction to Programming with C++, Eight Edition
• A stream manipulator is used to manipulate (manage)
the characters in an input or output string
• endl is a stream manipulator that advances the cursor to
the next line on the screen
– Equivalent to pressing the Enter key (carriage return
and line feed)
Displaying Messages on the Computer
Screen (cont’d.)
8
An Introduction to Programming with C++, Eight Edition
Displaying Messages on the Computer
Screen (cont’d.)
9
An Introduction to Programming with C++, Eight Edition
• You can evaluate arithmetic expressions in C++ using
arithmetic operators
• Operators are negation (-), addition (+), subtraction (-),
multiplication (*), division (/), and modulus (%)
• Negation and subtraction use the same symbol, but
negation is a unary operator (one operand) and
subtraction is a binary operator (two operands)
• Modulus gives remainder when dividing two integers
Arithmetic Operators in C++
10
An Introduction to Programming with C++, Eight Edition
• Each operator has a precedence: determines in which
order operators in an expression are evaluated
• Operators with lower-precedence numbers are
evaluated before higher ones
• Parentheses have lowest-precedence number, so they
can be used to override precedence order
• Operators with the same precedence number are
evaluated from left to right
Arithmetic Operators in C++ (cont’d.)
11
An Introduction to Programming with C++, Eight Edition
Arithmetic Operators in C++ (cont’d.)
12
Figure 4-7 Standard arithmetic operators and their order of
precedence
An Introduction to Programming with C++, Eight Edition
Arithmetic Operators in C++ (cont’d.)
13
An Introduction to Programming with C++, Eight Edition
• Recall that the compiler will implicitly promote or
demote data types to match when possible
• Sometimes it is necessary to explicitly cast from one
data type into another
– Example: dividing two integers gives the result of
integer division (no remainder), but you would really like a
double result
– If one or both of the integers is a literal, you can
cast it to a double by adding .0 to the end of it
– If both are variables, you must use the static_cast
operator
Type Conversions in Arithmetic
Expressions
14
An Introduction to Programming with C++, Eight Edition
Type Conversions in Arithmetic
Expressions (cont’d.)
15
An Introduction to Programming with C++, Eight Edition
• Used to explicitly convert data from one data type to
another
• Called an explicit type conversion or type cast
• Syntax: static_cast(data)
– data can be a literal constant, named constant, or
variable
– dataType is the data type to which you want the
data converted
The static_cast Operator
16
An Introduction to Programming with C++, Eight Edition
The static_cast Operator (cont’d.)
17
An Introduction to Programming with C++, Eight Edition
The static_cast Operator (cont’d.)
18
An Introduction to Programming with C++, Eight Edition
• You use an assignment statement to assign a value to a
variable while a program is running
• Syntax: variableName = expression
– The = symbol is the assignment operator
• Tells computer to evaluate expression on right side of
assignment operator and store result in variable on left
side of the operator
– expression can include one or more literal
constants, named constants, variables, or arithmetic
operators
Assignment Statements
19
An Introduction to Programming with C++, Eight Edition
• Data type of expression in an assignment statement
must match data type of the variable
• If they don’t match, compiler will use implicit type
casting to get them to match
– Doesn’t always produce correct result
– Better to explicitly cast to correct data type
yourself
• Remember:
– Declaration statement creates a new variable
– Assignment statement assigns a new value to an
existing variable
Assignment Statements (cont’d.)
20
An Introduction to Programming with C++, Eight Edition
Assignment Statements (cont’d.)
21
An Introduction to Programming with C++, Eight Edition
• Allow you to abbreviate assignment statements that
contain an arithmetic operator
• Statement must be of the form
variableName = variableName arithmeticOperator value
• Abbreviated as variableName arithmeticOperator =
value
– Example: price = price*1.05; can be abbreviated
as price *= 1.05;
• Most common operators are += , -= , *= , /= , and %=
Arithmetic Assignment Operators
22
An Introduction to Programming with C++, Eight Edition
Arithmetic Assignment Operators
(cont’d)
23
An Introduction to Programming with C++, Eight Edition
The End ♥ ♥ ♥
24

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
 
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
 
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
 
Chapter 02 - Problem Solving
Chapter 02 - Problem SolvingChapter 02 - Problem Solving
Chapter 02 - Problem SolvingLuis Daniel Serrano
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c languagekamalbeydoun
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4Dr.YNM
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
Verilog operators
Verilog operatorsVerilog operators
Verilog operatorsDr.YNM
 
A quick introduction to c programming
A quick introduction to c programmingA quick introduction to c programming
A quick introduction to c programmingMohit Patodia
 
Fda unit 1 lec 1
Fda unit 1 lec  1Fda unit 1 lec  1
Fda unit 1 lec 1Eugin Britto
 

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)
 
Lesson 10
Lesson 10Lesson 10
Lesson 10
 
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
 
test(3)arithmetic in c
test(3)arithmetic in ctest(3)arithmetic in c
test(3)arithmetic in c
 
Lesson 9.2 guessing the game program
Lesson 9.2 guessing the game programLesson 9.2 guessing the game program
Lesson 9.2 guessing the game program
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Chapter 02 - Problem Solving
Chapter 02 - Problem SolvingChapter 02 - Problem Solving
Chapter 02 - Problem Solving
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
Ppl
PplPpl
Ppl
 
Lesson 9.1 value returning
Lesson 9.1 value returningLesson 9.1 value returning
Lesson 9.1 value returning
 
Compiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent OptimizationsCompiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent Optimizations
 
Data flow model -Lecture-4
Data flow model -Lecture-4Data flow model -Lecture-4
Data flow model -Lecture-4
 
Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Lesson 7.2 using counters and accumulators
Lesson 7.2 using counters and accumulatorsLesson 7.2 using counters and accumulators
Lesson 7.2 using counters and accumulators
 
Verilog operators
Verilog operatorsVerilog operators
Verilog operators
 
A quick introduction to c programming
A quick introduction to c programmingA quick introduction to c programming
A quick introduction to c programming
 
Functions
FunctionsFunctions
Functions
 
Fda unit 1 lec 1
Fda unit 1 lec  1Fda unit 1 lec  1
Fda unit 1 lec 1
 

Similar to Lesson 4.1 completing the problem solving process

Chapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving ProcessChapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving Processmshellman
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variablesTony Apreku
 
Chapter2
Chapter2Chapter2
Chapter2Anees999
 
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Blue Elephant Consulting
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Blue Elephant Consulting
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12Terry Yoast
 
Review chapter 1 2-3
Review chapter 1 2-3Review chapter 1 2-3
Review chapter 1 2-3ahmed22dg
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02Terry Yoast
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfmadihamaqbool6
 
intro to c
intro to cintro to c
intro to cteach4uin
 
C++.ppt
C++.pptC++.ppt
C++.pptshweta210
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
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 exampleVaibhav Khanna
 
Computer Programming
Computer ProgrammingComputer Programming
Computer ProgrammingBurhan Fakhar
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2Don Dooley
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Mohamed El Desouki
 
Lecture#2 Computer languages computer system and Programming EC-105
Lecture#2 Computer languages computer system and Programming EC-105Lecture#2 Computer languages computer system and Programming EC-105
Lecture#2 Computer languages computer system and Programming EC-105NUST Stuff
 
C program
C programC program
C programAJAL A J
 
C++ Overview
C++ OverviewC++ Overview
C++ Overviewkelleyc3
 

Similar to Lesson 4.1 completing the problem solving process (20)

Chapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving ProcessChapter 4 - Completing the Problem-Solving Process
Chapter 4 - Completing the Problem-Solving Process
 
C++ ch2
C++ ch2C++ ch2
C++ ch2
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
 
Chapter2
Chapter2Chapter2
Chapter2
 
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
Intro To C++ - Cass 11 - Converting between types, formatting floating point,...
 
Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...Intro To C++ - Class 11 - Converting between types, formatting floating point...
Intro To C++ - Class 11 - Converting between types, formatting floating point...
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
 
Review chapter 1 2-3
Review chapter 1 2-3Review chapter 1 2-3
Review chapter 1 2-3
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
 
intro to c
intro to cintro to c
intro to c
 
C++.ppt
C++.pptC++.ppt
C++.ppt
 
C programming language
C programming languageC programming language
C programming language
 
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
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
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#2 Computer languages computer system and Programming EC-105
Lecture#2 Computer languages computer system and Programming EC-105Lecture#2 Computer languages computer system and Programming EC-105
Lecture#2 Computer languages computer system and Programming EC-105
 
C program
C programC program
C program
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 

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

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
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
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
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
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
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
 

Recently uploaded (20)

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🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
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
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
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🔝
 
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
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
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
 

Lesson 4.1 completing the problem solving process

  • 1. Introduction to Programming in C++ Eight Edition Lesson 4.1: Completing the Problem-Solving Process
  • 2. An Introduction to Programming with C++, Eight Edition • Get numeric and character data from the keyboard • Display information on the computer screen • Write arithmetic expressions • Type cast a value • Write an assignment statement • Code the algorithm into a program • Desk-check a program • Evaluate and modify a program Objectives 2
  • 3. An Introduction to Programming with C++, Eight Edition • The fourth step in the problem-solving process is to code algorithm into a program • Begin by declaring a memory location for each input, processing, and output value in IPO chart • Optionally initialize each value (highly preferred) • Next, you code the instructions for the algorithm Finishing Step 4 in the Problem- Solving Process 3
  • 4. An Introduction to Programming with C++, Eight Edition Getting Data from the Keyboard 4 • C++ uses stream objects to perform input/output operations • A stream is a sequence of characters • The cin object is used to obtain information from the keyboard (program pauses while user enters data) • The extraction operator (>>) takes information out of cin object and stores it in internal memory – Syntax: cin >> variableName;
  • 5. An Introduction to Programming with C++, Eight Edition Getting Data from the Keyboard (cont’d.) 5
  • 6. An Introduction to Programming with C++, Eight Edition Getting Data from the Keyboard (cont’d.) 6
  • 7. An Introduction to Programming with C++, Eight Edition Displaying Messages on the Computer Screen 7 • You use a prompt (message) to let the user know what data is to be entered • The cout object is used with the insertion operator (<<) To display information on the screen. • Information can be any combination of literal constants, named constants , and variables. • Multiple items can be printed in the same statement - Systax : cout << item1 [<<item2 << itemN]; - Part in brackets is optional
  • 8. An Introduction to Programming with C++, Eight Edition • A stream manipulator is used to manipulate (manage) the characters in an input or output string • endl is a stream manipulator that advances the cursor to the next line on the screen – Equivalent to pressing the Enter key (carriage return and line feed) Displaying Messages on the Computer Screen (cont’d.) 8
  • 9. An Introduction to Programming with C++, Eight Edition Displaying Messages on the Computer Screen (cont’d.) 9
  • 10. An Introduction to Programming with C++, Eight Edition • You can evaluate arithmetic expressions in C++ using arithmetic operators • Operators are negation (-), addition (+), subtraction (-), multiplication (*), division (/), and modulus (%) • Negation and subtraction use the same symbol, but negation is a unary operator (one operand) and subtraction is a binary operator (two operands) • Modulus gives remainder when dividing two integers Arithmetic Operators in C++ 10
  • 11. An Introduction to Programming with C++, Eight Edition • Each operator has a precedence: determines in which order operators in an expression are evaluated • Operators with lower-precedence numbers are evaluated before higher ones • Parentheses have lowest-precedence number, so they can be used to override precedence order • Operators with the same precedence number are evaluated from left to right Arithmetic Operators in C++ (cont’d.) 11
  • 12. An Introduction to Programming with C++, Eight Edition Arithmetic Operators in C++ (cont’d.) 12 Figure 4-7 Standard arithmetic operators and their order of precedence
  • 13. An Introduction to Programming with C++, Eight Edition Arithmetic Operators in C++ (cont’d.) 13
  • 14. An Introduction to Programming with C++, Eight Edition • Recall that the compiler will implicitly promote or demote data types to match when possible • Sometimes it is necessary to explicitly cast from one data type into another – Example: dividing two integers gives the result of integer division (no remainder), but you would really like a double result – If one or both of the integers is a literal, you can cast it to a double by adding .0 to the end of it – If both are variables, you must use the static_cast operator Type Conversions in Arithmetic Expressions 14
  • 15. An Introduction to Programming with C++, Eight Edition Type Conversions in Arithmetic Expressions (cont’d.) 15
  • 16. An Introduction to Programming with C++, Eight Edition • Used to explicitly convert data from one data type to another • Called an explicit type conversion or type cast • Syntax: static_cast(data) – data can be a literal constant, named constant, or variable – dataType is the data type to which you want the data converted The static_cast Operator 16
  • 17. An Introduction to Programming with C++, Eight Edition The static_cast Operator (cont’d.) 17
  • 18. An Introduction to Programming with C++, Eight Edition The static_cast Operator (cont’d.) 18
  • 19. An Introduction to Programming with C++, Eight Edition • You use an assignment statement to assign a value to a variable while a program is running • Syntax: variableName = expression – The = symbol is the assignment operator • Tells computer to evaluate expression on right side of assignment operator and store result in variable on left side of the operator – expression can include one or more literal constants, named constants, variables, or arithmetic operators Assignment Statements 19
  • 20. An Introduction to Programming with C++, Eight Edition • Data type of expression in an assignment statement must match data type of the variable • If they don’t match, compiler will use implicit type casting to get them to match – Doesn’t always produce correct result – Better to explicitly cast to correct data type yourself • Remember: – Declaration statement creates a new variable – Assignment statement assigns a new value to an existing variable Assignment Statements (cont’d.) 20
  • 21. An Introduction to Programming with C++, Eight Edition Assignment Statements (cont’d.) 21
  • 22. An Introduction to Programming with C++, Eight Edition • Allow you to abbreviate assignment statements that contain an arithmetic operator • Statement must be of the form variableName = variableName arithmeticOperator value • Abbreviated as variableName arithmeticOperator = value – Example: price = price*1.05; can be abbreviated as price *= 1.05; • Most common operators are += , -= , *= , /= , and %= Arithmetic Assignment Operators 22
  • 23. An Introduction to Programming with C++, Eight Edition Arithmetic Assignment Operators (cont’d) 23
  • 24. An Introduction to Programming with C++, Eight Edition The End ♥ ♥ ♥ 24