COSC-1337 Chapter 2

Ace your homework & exams now with Quizwiz!

2R - 6 - 72, 'A',and "Hello World" are all examples of _____ .

72, 'A',and "Hello World" are all examples of constants or literals.

2R - 7 - 978 .65 x 10^12 would be written in E notation as ______ .

978 .65 x 10^12 would be written in E notation as 9.7865E14

2.7 - C2.13 Which integer data types can only hold non-negative values?

unsigned short, unsigned int, and unsigned long can only hold non-negative values

2.2 - What is the alarm escape sequence, and what does it do?

The alarm escape sequence is written as \a and it causes the computer to beep

2.2 - What is the backslash escape sequence, and what does it do?

The backslash escape sequence is written as \\ and it causes a backslash to be printed

2.2 - What is the backspace escape sequence, and what does it do?

The backspace escape sequence is written as \b and it causes the cursor to back up (i.e., move left) one position

2R - 8 - The character literal 'A' requires _____ byte(s) of memory, whereas the string literal "A" requires _____ byte(s).

The character literal 'A' requires one byte of memory, whereas the string literal "A" requires 2 bytes.

2.2 - What is the double quote escape sequence, and what does it do?

The double quote escape sequence is written as \" and it causes a double quotation mark to be printed.

2.1 - How is the double slash (//) used?

The double slash marks the beginning of a comment

2.8 - What is a double?

A double is a double precision floating-point data type that has: -8 bytes -a range between ±1.7E-308 and ±1.7E308 -16 significant digits

2.8 - What is a float?

A float is a single precision floating-point data type that has: -4 bytes -a range between ±3.4E-38 and ±3.4E38 -7 significant digits -To store a float literal you may have to append the f suffix

2R - 5 - A group of statements, such as the body of a function, must be enclosed in ______ .

A group of statements, such as the body of a function, must be enclosed in braces {}.

2.5 - What is a literal?

A literal is a piece of data written directly into a program's code. One of the most common uses of literals is to assign a value to a variable. Another common use of literals is to display something on the screen. Literals can be characters, strings, or numeric values.

2.8 - What is a long double?

A long double is a double precision floating-point data type that has: -8 bytes -a range between ±1.7E-308 and ±1.7E308 -16 significant digits -To force a value to be stored as a long double append an L to it Some compilers use more than 8 bytes for a long double. This allows a greater range.

2.7 - What is a long int?

A long int is an integer data type that is typically 4 bytes from -2,147,483,648 to +2,147,483,647

2.7 - What is a long long int?

A long long int is an integer data type that is typically 8 bytes from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807

2.16 - What is a multi-line comment?

A multi-line comment starts with a forward slash and an asterisk (/*) and ends with an asterisk and a forward slash (*/). The compiler ignores everything between those markers.

2.7 - What is a short int?

A short int is an integer data type that is typically 2 bytes from -32,768 to +32,767

2.16 - What is a single line comment?

A single line comment starts with two forward slashes (//) and the compiler ignores everything from that point to the end of the line.

2.9 - What is a string?

A string is a character data type. It can hold a whole series of characters. To compensate for the variable length C++ appends an extra byte to the end called a null terminator to mark the end. A string is enclosed in double quotation marks.

2.7 - What is an int?

An int is an integer data type that is typically 4 bytes from -2,147,483,648 to +2,147,483,647

2.7 - What is an unsigned int?

An unsigned int is an integer data type that is typically 4 bytes from 0 to +4,294,967,295

2.7 - What is an unsigned long int?

An unsigned long int is an integer data type that is typically 4 bytes from 0 to +4,294,967,295

2.7 - What is an unsigned long long int?

An unsigned long long int is and integer data type that is typically 8 bytes from 0 to +8,446,744,073,709,551,615

2.7 - What is an unsigned short int?

An unsigned short int is an integer data type that is typically 2 bytes from 0 to +65,535

2R - 14 - Assume double variables x = 2.5, y = 7.0, and z = 3. What value will be stored in integer variable result by each of the following statements? A) result = x + y; B) result = y * 2; C) result = y / z;

Assume double variables x = 2.5, y = 7.0, and z = 3. What value will be stored in integer variable result by each of the following statements? A) result = x + y; 9 B) result = y * 2;14 C) result = y / z; 2

