• Home
  • Textbooks
  • Starting out with C++: From Control Structures through Objects
  • Introduction to C++

Starting out with C++: From Control Structures through Objects

Tony Gaddis

Chapter 2

Introduction to C++ - all with Video Answers

Educators


Chapter Questions

Problem 1

How many operands does each of the following types of operators require?
_______ Unary
_______ Binary
_______ Ternary

Check back soon!
01:26

Problem 2

How may the double variables temp, weight, and age be defined in one statement?

Willis James
Willis James
Numerade Educator
01:26

Problem 3

How may the int variables months, days, and years be defined in one statement, with months initialized to 2 and years initialized to 3?

Willis James
Willis James
Numerade Educator

Problem 4

Write assignment statements that perform the following operations with the variables a, b, and c:
A) Adds 2 to a and stores the result in b.
B) Multiplies b by 4 and stores the result in a.
C) Divides a by 3.14 and stores the result in b.
D) Subtracts 8 from b and stores the result in a.
E) Stores the value 27 in a.
F) Stores the character ‘K’ in c.
G) Stores the ASCII code for ‘B’ in c.

Check back soon!

Problem 5

Is the following comment written using single-line or multi-line comment symbols?
/* This program was written by M. A. Codewriter*/

Check back soon!

Problem 6

Is the following comment written using single-line or multi-line comment symbols?
// This program was written by M. A. Codewriter

Check back soon!

Problem 7

Modify the following program so it prints two blank lines between each line of text.
#include <iostream>
using namespace std;
int main()
{
cout << "Two mandolins like creatures in the";
cout << "dark";
cout << "Creating the agony of ecstasy.";
cout << " - George Barker";
return 0;
}

Check back soon!

Problem 8

What will the following programs print on the screen?
A) #include <iostream>
using namespace std;
int main()
{
int freeze = 32, boil = 212;
freeze = 0;
boil = 100;
cout << freeze << endl << boil << endl;
return 0;
}
B) #include <iostream>
using namespace std;
int main()
{
int x = 0, y = 2;
x = y * 4;
cout << x << endl << y << endl;
return 0;
}
C) #include <iostream>
using namespace std;
int main()
{
cout << "I am the incredible";
cout << "computing\nmachine";
cout << "\nand I will\namaze\n";
cout << "you.";
return 0;
}
D) #include <iostream>
using namespace std;
int main()
{
cout << "Be careful\n";
cout << "This might/n be a trick ";
cout << "question\n";
return 0;
}
E) #include <iostream>
using namespace std;
int main()
{
int a, x = 23;
a = x % 2;
cout << x << endl << a << endl;
return 0;
}

Check back soon!
00:25

Problem 9

Every complete statement ends with a(n) _________.
A) period
B) # symbol
C) semicolon
D) ending brace

Ernest Castorena
Ernest Castorena
Numerade Educator

Problem 10

Which of the following statements is correct?
A) #include (iostream)
B) #include {iostream}
C) #include <iostream>
D) #include [iostream]
E) All of the above

Check back soon!

Problem 11

Every C++ program must have a _________.
A) cout statement
B) function main
C) #include statement
D) All of the above

Check back soon!
00:25

Problem 12

Preprocessor directives begin with _________.
A) #
B) !
C) <
D) *
E) None of the above

Ernest Castorena
Ernest Castorena
Numerade Educator

Problem 13

The following data
72
'A'
"Hello World"
2.8712
are all examples of _________.
A) variables
B) literals or constants
C) strings
D) none of the above

Check back soon!
01:26

Problem 14

A group of statements, such as the contents of a function, is enclosed in _________.
A) braces {}
B) parentheses ()
C) brackets <>
D) all of the above will do

Prashant Bana
Prashant Bana
Numerade Educator

Problem 15

Which of the following are not valid assignment statements? (Select all that apply.)
A) total = 9;
B) 72 = amount;
C) profit = 129
D) letter = 'W';

Check back soon!

Problem 16

Which of the following are not valid cout statements? (Select all that apply.)
A) cout << "Hello World";
B) cout << "Have a nice day"\n;
C) cout < value;
D) cout << Programming is great fun;

Check back soon!

Problem 17

Assume $w=5, x=4, y=8$, and $z=2$. What value will be stored in result in each of the following statements?
A) result $=x+y$;
B) result $=z^* 2$;
C) result $=$ y $/ x$
D) result $=\mathrm{y}-\mathrm{z}$;
E) result = w \% 2;

Check back soon!
02:04

Problem 18

How would each of the following numbers be represented in E notation?
A) $3.287 \times 10^6$
B) $-978.65 \times 10^{12}$
C) $7.65491 \times 10^{-3}$
D) $-58710.23 \times 10^{-4}$

Susan Hallstrom
Susan Hallstrom
Numerade Educator

Problem 19

The negation operator is _________.
A) unary
B) binary
C) ternary
D) none of the above

Check back soon!

Problem 20

A(n) ___________ is like a variable, but its value is read-only and cannot be changed during the program’s execution.
A) secure variable
B) uninitialized variable
C) named constant
D) locked variable

Check back soon!

Problem 21

When do preprocessor directives execute?
A) Before the compiler compiles your program
B) After the compiler compiles your program
C) At the same time as the compiler compiles your program
D) None of the above

Check back soon!

Problem 22

True or False
T F A variable must be defined before it can be used.

Check back soon!

Problem 23

True or False
T F Variable names may begin with a number.

Check back soon!

Problem 24

True or False
T F Variable names may be up to 31 characters long.

Check back soon!

Problem 25

True or False
T F A left brace in a C++ program should always be followed by a right brace later in the program.

Check back soon!

Problem 26

True or False
T F You cannot initialize a named constant that is declared with the const modifier.

Check back soon!

Problem 27

Convert the following pseudocode to C++ code. Be sure to define the appropriate variables.
Store 20 in the speed variable.
Store 10 in the time variable.
Multiply speed by time and store the result in the distance variable.
Display the contents of the distance variable.

Check back soon!

Problem 28

Convert the following pseudocode to C++ code. Be sure to define the appropriate variables.
Store 172.5 in the force variable.
Store 27.5 in the area variable.
Divide area by force and store the result in the pressure variable.
Display the contents of the pressure variable.

Check back soon!

Problem 29

There are a number of syntax errors in the following program. Locate as many as you
can.
*/ What's wrong with this program? /*
#include iostream
using namespace std;
int main();
}
int a, b, c \\ Three integers
a = 3
b = 4
c = a + b
Cout < "The value of c is %d" < C;
return 0;
{

Check back soon!