expand icon
book C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith cover

C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith

Edition 8ISBN: 978-1285867410
Chapter 8: Advanced Modularization Techniques
arrow icon
Chapter 9: Object Oriented C++
arrow icon
book C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith cover

C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith

Edition 8ISBN: 978-1285867410
Exercise 7
Swapping Values
In this exercise, you use what you have learned about swapping values to answer the following question.
Suppose you have declared and initialized two string variables, product1 and product2, in a C++ program. Now, you want to swap the values stored in product1 and product2 but only if the value of product1 is greater than the value of product2. Write the C++ code that accomplishes this task. The declarations are as follows:
string product1 = "hammer";string product2 = "wrench";
Explanation
Verified
like image
like image

Program plan:
• Define a main function ...

close menu
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
Chapter 1: An Introduction to C and the C++ Programming Environment
Free
arrow img
Chapter 2: Variables, Constants, Operators, and Writing Programs Using Sequential Statements
arrow img
Chapter 3: Writing Programs That Make Decisions
arrow img
Chapter 4: Writing Programs Using Loops
arrow img
Chapter 5: Using Arrays in C++ Programs
arrow img
Chapter 6: File Handling and Applications
arrow img
Chapter 7: Advanced Array Techniques
arrow img
Chapter 8: Advanced Modularization Techniques
arrow img
Chapter 9: Object Oriented C++
arrow img
cross icon