TU
C++ Programming: From Problem Analysis
VI
to Program Design
D.S. Malik
A2
──────────────────────────────────────────────────
8th Edition
6_
AP
PR
OV
ED
??
,ST
TABLE OF CONTENTS
UV
Solutions Manual: C++ Programming: From Problem Analysis to Program Design, 8th
Edition
By D. S. Malik
IA
Chapter 1 An Overview of Computers and Programming Languages
Chapter 2 Basic Elements of C++
26
Chapter 3 Input/Output
Chapter 4 Control Structures I (Selection)
Chapter 5 Control Structures II (Repetition)
_A
Chapter 6 User-Defined Functions
Chapter 7 User-Defined Simple Data Types, Namespaces, and the string Type
PP
Chapter 8 Arrays and Strings
Chapter 9 Records (structs)
Chapter 10 Classes and Data Abstraction
RO
Chapter 11 Inheritance and Composition
Chapter 12 Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 13 Overloading and Templates
VE
Chapter 14 Exception Handling
Chapter 15 Recursion
D?
Chapter 16 Searching, Sorting, and the vector Type
Chapter 17 Linked Lists
Chapter 18 Stacks and Queues
?
1
,ST
Chapter 1
1. a. true; b. false; c. false; d. true; e. false; f. true; g. true; h. true; i. false; j. false; k. true; l. true; m. true;
n. true; o. true; p. false; q. true; r. true; s. true
UV
2. CPU.
3. Base 2 or binary.
4. The equivalent machine language program of a high-level language program.
5. In linking, an object program is combined with other programs in the library, used in the program, to
IA
create the executable code.
6. Loader
7. #
26
8. Preprocessor
9. Programming is a process of problem solving.
10. A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time.
_A
11. (1) Analyze and outline the problem and its solution requirements, and design an algorithm to solve the
problem. (2) Implement the algorithm in a programming language, such as C++, and verify that the
algorithm works. (3) Maintain the program by using and modifying it if the problem domain changes.
12. (1) Thoroughly understand the problem. (2) Understand the problem requirements. (3) If the problem is
complex, divide the problem into subproblems and repeat Steps 1 and 2.
PP
13. To find the weighted average of the four test scores, first you need to know each test score and its
weight. Next, you multiply each test score with its weight, and then add these numbers to get the
average. Therefore,
1. Get testScore1, weightTestScore1
RO
2. Get testScore2, weightTestScore2
3. Get testScore3, weightTestScore3
4. Get testScore4, weightTestScore4
5. weightedAverage = testScore1 * weightTestScore1 +
VE
testScore2 * weightTestScore2 +
testScore3 * weightTestScore3 +
testScore4 * weightTestScore4;
D?
14. a. Get quarters
b. Get dimes
c. Get nickels
d. Get pennies
?
e. changeInPennies = quarters * 25 + dimes * 10 + nickels * 5
+ pennies
15. To find the price per square inch, first we need to find the area of the pizza. Then we divide the price of
the pizza by the area of the pizza. Let radius denote the radius and area denote the area of the
circle, and price denote the price of pizza. Also, let pricePerSquareInch denote the price per
square inch.
,ST
a. Get radius
UV
b. area = π * radius * radius
c. Get price
d. pricePerSquareInch = price / area
IA
16. To determine the least selling price of a car, we need to know the listing price of the car. The algorithm
is as follows:
26
a. Get listingPrice
b. Calculate the least selling price leastSellingPrice using the formula:
leastSellingPrice = listingPrice × 0.85) + 500
_A
17. Suppose that radius denotes radius of the sphere, volume denotes volume of the sphere, and
surfaceArea denotes the surface area of the sphere. The following algorithm computes the volume
and surface area of the sphere.
PP
Algorithm C++ Instruction (Code)
1 1. Get the radius. cin >> radius;
2 2. Calculate the volume. volume = (4..0) * 3.1416 * radius * radius * radius;
3 3. Calculate the surface surfaceArea = 4.0 * 3.1416 * radius * radius;
RO
area.
18. Suppose that billingAmount denotes the total billing amount, movingCost denotes moving cost,
area denotes the area of the yard that needs to be moved, numOfAppl denotes the number of
VE
fertilizing applications, and numOfTrees denotes the number of trees to be planted. The following
algorithm computes and outputs the billing amount.
a. Enter the area of the yard.
D?
b. Get area
c. Enter the number of fertilizing applications.
d. Get numOfAppl
?
e. Enter the number of trees to be planted.
f. Get numOfTrees
g. Calculate the billingAmount using the formula:
billingAmount = (area / 5000) * 35.00 + numOfAppl * 30.00
+ numOfTrees * 50.00