• Home
  • Textbooks
  • C# Programming: From Problem Analysis to Program Design
  • Data Types and Expressions

C# Programming: From Problem Analysis to Program Design

Barbara Doyle

Chapter 2

Data Types and Expressions - all with Video Answers

Educators


Chapter Questions

02:06

Problem 1

Which of the following is a valid identifier?
a. namespace
b. variable 1
c. exampleOfAValue
d. 3value
e. value#1

Ernest Castorena
Ernest Castorena
Numerade Educator
00:41

Problem 2

The number 768 is an example of a __________ type.
a. bool
b. integral
c. floating-point
d. struct
e. decimal

Ernest Castorena
Ernest Castorena
Numerade Educator
01:26

Problem 3

Which of the following is a reference type?
a. int
b. bool
c. string
d. decimal
e. integral

Ernest Castorena
Ernest Castorena
Numerade Educator
00:53

Problem 4

The character that cannot be used with an identifier is:
a. –
b. $
c. *
d. #
e. all of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:05

Problem 5

Which of the following is a reserved keyword?
a. Console
b. data
c. int
d. System
e. all of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:13

Problem 6

One of primary differences between float, double, and decimal is:
a. float is used to represent more significant digits.
b. double is normally used with large monetary values.
c. decimal is not used to display negative values.
d. double does not require suffixing a numeric literal with a value such as m or f.
e. decimal is primarily used to represent small monetary values that require a $ for formatting.

Ernest Castorena
Ernest Castorena
Numerade Educator
01:16

Problem 7

Which of the following is a valid declaration for a variable to store the name of this textbook?
a. string name of book;
b. char nameOfBook;
c. boolean nameOfBook;
d. string bookName;
e. char book Name;

Ernest Castorena
Ernest Castorena
Numerade Educator
00:50

Problem 8

Types are implemented in C# using:
a. classes
b. types
c. objects
d. namespaces
e. programs

Ernest Castorena
Ernest Castorena
Numerade Educator
00:29

Problem 9

An object of the int class is:
a. 47.98
b. 47
c. int class
d. type object
e. type integral

Ernest Castorena
Ernest Castorena
Numerade Educator
00:50

Problem 10

What would be an appropriate declaration for a memory location to be used as a flag
to indicate whether a value has reached its upper limit?
a. int upperLimit;
b. upperLimit reached;
c. bool upperLimit;
d. Boolean upperLimit;
e. string upperLimit;

Ernest Castorena
Ernest Castorena
Numerade Educator
00:58

Problem 11

Adding the keyword const to a declaration:
a. places a value in memory that cannot be changed
b. declares variables of the constant type
c. must be done by placing it after the identifier in the declaration
d. can only be done with the integral types
e. is prohibited in C#

Ernest Castorena
Ernest Castorena
Numerade Educator
00:38

Problem 12

Which statement increases the result by 15?
a. 15 += result;
b. 15 =+ result;
c. result =+ 15;
d. result += 15;
e. result = 15 +;

Ernest Castorena
Ernest Castorena
Numerade Educator
00:56

Problem 13

What is stored in ans as a result of the arithmetic expression, given the following
declarations?
int ans = 0, v1 = 10, v2 = 19;
ans = --v2 % v1++;
a. 1.8
b. 9
c. 8
d. 2
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
01:36

Problem 14

What is stored in ans as a result of the arithmetic expression, given the following declarations?
int ans = 10, v1 = 5, v2 = 7, v3 = 18;
ans += v1 + 10 * (v2-- / 5) + v3 / v2;
a. 18
b. 32
c. 28
d. 30
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
00:59

Problem 15

Which of the following formats 86 to display with two digits to the right of the
decimal?
a. {0:C}
b. {0:c}
c. {0:f 2}
d. all of the above
e. none of the above

Ernest Castorena
Ernest Castorena
Numerade Educator
03:31

Problem 16

