Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views9 pages

Program. Qs & Ans

The document is a compilation of fill-in-the-blank and multiple-choice questions covering fundamental concepts of computers and programming, specifically focusing on C++ programming techniques. It includes topics such as the role of the CPU, types of software, programming languages, expressions, decision-making, loops, functions, and arrays. Additionally, it references the textbook by Tony Gaddis for further reading and context.

Uploaded by

padostypadmole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Program. Qs & Ans

The document is a compilation of fill-in-the-blank and multiple-choice questions covering fundamental concepts of computers and programming, specifically focusing on C++ programming techniques. It includes topics such as the role of the CPU, types of software, programming languages, expressions, decision-making, loops, functions, and arrays. Additionally, it references the textbook by Tony Gaddis for further reading and context.

Uploaded by

padostypadmole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

COMPILED BY :

PROF. MANUEL
( BSC. COMPUTER SCIENCE )

PROGRAMMING TECHNIQUES ( C-TONY GADDIS )

CHAPTER 1 – Introduction to Computers and Programming

Fill-in-the-Blank

1. Computers can do many different jobs because they can be programmed.


2. The job of the CPU is to fetch instructions, carry out the operations commanded by the
instructions, and produce some outcome or resultant information.
3. Internally, the CPU consists of the control unit and the arithmetic and logic unit
(ALU).

4. A(n) disk drive is an example of a secondary storage device.


5. The two general categories of software are system software and application software.
6. A program is a set of instructions.
7. Since computers can’t be programmed in natural human language, algorithms must be
written in a(n) programming language.

8. Machine language is the only language computers really process.

9. High-level languages are close to the level of humans in terms of readability.

10. Low-level languages are close to the level of the computer.

11. A program’s ability to run on several different types of computer systems is called
portability.

12. Words that have special meaning in a programming language are called keywords.

13. Words or names defined by the programmer are called identifiers.


14. Operators are characters or symbols that perform operations on one or more operands.

15. Punctuation characters or symbols mark the beginning or ending of programming


statements, or separate items in a list.
16. The rules that must be followed when constructing a program are called syntax.

17. A(n) variable is a named storage location.

18. A variable must be declared before it can be used in a program.

19. The three primary activities of a program are input, processing, and output.

20. Input is information a program gathers from the outside world.

21. Output is information a program sends to the outside world.

22. A(n) flowchart is a diagram that graphically illustrates the structure of a program.

CHAPTER 2 – Introduction to C++

Multiple Choice

1. Every complete statement ends with a


C) semicolon

2. Which of the following statements is correct?


C) #include <iostream>

3. Every C++ program must have a


B) function main
4. Preprocessor directives begin with a
A) #

5. The following data: 72, 'A', "Hello World", 2.8712 are all examples of
B) Literals or constants

6. A group of statements, such as the contents of a function, is enclosed in


A) Braces {}

7. Which of the following are not valid assignment statements? (Circle all that apply.)
B) 72 = amount;
C) profit = 129
8. Which of the following are not valid cout statements? (Circle all that apply.)
B) cout << "Have a nice day"\n;
C) cout < value;
D) cout << Programming is great fun;

9. Assume w = 5, x = 4, y = 8, and z = 2. What value will be stored in result?


A) result = x + y; → 12
B) result = z * 2; → 4
C) result = y / x; → 2
D) result = y − z; → 6
E) result = w % 2; → 1

10. How would each of the following numbers be represented in E notation?


A) 3.287 × 10⁶ → 3.287e6
B) −978.65 × 10¹² → -9.7865e14
C) 7.65491 × 10⁻³ → 7.65491e-3
D) −58710.23 × 10⁻⁴ → -5.871023
11. The negation operator is
A) Unary
12. A(n) __________ is like a variable, but its value is read-only and cannot be changed
during the program’s execution.
C) named constant

13. When do preprocessor directives execute?


A) Before the compiler compiles your program
CHAPTER 3 – Expressions and Interactivity

1. The cos library function returns the cosine of an angle.

2. The sin library function returns the sine of an angle.

3. The tan library function returns the tangent of an angle.


4. The exp library function returns the exponential function of a number.

5. The fmod library function returns the remainder of a floating point division.

6. The log library function returns the natural logarithm of a number.

7. The log10 library function returns the base-10 logarithm of a number.

8. The pow library function returns the value of a number raised to a power.

9. The sqrt library function returns the square root of a number.

10. The <cmath> file must be included in a program that uses the mathematical functions.

CHAPTER 4 – Making Decisions

1. An expression using the greater-than, less-than, greater-than-or-equal to, less-than-or-


equal to, equal, or not-equal to operator is called a(n) relational expression.

2. A relational expression is either true or false.

3. The value of a relational expression is 0 if the expression is false or 1 if the expression is


true.

4. The if statement regards an expression with the value 0 as false.

5. The if statement regards an expression with a nonzero value as true.


6. For an if statement to conditionally execute a group of statements, the statements must be
enclosed in a set of braces.

7. In an if/else statement, the if part executes its statement or block if the expression is true,
and the else part executes its statement or block if the expression is false.

8. The trailing else in an if/else if statement has a similar purpose as the default section of a
switch statement.

9. The if/else if statement is actually a form of the nested if statement.

10. If the sub-expression on the left of the && logical operator is false, the right sub-
expression is not checked.
11. If the sub-expression on the left of the || logical operator is true, the right sub-expression
is not checked.

12. The ! logical operator has higher precedence than the other logical operators.

13. The logical operators have left-to-right associativity.

14. The && logical operator works best when testing a number to determine if it is within a
range.

15. The || logical operator works best when testing a number to determine if it is outside a
range.

