Engineering Problem Solving with C++, 3/E solutions manual and test bank by Ingber & Etter
Downloadable Instructor Resources
Help downloading instructor resources
Exam Practice!
1.
T
2.
F
3.
T
4.
T
5.
F
6.
Not Correct.
int i, j, k;
7.
Correct.
8.
Incorrect. double D1, D2, D3;
9.
Correct.
10.
Correct.
11.
(d)
12.
(b)
13.
(a)
14.
(c)
15.
(e)
Memory Snapshots
16.
x1=>2, z=>2, x=>2
17.
x=>2, y=>1, a=>3.8, n=>2
Output
18.
value_1 = 5.78263
19.
Missing ; (value_4 = 6.645832e+01)
20.
value_5 = 7750
Programming Exercises
/*--------------------------------------------------------------------*/
/* Problem chapter2_21
*/
/*
*/
/* This program converts miles to
kilometers. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double miles, kilometers;
/*
Enter number of miles from the keyboard.
*/
cout << "Enter the number of
miles: \n";
cin >> miles;
/*
Compute the number of kilometers equal to the specified miles. */
kilometers = 1.6093440*miles;
/*
Print the number of kilometers.
*/
cout << miles << " miles =
" << kilometers << " kilometers \n";
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_22 */
/*
*/
/* This program converts meters to miles. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double miles, meters;
/*
Enter number of meters from the keyboard. */
cout << "Enter the number of meters:
\n";
cin >> meters;
/*
Compute the number of miles equal to the specified meters. */
miles = meters/1609.3440;
/*
Print the number of miles. */
cout
<< meters << " meters = "<< miles <<
" miles \n";
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_23
*/
/*
*/
/* This program converts pounds to
kilograms. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double pounds, kilograms;
/*
Enter number of pounds from the keyboard. */
cout << "Enter the number of
pounds: ";
cin >> pounds;
/*
Compute number of kilograms equal to the specified pounds. */
kilograms = pounds/2.205;
/*
Print the number of kilograms. */
cout << pounds << " pounds
= " << kilograms << " kilograms \n";
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_24
*/
/*
*/
/* This program converts newtons to pounds. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double pounds, newtons;
/*
Enter number of newtons from the keyboard. */
cout << "Enter the number of
newtons: ";
cin >> newtons;
/*
Compute number of pounds equal to the specified newtons. */
pounds = newtons/4.448;
/*
Print the number of pounds. */
cout << newtons << "
newtons = " << pounds << " pounds \n";
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_25
*/
/* */
/* This program converts degrees Fahrenheit to
degrees Rankin. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double degrees_F, degrees_R;
/*
Enter temperture in degrees Fahrenheit from the keyboard. */
cout << "Enter the temperature in
degrees Fahrenheit: ";
cin >> degrees_F;
/*
Compute the equivalent temperature in degrees Rankin */
/*
from the given temperature. */
degrees_R = degrees_F + 459.67;
/*
Print the temperatures. */
cout << degrees_F << "
degrees Fahrenheit = " << degrees_R << " degrees Rankin
\n";
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_26
*/
/*
*/
/* This program converts degrees Celsius to
degrees Rankin. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double degrees_C, degrees_F, degrees_R;
/*
Enter temperture in degrees Celsius from the keyboard. */
cout << "Enter the temperature in
degrees Celsius: \n";
cin >> degrees_C;
/*
Compute the equivalent temperature in degrees Rankin */
/*
from the given temperature. */
degrees_F = (9.0/5.0)*degrees_C + 32;
degrees_R = degrees_F + 459.67;
/*
Print the temperatures. */
cout << degrees_C << "
degrees Celsius = " << degrees_R << " degrees Rankin
\n";
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_27
*/
/*
*/
/* This program converts degrees Kelvin to
degrees Fahrenheit. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double degrees_R, degrees_K, degrees_F;
/*
Enter temperture in degrees Kelvin from the keyboard. */
cout << "Enter the temperature in
degrees Kelvin: \n";
cin >> degrees_K;
/*
Compute the equivalent temperature in degrees Fahrenheit */
/*
from the given temperature. */
degrees_R = (9.0/5.0)*degrees_K;
degrees_F = degrees_R - 459.67;
/*
Print the temperatures. */
cout << degrees_K << "
degrees Kelvin = " << degrees_F << " degrees Fahrenheit
\n";
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_28
*/
/*
*/
/* This program finds the area of a
rectangle. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double a, b, area;
/*
Enter the lengths of sides of the rectangle. */
cout << "Enter the lengths of the
sides of the rectangle: ";
cin
>> a >> b;
/*
Compute the area of the rectangle.
*/
area = a*b;
/*
Print the value of the area. */
cout << "The area of a rectangle
with sides " << a << " and " << b
<< " is " << area
<< endl;
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_29
*/
/* */
/* This program finds the area of a
triangle. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double h, b, area;
/*
Enter the base and the height of the triangle. */
cout << "Enter the base and the
height of the triangle: ";
cin >> b >> h;
/*
Compute the area of the triangle.
*/
area = 0.5*b*h;
/*
Print the value of the area. */
cout << "The area of a triangle
with base " << b << " and height " << h
<< "is " << area
<< endl;
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_30
*/
/*
*/
/* This program finds the area of a circle. */
#include
<iostream>
using
namespace std;
const
double PI = 3.141593;
int
main()
{
/*
Declare variables. */
double r, area;
/*
Enter the radius. */
cout << "Enter the radius of the
circle: ";
cin >> r;
/*
Compute the area of the circle.
*/
area = PI*r*r;
/*
Print the value of the area. */
cout << "The area of a circle
with radius " << r << " is "
<< area << endl;
/*
Exit program. */
return 0;
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Problem chapter2_31
*/
/*
*/
/* This program computes the area of a sector of
a circle when */
/* theta (u) is the angle in radians between the
radii. */
#include
<iostream>
using
namespace std;
int
main()
{
/*
Declare variables. */
double u, r, area;
/*
Enter the lengths of the radii and */
/*
the angle between them.
*/
cout << "Enter the length of the
radii and the angle "
<< "(in radians) between
them: ";
cin >> r >> u;
/*
Compute the area of the sector.
*/
area = (r*r*u)/2.0;
/*
Print the value of the area. */
cout << "The area of sector is
" << area << endl;
1.
Match each of the following
data types with literal constants of that data type. A data type can be used
more than once.
A.
integer
B.
double
C.
character
D.
string
E.
boolean
F.
none of the above.
________ 1.427E3
________ "Oct"
________ -63.29
________ Zipcode
________ '+'
________ -85
________ true
________ '\''
2.
For each of the following
determine if it is a valid identifier, and if it is not state why.
A.
House#
B.
2nd
C.
WHILE
D.
num4
E.
double
F.
last_name
3.
Evaluate the following
functions
A.
(4 - 7) * 3
B.
14 % 4
C.
24 / 9
D.
6.72 / 4.2
E.
2 + 8 * 3 + 7
4.
What is the output of the
following program.
#include
<iostream>
#include
<iomanip>
using namespace
std;
int main ()
{ int hr, min;
hr = 1;
min = 50;
cout << "The exam is over at
" << hr
<< “:” << min << endl;
cout << "One down\n "
<< “two to go!” ;
return 0;
}
5.
What is the output of the
following program
#include
<iostream>
#include
<iomanip>
using namespace
std;
int main()
{ int
WholeNumber;
double Real1, Real2;
WholeNumber = 76;
Real1 = 3.167;
Real2 = -24.103;
cout << setw(6) << WholeNumber << endl;
cout << setiosflags(ios::fixed);
cout << setprecision(2) <<
Real1 << ", " << Real2 << endl;
cout <<
setiosflags(ios::showpoint) <<
Real2 << 8.376 << endl;
return 0;
}
6. Which of the following are valid on the left side of an assignment
operator?
A.
A numeric constant
B.
An expression such as 8*6
C.
A declared constant
D.
A variable
E.
All of the above are valid on
the left side of an assignment operator.
7. Which of the following is valid on the right side of an assignment
operator?
A.
A numeric constant
B.
An expression such as 8*6
C.
A declared constant
D.
A variable
E.
All of the above are valid on
the right side of an assignment operator.
8. The operator >> is used to
A.
Take a value from the input
stream an store it into a variable
B.
Take a value from a variable
and place it into the output stream
C.
Perform integer division and
produce the remainder of the division
D.
Specify that the left hand
operand is much larger than the right hand operand.
9.
The file which must appear in a
#include preprocessor statement if you are using the fabs function is …
A. iostream
B. iomanip
C. cmath
D. string
10. Which of the following is not a data type used to represent a
floating point value
A. float
B. double
C. long double
D. short
11. Which of the following is not a syntactically correct declaration?
A. int number(12);
B. double value1(4.5); value2(3.7);
C. double tax_percent =0.06;
D.
int x,y,z;
12. Which of the following operators is the increment operator
A. +=
B. +
C. %
D. ++
13. Which output flag is set to guarantee that a decimal point will be
printed when printing a floating point value?
A. fixed
B. showpoint
C. precision
D. setw
14. Function arguments are …
A. the term used for the name of the function
B. the term that refers to the value returned by a function
C. the term that refers to the values passed to the function when the
function is invoked.
D. the term that refers to a function invocation.
15. Which of the following function invocations is an approximation of
PI
A. atan(-1);
B. acos(-1);
C. sin(-1);
D. cos(-1);
16. Line comments begin with // and run for the rest of the line
A.
true
B.
false
1.
Match each of the following
data types with literal constants of that data type. A data type can be used
more than once.
A.
integer
B.
double
C.
character
D.
string
E.
boolean
F.
none of the above.
____B___ 1.427E3
____D___ "Oct"
____B___ -63.29
____F___ Zipcode
____C___ '+'
____A___ -85
____E___ true
____C___ '\''
2.
For each of the following
determine if it is a valid identifier, and if it is not state why.
A.
House# not valid, # is not allowed in
identifier
B.
2nd not valid, identifiers
must start with letter or underscore not a number
C.
WHILE valid
D.
num4 valid
E.
double not valid, double is a reserved
keyword
F.
last_name valid
3.
Evaluate the following
functions
A.
(4 - 7) * 3 -9
B.
14 % 4 2
C.
24 / 9 2
D.
6.72 / 4.2 1.6
E.
2 + 8 * 3 + 7 33
4.
What is the output of the
following program.
#include
<iostream>
#include
<iomanip>
using namespace
std;
int main ()
{ int hr, min;
hr = 1;
min = 50;
cout << "The exam is over at
" << hr
<< “:” << min << endl;
cout << "One down\n "
<< “two to go!” ;
return 0;
}
The
exam is over at 1:50
One
down
two
to go!
5.
What is the output of the
following program
#include
<iostream>
#include
<iomanip>
using namespace
std;
int main()
{ int
WholeNumber;
double Real1, Real2;
WholeNumber = 76;
Real1 = 3.167;
Real2 = -24.103;
cout << setw(6) << WholeNumber << endl;
cout << setiosflags(ios::fixed);
cout << setprecision(2) <<
Real1 << ", " << Real2 << endl;
cout <<
setiosflags(ios::showpoint) <<
Real2 << 8.376 << endl;
return 0;
}
76
3.17, -24.10
-24.108.38
6. Which of the following are valid on the left side of an assignment
operator?
A.
A numeric constant
B.
An expression such as 8*6
C.
A declared constant
D.
A variable
E.
All of the above are valid on
the left side of an assignment operator.
7. Which of the following are valid on the right side of an assignment
operator?
A.
A numeric constant
B.
An expression such as 8*6
C.
A declared constant
D.
A variable
E.
All of the above are valid on
the right side of an assignment operator.
8. The operator >> is used to
A.
Take a value
from the input stream an store it into a variable
B.
Take a value from a variable
and place it into the output stream
C.
Perform integer division and
produce the remainder of the division
D.
Specify that the left hand
operand is much larger than the right hand operand.
9.
The file which must appear in a
#include preprocessor statement if you are using the fabs function is …
A. iostream
B. iomanip
C. cmath
D. string
10. Which of the following is not a data type used to represent a
floating point value
A. float
B. double
C. long double
D. short
11. Which of the following is not a syntactically correct declaration?
A. int number(12);
B. double value1(4.5); value2(3.7);
C. double tax_percent =0.06;
D.
int x,y,z;
12. Which of the following operators is the increment operator
A. +=
B. +
C. %
D. ++
13. Which output flag is set to guarantee that a decimal point will be
printed when printing a floating point value?
A. fixed
B. showpoint
C. precision
D. setw
14. Function arguments are …
A. the term used for the name of the function
B. the term that refers to the value returned by a function
C. the term that
refers to the values passed to the function when the function is invoked.
D. the term that refers to a function invocation.
15. Which of the following function invocations is an approximation of
PI
A. atan(-1);
B. acos(-1);
C. sin(-1);
D. cos(-1);
16. Line comments begin
with // and run for the rest of the line
A.
true
B.
false
17. The purpose of a comment is to help the compiler understand your
program and create efficient object code.
A.
true
B.
false
18. The math function sin will compute sine when given the angle in
degrees
A.
true
B.
false
19.
The setw manipulator is used to
set the field width for all values that are printed until another setw
manipulator is encountered.
A.
true
B.
false
20. The preprocessor
directive #include <iostream> copies the file iostream into the program before
compilation, so that the program can use input and output objects and
operators.
A.
true
B.
false
21. The operand of the increment operator may be either a declared
constant or a variable.
A. true
B. false
22.
The math function tan will
compute tangent when the angle is given in radians.
A. true
B. false
23. In a case sensitive
language, such as C++, the variables apples
and APPLES refer to different
storage locations.
A. true
B. false
24. An expression involving operators can appear
after the output operator << in a cout statement.
A. true
B. false
25.
The precision of a
floating point number is determined by the number of bits used to represent the
exponent.
A.
true
B.
false
26.
Identifiers should be carefully
chosen to reflect the contents of the object; this helps the compiler
understand your program.
A.
True
B.
False
27.
C++ is a strongly
typed programming language.
A.
True
B.
False
28.
Symbolic constants in C++ are
declared with the modifier const; attempting to change the value of a symbolic
constant will be flagged as a syntax error by the compiler.
A.
True
B.
False
29.
Class declarations
specify a programmer-defined type/object.
A.
True
B.
False
30.
Class members may
include data (attributes) and methods (functions).
A.
True
B.
False
31.
Which of the following
visibilities by be used to control access to class members:
A.
public
B.
protected
C.
private
D.
All of these are visibilities
used to control access to class members.
32.
Class attributes define the
operations that may be performed on class objects.
A.
True
B.
False
33.
Constructors are
special methods of a class that are executed when objects of the class type are
created.
A.
True
B.
False
34.
Constructors must have the same
name as the class; therefore there may be only one constructor in any class.
A.
True
B.
False
35.
Once a class is
defined, you may use the class as a type specifier.
A.
True
B.
False
No comments:
Post a Comment