Problem Solving Using C++

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/28

flashcard set

Earn XP

Description and Tags

Flashcards covering fundamental concepts from Chapter 2 including program structure, identifiers, built-in data types, arithmetic operations, operator precedence, memory allocation, and problem-solving steps.

29 Terms

1
New cards

What is a modular program in C++?

A program consisting of interrelated segments (or modules) arranged in a logical and understandable form, which can be implemented as classes or functions.

2
New cards

How does a function process input in C++?

A function accepts an input, processes the input, and produces an output, with its processing encapsulated and hidden inside the function.

3
New cards

What rules govern the naming of identifiers in C++?

The first character must be a letter or underscore; subsequent characters may only be letters, digits, or underscores; keywords cannot be used; and the maximum length is 10241024 characters.

4
New cards

What is the function of main() in a C++ program?

The main() function serves as the driver function, directing the overall program execution and calling all other functions.

5
New cards

What three elements are contained in a C++ function header line?

The type of data returned by the function (if any), the name of the function, and the type of data passed into the function (argument list) when invoked.

6
New cards

What is the role of the return 0 statement in the main() function?

It returns a value of 0 from the function and causes the main program execution to end.

7
New cards

What is the cout object in C++?

It is an output object that sends data to a standard output display device.

8
New cards

What is a C++ preprocessor command and how is it formatted?

It is an instruction starting with a # symbol (such as #include ) that triggers an action before the source code is compiled into machine code.

9
New cards

What is a string delimiter in C++?

A symbol, such as double quotes, that marks the beginning and end of a string literal without being part of the string itself.

10
New cards

How do single-line comments differ from block comments in C++?

Line comments begin with // and continue to the end of the line, whereas block comments begin with /* and end with */, spanning across multiple lines.

11
New cards

What are the two fundamental groupings of C++ data types?

Class data types (created by the programmer) and built-in data types (primitive types inherent to the compiler).

12
New cards

What are the nine built-in integer data types in C++?

bool, char, short int, int, long int, unsigned char, unsigned short int, unsigned int, and unsigned long int.

13
New cards

What ASCII code and storage size represent the letter 'A' in memory?

The ASCII code is 01000001, which takes 1 byte1\,\text{byte} of memory storage.

14
New cards

What information does the sizeof() operator return in C++?

It provides the number of bytes used by the compiler to store values of a specified data type or variable.

15
New cards

What is the difference between signed and unsigned integer data types?

Signed types permit negative, positive, and zero values. Unsigned types permit only positive and zero values, providing essentially double the positive range of their signed counterparts.

16
New cards

What are the storage sizes and value ranges for short int and unsigned short int?

short int uses 2 bytes2\,\text{bytes} with a range of −32,768-32,768 to +32,767+32,767. unsigned short int uses 2 bytes2\,\text{bytes} with a range of 00 to 65,53565,535.

17
New cards

What are the storage sizes and value ranges for 4-byte int and unsigned int?

int uses 4 bytes4\,\text{bytes} with a range of −2,147,483,648-2,147,483,648 to +2,147,483,647+2,147,483,647. unsigned int uses 4 bytes4\,\text{bytes} with a range of 00 to 4,294,967,2954,294,967,295.

18
New cards

What are the storage sizes and precision levels for C++ floating-point data types?

float uses 4 bytes4\,\text{bytes} (single precision), while double and long double use 8 bytes8\,\text{bytes} (double precision).

19
New cards

How do floating-point literals differ for float and long double types in code?

Floating-point literals are double by default. Appending an f or F creates a float literal (e.g., 9.234F), and appending an l or L creates a long double literal (e.g., 9.234L).

20
New cards

How does integer division differ from modulus division in C++?

Integer division (/) drops or truncates any fractional remainder (e.g., 15/2=715 / 2 = 7), whereas modulus division (%) yields only the integer remainder (e.g., 9%4=19 \mathbin{\%} 4 = 1).

21
New cards

What is a mixed-mode expression in C++ and what type of value does it return?

An expression containing both integer and floating-point operands, which yields a double-precision floating-point value.

22
New cards

What is operator associativity in C++?

The order in which operators of the same precedence level are evaluated in an expression (such as left-to-right or right-to-left).

23
New cards

What distinction exists between a variable declaration statement and a definition statement?

A declaration statement specifies the data type and identifier of a variable, while a definition statement causes the computer to allocate memory storage for it.

24
New cards

What is the purpose of the C++ address operator (&)?

It provides the memory address assigned to a specific variable.

25
New cards

What are the four steps in the problem-solving procedure for software development?

Step 1: Analyze the Problem; Step 2: Develop a Solution; Step 3: Code the Solution; Step 4: Test and Correct the Program.

26
New cards
<p>According to the structure diagram of the main() function, what are the key labeled components?</p>

According to the structure diagram of the main() function, what are the key labeled components?

The type of returned value (int), the function name (main), an empty argument list (), and the function body inside braces containing statements and return 0;.

27
New cards
<p>Which integer data types are categorized in C++ as shown in Figure 2.6?</p>

Which integer data types are categorized in C++ as shown in Figure 2.6?

bool, char, short int, int, long int, unsigned char, unsigned short int, unsigned int, and unsigned long int.

28
New cards
<p>How is the word 'BARTER' stored in memory as illustrated in Figure 2.7?</p>

How is the word 'BARTER' stored in memory as illustrated in Figure 2.7?

It uses 6 bytes6\,\text{bytes} of storage, with each character stored in ASCII binary: B (01000010), A (01000001), R (01010010), T (01010100), E (01000101), and R (01010010).

29
New cards
<p>What precedence levels and associativity are assigned to C++ arithmetic operators in Table 2.8?</p>

What precedence levels and associativity are assigned to C++ arithmetic operators in Table 2.8?

Unary negation (-) has Right to left associativity; multiplication (*), division (/), and modulus (%) have Left to right associativity; addition (+) and subtraction (-) have Left to right associativity.