16. A variable with block scope is only visible when the program is executing in the block
containing the variable’s definition.
17. You use the relational operator to determine whether one string object is greater than
another string object.

18. An expression using the conditional operator is called a(n) ternary expression.

19. The expression that is tested by a switch statement must have a(n) integer value.

20. The expression following a case statement must be a(n) integer literal.

21. A program will “fall through” a case section if it is missing the break statement.
22. What value will be stored in the variable t after each of the following statements
executes?
A) t = (12 > 1); → 1
B) t = (2 < 0); → 0
C) t = (5 == (3 * 2)); → 0
D) t = (5 == 5); → 1

CHAPTER 5 – Loops and Files

1. To increment a value means to increase it by one, and to decrement a value means to


decrease it by one.

2. When the increment or decrement operator is placed before the operand (or to the
operand’s left), the operator is being used in prefix mode.

3. When the increment or decrement operator is placed after the operand (or to the
operand’s right), the operator is being used in postfix mode.
4. The statement or block that is repeated is known as the body of the loop.
5. Each repetition of a loop is known as a(n) iteration.

6. A loop that evaluates its test expression before each repetition is a(n) pretest loop.

7. A loop that evaluates its test expression after each repetition is a(n) posttest loop.

8. A loop that does not have a way of stopping is a(n) infinite loop.
9. A(n) counter is a variable that “counts” the number of times a loop repeats.

10. A(n) running total is a sum of numbers that accumulates with each iteration of a loop.

11. A(n) accumulator is a variable that is initialized to some starting value, usually zero, and
then has numbers added to it in each iteration of a loop.

12. A(n) sentinel is a special value that marks the end of a series of values.
13. The do-while loop always iterates at least once.

14. The while and for loops will not iterate at all if their test expressions are false to start
with.

15. The for loop is ideal for situations that require a counter.

16. Inside the for loop’s parentheses, the first expression is the initialization, the second
expression is the test, and the third expression is the update.

17. A loop that is inside another is called a(n) nested loop.

18. The break statement causes a loop to terminate immediately.

19. The continue statement causes a loop to skip the remaining statements in the current
iteration.

CHAPTER 6 – Functions
1. The function header is the part of a function definition that shows the function name,
return type, and parameter list.

2. If a function doesn’t return a value, the word void will appear as its return type.
3. Either a function’s definition or its prototype must precede all calls to the function.

4. Values that are sent into a function are called arguments.

5. Special variables that hold copies of function arguments are called parameters.

6. When only a copy of an argument is passed to a function, it is said to be passed by value.


7. A(n) function prototype eliminates the need to place a function definition before all calls
to the function.

8. A(n) local variable is defined inside a function and is not accessible outside the function.

9. Global variables are defined outside all functions and are accessible to any function
within their scope.

10. Global variables provide an easy way to share large amounts of data among all the
functions in a program.

11. Unless you explicitly initialize global variables, they are automatically initialized to 0.

12. If a function has a local variable with the same name as a global variable, only the local
variable can be seen by the function.
13. Static local variables retain their value between function calls.

14. The return statement causes a function to end immediately.

15. Default arguments are passed to parameters automatically if no argument is provided in


the function call.

16. When a function uses a mixture of parameters with and without default arguments, the
parameters with default arguments must be defined last.

17. The value of a default argument must be a(n) constant.

18. When used as parameters, reference variables allow a function to access the parameter’s
original argument.

19. Reference variables are defined like regular variables, except there is a(n) ampersand
(&) in front of the name.

20. Reference variables allow arguments to be passed by reference.


21. The exit function causes a program to terminate.

22. Two or more functions may have the same name, as long as their parameter lists are
different.
CHAPTER 7 - Arrays

1. An array is a collection of like variables that are accessed using a common name and an
index.

2. An individual element of an array is accessed using a subscript.

3. In C++, array subscripts start at 0.

4. The value in brackets used to access an array element is called a subscript or index.

5. Subscripts in C++ always start with 0.


6. Array subscripts must be a(n) integer.

7. C++ does not perform bounds checking on arrays.


8. Using an invalid subscript for an array can result in unpredictable behavior.

9. You should always make sure that your subscript is within the array’s declared bounds.

10. If you leave out the size of an array during initialization, C++ will determine the size
from the number of elements in the initialization list.

int scores[] = {1, 2, 3, 4}; // size = 4

11. If you partially initialize an array, the remaining elements will be set to zero (for numeric
types).

12. Array names are like pointers to the first element in the array.

13. To access each element of an array, you typically use a loop, often a for loop.

14. You cannot use the assignment operator (=) to copy entire arrays.
15. To copy one array to another, you must copy each element individually using a loop.

16. A parallel array is two or more arrays that are related by their corresponding
subscripts.

17. A two-dimensional array is like a table made up of rows and columns.

18. To declare a 2D array, you specify two sizes in brackets, e.g.

int table[3][4];

19. The total number of elements in a 2D array is the product of rows × columns.

20. You can use nested loops to process the contents of a 2D array.
21. C++ does not perform bounds checking on 2D arrays either.
22. The Standard Template Library (STL) provides the vector class as a modern alternative
to arrays.

23. A vector is a sequence container that can change size automatically.

24. You must #include <vector> to use the vector class.

25. To declare a vector of integers:

vector<int> numbers;

26. To add a new element to the end of a vector, use the push_back function.
27. You can access individual vector elements using bracket notation or the at() member
function.
28. The size() member function returns the number of elements in the vector.

29. Use pop_back() to remove the last element from a vector.

30. Vectors automatically manage their memory, so you don’t need to track the size
manually when adding/removing elements.

Gaddis, T. (2021). Starting out with C++: From control structures through objects (10th ed.).
Pearson.

You might also like