2R - 13 - Assume integers x = 4, y = 7, and z = 2. What value will be stored in integer variable result by each of the following statements? A) result = x + y; B) result = y * 2; C) result = y / z;

Assume integers x = 4, y = 7, and z = 2. What value will be stored in integer variable result by each of the following statements? A) result = x + y; 13 B) result = y * 2; 14 C) result = y / z; 3

2.11 - What is a bool?

Bool is the Boolean expression that allows you to create variables that hold true or false values. Although it appears to store the words true or false, it is actually storing 1 or 0 (T or F). As variables, they do not need quotation marks.

2.1 - What is a namespace?

C++ uses namespaces to organize the names of program entities. The statement using namespace std; declares that the program will be accessing entities whose names are part of the namespace called std. Programs usually contain various types of items with unique names. Variables, functions, and objects are examples of program entities that must have names .

2.9 - What is a char?

Char is a character data type. It is the simplest character data type. A variable of this type can hold only a single character and, on most systems, uses just one byte of memory. A value being assigned to a char variable is enclosed in single quotes.

2.2 - What is an escape sequence?

Escape sequences are written as a backslash character (\) followed by a control character and are used to control the way output is displayed. An escape sequence must start with a backslash, be placed inside quotation marks, and have no spaces between the backslash and the control character.

2R - 3 - Every C++ program must have a function named ________ .

Every C++ program must have a function named main.

2R - 1 - Every complete statement ends with a _______ .

Every complete statement ends with a semicolon.

2.15 - What are the three types of arithmetic operators?

Generally, there are three types of operators: unary, binary, and ternary. Unary operators only require a single operand (-5 with its negation operator), binary work with two operands (most common type), and ternary which requires three operands and will be discussed in CH4.

2R - 10 - If the variable letter and w have been defined as character variables, indicate if each of the following assignment statements is valid or invalid. A) letter = w; B) letter = 'w'; C) letter = "w";

If the variable letter and w have been defined as character variables, indicate if each of the following assignment statements is valid or invalid. A) letter = w; Invalid B) letter = 'w'; Valid C) letter = "w"; Invalid

2R - 9 - Indicate if each of the following assignment statements is valid or invalid. A) total = 9; B) 72 = amount; C) yourAge = myAge;

Indicate if each of the following assignment statements is valid or invalid. A) total = 9; Valid B) 72 = amount; Invalid C) yourAge = myAge; Valid

2R - 12 - Indicate if each of the following cout statements is valid or invalid. A) cout << "Hello world"; B) cout << Hello world; C) cout<< "Hello" << " world";

Indicate if each of the following cout statements is valid or invalid. A) cout << "Hello world"; Valid B) cout << Hello world; Invalid C) cout<< "Hello" << " world"; Valid

2R - 11 - Indicate if each of the following cout statements is valid or invalid. A) cout << "Hello" << endl; B) cout << "Hello" << \n; C) cout << Hello;

Indicate if each of the following cout statements is valid or invalid. A) cout << "Hello" << endl; Valid B) cout << "Hello" << \n; Invalid C) cout << Hello; Valid, but prints the contents of variable Hello

2.7 - C2.11 Is the variable name Sales the same as sales? Why or why not?

No, variable names are case sensitive

2.1 - How are opening and closing quotation marks ("") used?

Opening and closing quotation marks enclose a string of characters, such as a message that is to be printed on the screen.

2R - 4 - Preprocessor directives begin with a ________ .

Preprocessor directives begin with a #.

2.17 - What is programming style?

Programming style refers to the way source code is visually arranged. Ideally, it is a consistent method of putting spaces and indentions in a program so visual cues are created to aid the human reader.

2.2 - What is the horizontal tab escape sequence, and what does it do?

The horizontal tab escape sequence is written as \t and it causes the cursor to skip over to the next tab stop

2.15 - What is the modulus operator?

The modulus operator is the percent symbol (%) and it computes the remainder of doing an integer divide.

2.2 - What is the newline escape sequence, and what does it do?

The newline escape sequence is written as \n and it causes the cursor to go to the next line for subsequent printing.

2.1 - How are the opening and closing brackets (<>) used?

The opening and closing brackets enclose a filename when used with the #include directive

2.1 - How are the opening and closing parentheses (()) used?

The opening and closing parentheses are used in naming a function, as in "int main()>"

