• Home
  • Textbooks
  • Starting Out with C++ Brief. From Control Structures through Objects
  • Introduction to C++

Starting Out with C++ Brief. From Control Structures through Objects

Tony Gaddis

Chapter 2

Introduction to C++ - all with Video Answers

Educators


Chapter Questions

01:57

Problem 1

How many operands does each of the following types of operators require?
___________Unary
__________Binary
___________Ternary

Aaron Goree
Aaron Goree
Numerade Educator
01:26

Problem 2

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

Willis James
Willis James
Numerade Educator
01:51

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 ?

Morgan Cheatham
Morgan Cheatham
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 times 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 ' $\mathrm{K}$ ' in c.
G) Stores the ASCII code for 'B' in c.

Check back soon!
01:38

Problem 5

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

Adam Conner
Adam Conner
Numerade Educator
01:38

Problem 6

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

Adam Conner
Adam Conner
Numerade Educator

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 $<$ "
return $0 ;$
int main()
\{
cout $\ll$ "Two mandolins like creatures in the";
cout $<$ "dark";
cout $\ll$ "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 $\ll$ freeze $\ll$ endl $\ll$ boil endl;
return $0 ;$
\}
\#include <iostream>
using namespace std;
int main()
\{
int freeze $=32$, boil $=212$;
freeze $=0$;
boil $=100$;
cout $\ll$ freeze $\ll$ endl $\ll$ boil $\ll$ endl;
return 0 ;
\}
B)
\#include <iostream>
using namespace std;
int main()
\{
int $\mathrm{x}=0, \mathrm{y}=2$;
$\mathrm{x}=\mathrm{y} \star 4$;
cout $\ll x \ll$ end $x \ll y \ll$ endl
return 0 ;
\}
C) \#include <iostream>
using namespace std;
int main()
\{
cout $\ll$ "I am the incredible";
cout $\ll$ "computing $\backslash$ nmachine";
cout $\ll$ "\nand I will \namaze $\backslash n "$;
cout $\ll$ "you. ";
return 0 ;
?
D) \#include <iostream>
using namespace std;
int main()
?
cout $\ll$ "Be careful $\backslash \mathrm{n}$ ";
cout $\ll$ "This might/n be a trick ";
cout $\ll$ "question $\backslash$ n" ;
return 0 ;
\}E) \#include <iostream>
using namespace std;
int main( )
$\{$ int $a, x=23 ;$
a $=x$ o $2 ;$
cout $\ll x \ll$ end $l \ll a \ll$ end 1 ;
return $0 ;$
\} i
E) \#include <iostream>
using namespace std;
int main()
\{
int $a, x=23$;
$\mathrm{a}=\mathrm{x}$ \& 2 ;
cout $\ll \mathrm{x} \ll$ endl $\ll \mathrm{a} \ll$ end ;
return 0 ;
\}

Check back soon!
00:49

Problem 9

Every complete statement ends with a
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 12

Every $\mathrm{C}_{++}$program must have a
A) cout statement.
B) function main.
C) \#include statement.
D) All of the above

Check back soon!

Problem 12

Preprocessor directives begin with a
A) \#
B) !
C) $<$
D) *
E) None of the above

Check back soon!
01:15

Problem 13

The following data
72
'A'
"Hello World"
2.8712
72
' $\mathrm{A}$ '
"Hello World"
2. 8712are all examples of
A) Variables
B) Literals or constants
C) Strings
D) None of the above

Zack Spears
Zack Spears
Numerade Educator
00:49

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

Ernest Castorena
Ernest Castorena
Numerade Educator
01:23

Problem 15

Which of the following are not valid assignment statements? (Circle all that apply.)
A) $\operatorname{total}=9$;
B) 72 = amount;
C) profit $=129$
D) letter $=$ ' $\mathrm{W}$ ';

Kerry Thornton-Genova
Kerry Thornton-Genova
Numerade Educator

Problem 16

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

Check back soon!
02:39

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 $=y-z$;
E) result $=w$ o 2 ;

Kayleah Tsai
Kayleah Tsai
Numerade Educator
01:50

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}$

Abdel Osman
Abdel Osman
Numerade Educator
01:01

Problem 19

The negation operator is
A) Unary
B) Binary
C) Ternary
D) None of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
05:10

Problem 20

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

Samuel Goyette
Samuel Goyette
Numerade Educator
00:48

Problem 21

True or False
$\mathrm{T} \mathrm{F}$ A variable must be defined before it can be used.

Alexandra Ali
Alexandra Ali
Numerade Educator
02:28

Problem 23

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

Caleb Wood
Caleb Wood
Numerade Educator
01:03

Problem 23

True or False
$\mathrm{T} \mathrm{F}$ Variable names may be up to 31 characters long.

Vishal Sharma
Vishal Sharma
Numerade Educator
00:32

Problem 24

True or False
T F A left brace in a $\mathrm{C}_{++}$program should always be followed by a right brace later in the program.

Bahar Tehranipoor
Bahar Tehranipoor
Numerade Educator
02:26

Problem 25

Convert the following pseudocode to $\mathrm{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.

Willis James
Willis James
Numerade Educator
02:26

Problem 26

Convert the following pseudocode to $\mathrm{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.

Willis James
Willis James
Numerade Educator

Problem 27

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 \backslash \backslash$ Three integers
$a=3$
$b=4$
$c=a+b$
Cout $<$ "The value of $\mathrm{c}$ is $8 \mathrm{~d} "<\mathrm{c}$;
return 0 ;
$$
\{
$$

Check back soon!