Indicate the order of operations for the following assignment statements by placing a
number under the assignment operator, as illustrated in Figure 2-13.
a. ans = value1 + value2 * value3 – (value4 + 20 / 5 % 2) * 7;
b. ans += value1-- * 10;
c. ans = (((value1 + 7) – 6 * value2) / 2);
d. ans = value1 + value2 / value3 * value4--;

Ernest Castorena
Ernest Castorena
Numerade Educator
02:04

Problem 17

Which of the following are valid identifiers? If they are invalid, indicate why.
a. intValue
b. value#1
c. the first value
d. _value1
e. AVALUE

Ernest Castorena
Ernest Castorena
Numerade Educator
01:32

Problem 18

For each of the following, declare a variable using the best choice for data type.
a. a counter for the number of correct responses
b. the amount of money you owe on a credit card
c. the name of your hometown
d. the grade you hope to obtain on the next exam
e. the grade you hope is recorded at the end of the term for this course

Ernest Castorena
Ernest Castorena
Numerade Educator
02:06

Problem 19

For each of the following declarations, write an appropriate compile-time initialization.
a. counter for the number of correct responses begins with zero
b. amount of money you owe on a credit card is zero
c. name of the hometown or the city where your school is located
d. grade on the next exam is 100
e. grade to be recorded at the end of the term for this course is an A

Ernest Castorena
Ernest Castorena
Numerade Educator
04:36

Problem 20

20. Suppose x, y, and z are int variables and x = 2, y = 6, and z = 10.What will be in the memory locations of each of the variables after each of the following statements is executed? (For each exercise, use the original declaration.)
a. z += ++y % 2;
b. x = y + 14 – z / 7;
c. x = y * z / 2 – x * z;
d. x %= --z – y * 2;
e. y = (z – y) * 2 + --y;

Ernest Castorena
Ernest Castorena
Numerade Educator
03:26

Problem 21

Suppose x, y, and z are double variables and x = 2.5, y = 6.9, and z = 10.0.What will be in the memory locations of each of the variables after each of the following statements is executed? (For each exercise, use the original declaration.)
a. z *= y++ % 7;
b. x = (int) y + (14 – z / 7);
c. x = z / 3 * --y;
d. z /= (int) y / x;
e. z = x + y / 4;

Ernest Castorena
Ernest Castorena
Numerade Educator
02:59

Problem 22

What will be the output from each of the following statements?
a. Console. Write("Result is $\{0: c\} ", 67)$
b. Console. Write("Number $\{0: f 0\} \text { is }\{1: c\} ", 1,3)$
c. Console.Write $\left(^{* 4}\{0: \mathrm{f} 0\}-\{1: \mathrm{c}\} ", 1,3^{*} 2\right)$
d. Console. Write $\left(^{* 4}\{0: f 0\} \text { result } "+" x y z\{1: f 2\} ", 1,25\right)$
e. Console. Write("This is the $\{0: f 0\} \text { st example: }\{1: f 2\} ", 1,3)$

Ernest Castorena
Ernest Castorena
Numerade Educator
00:39

Problem 23

Explain how a variable differs from a constant.

Ernest Castorena
Ernest Castorena
Numerade Educator
01:19

Problem 24

24. Explain how type, class, and object are related to a string.

Ernest Castorena
Ernest Castorena
Numerade Educator
02:59

Problem 25

The following program has several syntax errors as well as style inconsistencies. Correct the syntax errors and identify the style violations.
namespace Chapter2
\{
class converter
\{
static void main
\[
\{
\]
CONST int inches $=12$
\[
\begin{array}{l}
\text { int } x=100 ; y=10 ; \\
\text { float } z=22.45
\end{array}
\]
double ans; ans=inches $+z^{*} \times$ \& $y$ System.write("The result is $\{f 2: 0\}$ " $+$ "ans")
\[
\begin{array}{l}
3 \\
3
\end{array}
\]

Ernest Castorena
Ernest Castorena
Numerade Educator