2.1 - How is the pound sign (#) used?

The pound sign marks the beginning of a preprocessor directive.

2.2 - What is the return escape sequence, and what does it do?

The return escape sequence is written as \r and it causes the cursor to go to the beginning of the current line, not the next line.

2.14 - What is a variable's scope?

The scope of a variable is the part of the program where it may be used. -A variable cannot be used before it is defined.

2.1 - How is the semicolon (;) used?

The semicolon marks the end of a complete programming statement

2.2 - What is the single quote escape sequence, and what does it do?

The single quote escape sequence is written as \' and it causes a single quotation mark to be printed.

2.12 - What is sizeof?

The sizeof operator may be used to determine the size of a data type on any system. It will report the number of bytes of memory used by any data type or variable.

2.7 - How do you abbreviate integer data types?

To abbreviate integer data types omit the word int

2R - 2 - To use cout statements you must include the ___________ file in your program

To use cout statements you must include the iostream file in your program

2.13 - What is the auto keyword?

Using auto instead of a data type with an initialization value will tell the compiler to determine the variable's data type from the initialization value.

2.1 - What is a preprocessor directive?

When a line begins with a # it indicates it is a preprocessor directive. The preprocessor reads your program before it is compiled and only executes those lines beginning with a # symbol. Think of the preprocessor as a program that "sets up" your source code for the compiler. The #include directive causes the preprocessor to include the contents of another file in the program . The word inside the brackets, iostream, is the name of the file that is to be included . The iostream file contains code that allows a C++ program to display output on the screen and read input from the keyboard.

2R - 17 - Write assignment statements that perform the following operations with int variable i, double variables d1 and d2, and char variable c. A) Add 2 to d1 and store the result in d2. B) Multiply d2 time 4 and store the result in d1. C) Store the character 'K' in c. D) Store the ASCII code for the character 'K' in i. E) Subtract 1 from i and store the result back in i.

Write assignment statements that perform the following operations with int variable i, double variables d1 and d2, and char variable c. A) Add 2 to d1 and store the result in d2. -- d2 = d1 + 2; B) Multiply d2 time 4 and store the result in d1. -- d1 = d2 * 4; C) Store the character 'K' in c. -- c = 'K'; D) Store the ASCII code for the character 'K' in i. -- i = 'K'; E) Subtract 1 from i and store the result back in i. -- i = i - 1;

2R - 18 - Write assignment statements that perform the following operations with int variable i, double variables d1 and d2, and char variable c. A) Subtract 8.5 from d2 and store the result in d1. B) Divide d1 by 3.14 and store the result in d2. C) Store the ASCII code for the character 'F' in c. D) Add 1 to i and store the new value back in i. E) Add d1 to the current value of d2 and store the result back in d2 as its new value.

Write assignment statements that perform the following operations with int variable i, double variables d1 and d2, and char variable c. A) Subtract 8.5 from d2 and store the result in d1. -- d1 = d2 - 8.5; B) Divide d1 by 3.14 and store the result in d2. -- d2 = d1 / 3.14; C) Store the ASCII code for the character 'F' in c. -- c = 'F'; D) Add 1 to i and store the new value back in i. -- i = i + 1; E) Add d1 to the current value of d2 and store the result back in d2 as its new value. -- d2 = d2 + d1;

2.10 - How do you use a string?

You have to use the string class. First you have to include the preprocessor directive in the header: #include <string> Then you define a string object which is done like defining a primitive variable or literal.

2.1 - How are opening and closing braces ({}) used?

opening and closing braces enclose a group of statements, such as the contents of a function.

2R - 15 - Write a C++ statement that defines the double variables temp, weight, and height all in the same statement.

double temp, weight, height;

2R - 16 - Write a C++ statement that defines the int variables months, days, and years all in the same statement, with months initialized to 2 and years initialized to 3.

int months = 2, days, years = 3;


Related study sets

Chapter 3. Cell Structure and Function

View Set

accounting 202 chapter 3 learnsmart

View Set

International Marketing CH. 1,2,3,4,5,6,7

View Set

Chapter 8: Corporate Strategy - Vertical Integration and Diversification

View Set

Ch 19 - Accounting for income taxes

View Set

Anatomy Chapter 5 The Skeletal System

View Set

Chapter 12: Communication, Conflict, and Negotiation

View Set

SCIENCE - Quiz 1.3 L'élaboration de la théorie atomique

View Set