MODULE in Computer Fundamentals
MODULE in Computer Fundamentals
MODULE 3
Computer Fundamentals
Programming 1
1. Understand the computer systems, program development cycle, basic analysis and
design techniques for computer programming.
1. A computer assisted method for the recording and analyzing of existing or hypothetical
systems is
a. data transmission b. data flow c. data capture d. data processing
6. The section of the CPU that selects, interprets and sees to the execution of program
instructions
a. memory b. register unit c. control unit d. ALU
7. The examination and changing of single bits or small groups of his within a word is called
a. bit b. byte c. bit manipulation d. bit slice
9. The 2’s complement of a binary no. is obtained by adding … to its 1’s complement.
a. 0 b. 1 c. 10 d. 12
11. Any storage device added to a computer beyond the immediately usable main storage is
known as
a. floppy disk b. hard disk c. backing storage d. punched card
- Input/Output (I/O)
- Arithmetic & logical calculation
- Decisions
- Repetitions
- Examples: C, C++, Fortran 90, Java, Basic, HTML, Perl, Haskell, Prolog, Pascal, etc.
A programming language consists of all symbols, characters, and usage rules that permit
people to communicate with computers.
Even though all programming languages have an instruction set that permits these familiar
operations to be performed, there’s a marked difference to be found in the symbols, characters,
and syntax of them.
Programming languages are said to be lower or higher, depending on whether they are closer to
the language the computer itself uses (lower, which means 0s and 1s) or to the language that
people use (higher, which means more English like)
High-level languages assist programmers by reducing the number of computer operation details
they have to specify, so that they can concentrate more on the logic needed to solve the problem.
High-level languages are often oriented toward a particular class of processing problems.
Unlike assembly programs, high-level language programs may be used with different makes of
computers with little modification.
COMPILERS
Naturally, a source program written in a high-level language must also be translated into machine-
usable code.
There are two kinds of translators —compilers and interpreters — and high-level languages are
called either compiled languages or interpreted languages.
The machine language code is called the object code and can be saved and either run (executed)
immediately or later.
INTERPRETERS
Translation and execution occur immediately, one after another, one statement at a time.
Unlike the compiled languages, no object code is stored and there is no compilation. This means
that in a program where one statement is executed several times (such reading an employee’s
payroll record), that statement is converted to machine language each time it is executed.
Compiled languages programs are better than interpreted languages programs as they can be
executed faster and more efficiently once the object code has been obtained.
On the other hand, interpreted languages programs do not generate object code and so are usually
easier to code and test.
Lesson 2 – Algorithms
Problem Solving Process
System Design:
Algorithm Design:
Programming:
Computing problems
- Actions to be executed
- Order to be executed
- Example: recipe
Program Control
Algorithm: Definition
o A cooking recipe, The rules of how to play a game, VCR instructions, Description
of a martial arts technique, Directions for driving from A to B, A knitting pattern, A
car repair manual
A Wrong Algorithm
If you follow this algorithm, you will never finish washing your hair!
Properties of Algorithms
Inputs:
- A number of quantities are provided to an algorithm initially before the algorithm begins.
These quantities are the inputs which are processed by the algorithm.
Definiteness:
- The processing rules specified in the algorithm must be precise, unambiguous and lead
to a specific action.
Effectiveness:
- Each instruction must be sufficiently basic such that it can, in principle, be carried out in a
finite time by a person with paper and pencil.
Finiteness:
- The total time to carry out all the steps in the algorithm must be finite. An algorithm may
contain instructions to repetitively carry out a group of instructions. This requirement
implies that the number repetitions must be finite.
Outputs:
Correctness:
- Correct set of output must be produced from the set of inputs. For the same input data, it
must always produce the same output.
WRITING ALGORITHMS
A Simple Example
Pseudocode
It is, as the name suggests, cannot be executed on a real computer, but models and resembles
real programming code, and is written at roughly the same level of detail.
It is very much like a 3GL and is therefore more easily translated into programming language.
For many programmers and program designers is the preferred way to state algorithms and
program specifications.
These keywords often resemble programming commands and often occur as pairs of words.
- When writing a keyword in pseudocodewe would often write it in UPPERCASE and may
even highlight it using boldface.
- This enables the person working with the algorithm to easily see the flow of logic through
the algorithm.
Example
Values
Variables
Components of an Algorithm
- Repeat an instruction. while (or maybe until) some true or falsecondition occurs.
- Test the condition each time before repeating the instruction.
FLOWCHARTS
These flowcharts play a vital role in the programming of a problem and are quite helpful in
understanding the logic of complicated and lengthy problems.
FLOWCHART SYMBOLS
GUIDELINES
In drawing a proper flowchart, all necessary requirements should be listed out in logical order.
The flowchart should be clear, neat and easy to follow There should not be any room for
ambiguity in understanding the flowchart.
The usual direction of the flow of a procedure or system is from left to right or top to bottom.
Only one flow line should come out from a process symbol.
Only one flow line should enter a decision symbol, but two or three flow lines, one for each
possible answer, should leave the decision symbol.
The flow of sequence is generally from the top of the page to the bottom of the page. This can
vary with loops which need to flow back to an entry point.
A flow chart on one page should not break and jump to another page.
A flow chart should have no more than around 15 symbols (not including START and STOP).
SYSTEM FLOWCHART
System flowchart describes the data flow for a data processing system.
It provides a logical diagram of how the system operates. It represents the flow of documents, the
operations performed in data processing system.
- the sources from which data is generated and device used for this purpose.
- various processing steps involved.
- the intermediate and final output prepared and the devices used for their storage..
PROGRAM FLOWCHART
A program flowchart represents, in detail, the various steps to be performed within the system for
transforming the input into output.
It serves as the basis for discussions and communication between the system analysts and the
programmers.
Program flowcharts are quite helpful to programmers in organizing their programming efforts.
Instructions: Read and understand each given item carefully. Write your final answer clearly and
neatly. No Erasure. Erasure made is considered wrong.
a. Executable file
b. Source file
c. Object file
d. Directory file
a. Source file
b. Executable file
c. Object file
d. Directory file
a. a rectangle
b. a rhombus
c. a parallelogram
d. a circle
6. A flowchart needs to represent the a situation where for each mark a student is award 'Pass'
or 'Fail'...the system will consider the mark and if it's 50 or over award 'Pass', else it awards
'Fail'. This is an example of which of the algorithm constructs?
a. decision
b. loop
c. sequence
d. all of the above
7. We can show the sequence of steps in an algorithm in a structural diagram called a flowchart.
a. True
b. False
10. A flowchart
The process associated with creating successful applications programs is called the program
development life cycle(PDLC).
There are various approaches in program development each with different perspectives.
Figure 1-1 illustrates the program development cycle, which can be broken down into at least
seven steps:
Waterfall Model
The first published model of program development process was derived from other engineering
process (Royce, 1970).
It is a multistage model with each stage concerned with separate activities of program
development.
Each stage in the model follows a linear sequence one after another, often with feedback loops.
Professional computer programmers write programs to satisfy the needs of others, called users
or end users.
Examples of end users include a HR Dept. that needs a printed list of all employees.
A Billing Dept. that wants a list of clients who are 30 or more days overdue on their payments,
and an
Order Dept. that needs a website to provide buyers with an online shopping cart.
Because programmers are providing a service to these users, programmers must first understand
what the users want.
When a program runs, you usually think of the logic as a cycle of input-processing-output
operations, but when you plan a program, you think of the output first.
The heart of the programming process lies in planning the program’s logic.
During this phase of the process, the programmer plans the steps of the program, deciding what
steps to include and how to order them.
Two common planning tools are flowcharts and pseudocode; you will work with many examples
of flowcharts and pseudocode in this course.
The programmer shouldn’t worry about the syntax of any particular language during the planning
stage, but should focus on figuring out what sequence of events will lead from the available input
to the desired output.
Planning the logic includes thinking carefully about all the possible data values a program might
encounter and how you want the program to handle each scenario.
- Structure charts
- Flowcharts
- Pseudocode
- Data modeling
The process of walking through a program’s logic on paper before you actually write the program
is called desk-checking.
Structure charts – depict the overall organization of a program, and how the modules of a
program – logically related operations that perform a well-defined task – are defined and how
they connect to each other hierarchically.
The programmer can write the source code for a program only after the logic is developed.
Programmers choose particular languages because some have built-in capabilities that make
them more efficient than others at handling certain types of operations.
Despite their differences, programming languages are quite alike in their basic capabilities – each
can handle input operations, arithmetic processing, output operations, and other standard
functions.
Only after choosing a language must the programmer be concerned with proper punctuation and
the correct spelling of commands – in other words, using the correct syntax.
Some experienced programmers can successfully combine logic planning and program coding in
one step.
Even though there are many programming languages, each computer knows only one language
– its machine language, which consists of 1s and 0s.
A program that is free of syntax errors in not necessarily free logical errors.
A logical error results when you see a syntactically correct statement but use the wrong one for
the current context.
For example, the English sentence The dog chases the cat, although syntactically perfect, is not
logically correct if the dog chases a ball or the cat is the aggressor.
After a program is free of syntax errors, the programmer can test it-that is, execute it with some
sample data to see whether the results are logically correct.
If you execute the program, provide the value 2 as input to the program, and the answer 4 is
displayed, you have executed one successful test run of the program.
However, if the answer 40 is displayed, maybe the program contains a logical error.
Maybe the second line of code was mistyped with an extra zero.
For example, if you write the program to double a number, then enter 2 and get an output value of
4, that doesn’t necessarily mean you have a correct program.
After the program is thoroughly tested and debugged, it is ready for the organization to use.
Putting the program into production might mean simply running the program once, if it was written
to satisfy a user’s request for a special list.
However, the process might take months if the program will be run on a regular basis, or if it is
one of a large system of programs being developed.
Perhaps data-entry people must be trained to prepare the input for the new program, users must
be trained to understand the output, or existing data in the company must be changed to an
entirely new format to accommodate this program.
Conversion, the entire set of actions an organization must take to switch over to using a new
program or set of programs, can sometimes take months or years to accomplish.
1. New tax rates are legislated, the format of an input file is altered, or the end user requires
additional information not included in the original output specifications.
2. New features will be added.
Instructions: Read and understand each given item carefully. Write your final answer clearly and
neatly. No Erasure. Erasure made is considered wrong.
1. Which of the following pairs of steps in the programming process is in the correct order?
3. The two most commonly used tools for planning a program’s logic are _________.
6. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user
to enter a value. The program multiplies the value by 10 and outputs the result.
7. Draw a flowchart or write pseudocode to represent the logic of a program that allows the user
to enter a value for one edge of a cube. The program calculates the surface area of one side
of the cube, the surface area of the cube, and its volume. The program outputs all the results.
Lesson 4 – Introduction to C
What is C?
Its instructions consists of terms that resemble algebraic expressions, supplemented by certain
English keywords such as if, else, for, and do.
Features modern flow control and data structures, and a rich setof operators.
History of C
C was developed in the 1970s by Dennis Ritchie at Bell Labs (Murray Hill, New Jersey) in the
process of implementing the Unix operating system on a DEC PDP-11 computer.
Preparing to Program
Structure of a C Program
One or more statements forms a block (compound) statement with the individual statements
enclosed within a pair of braces, i.e., { }
Comments in C
The first line /* A simple C program that outputs two lines of text */ starts with /*and ends with */
Comments are not executable statements and they are ignored by the compiler
Preprocessor Directives
Lines that begin with the #(read hash) sign are preprocessor directives
They are not executable code line but indications for the C preprocessor
The C preprocessor is a tool which filters your source code before it is compiled
In this case, it tells the compiler’s preprocessor that the contents of the file stdio.hshould be
included at the place where #include appears
The file stdio.his called a header file in C and it contains the declaration needed to perform
standard input output operations
It is independent from whether it is at the beginning, at the end or by the middle of the code -its
content is always the first to be executed when a program starts
In C, all functions are followed by a pair of parenthesis () that, optionally, can include arguments
within
The content of the main function follows immediately to its header enclosed between braces {}, as
in our example
The code inside the braces {} are program statements that are to be executed
The first statement printf("Hello, world\n"); causes the text Hello, world, enclosed in quotes, to be
printed in the standard output device (often known as the console)
\n tells to print a new line which causes the next text to be printed on next line
Hence, the next printf causes the text Welcome to ITC213 to be printed on next line
The closing brace } at the last line program signifies the end of the main() function and hence the
end of program
An editor is a specialized word processor used to prepare source modules in the language of
choice (e.g. C, C++, Java, Fortran)
The preprocessor adds in standard pre-written code (boilerplate) from include files you specify
to produce a complete source module
The compiler produces object code for the target computer/ operating system
An executable file is a program that will run on the computer. The editor, preprocessor, compiler
and linker are all executables. So is your program
A compilation error occurs when the compiler finds something in the source code that it can’t
compile
Linker errors are relatively rare and usually result from misspelling the name of a C library
function
- In this case, you get an Error: undefined symbols: error message, followed by the
misspelled name (preceded by an underscore)
Lesson 5 – C Fundamentals
The C Character Set
Set of characters that are used as building blocks to form basic program elements
Identifiers
Names given to various program elements such as variables, functions, labels, and other user
defined items
- For e.g., if your C compiler recognizes only the first 3 characters, the identifiers payand
paymentare same
Keywords
You cannot use a keyword for any other purpose other than as a keyword in a C program
Data Types
Determines how much space it occupies in storage and how the bit pattern stored is interpreted
The predefined types in C are the basic types and the type void
Basic types consist of the integer types and the floating types
The C language supports four basic data types, each of which are represented differently within
the computer memory
Variables
Variable Declaration
When you declare a variable, you instruct the compiler to set aside storage space for the variable
Constants
Unlike a variable, the value stored in a constant can’t be changed during program execution
Every constant has a type that is determined by its value and its notation
A literal constant is a value that is typed directly into the source code wherever it is needed
Numeric Constants
Floating-point constants:
Integer Constants
Character Constants
Character constants have integer values that are determined by the computer’s particular
character set
Most computers, and virtually all personal computers, make use of the ASCII character set
In ASCII, each individual character is numerically encoded with its own unique 7-bit combination
Escape Sequences
Certain nonprinting characters, as well as the backslash (\) and the apostrophe ('), can be
expressed in terms of escape sequences
Begins with a backward slash and is followed by one or more special characters
A character constant written in the form of escape sequence is called backslash character
constant
Symbolic Constants
Whenever you need the constant’s value in your program, you use its name as you would use a
variable name
C has two methods for defining a symbolic constant: the #define directive and the const keyword
Initialization of Variables
To initialize a variable, the declaration must consist of a datatype, followed by a variable name,
and equal sign (=) and a literal constant of the appropriate type
Expressions
An expression is any valid combination of different entities for example a constant, a variable, an
array element or a reference to a function
It may also consist of some combination of such entities, interconnected by one or more
operators
Simple Expressions
- The simplest C expression consists of a single item: a simple variable, literal constant or
symbolic constant
Complex Expressions
For example:
- -2+8
- is an expression consisting of the sub expressions 2and 8and the addition operator +
Statements
A statement is a complete direction instructing the computer to carry out some task
- Expression statements,
- Compound statements,
- Control statements
Expression Statements
Compound Statements
Unlike an expression statement, a compound statement does not end with a semicolon
Control Statements
Used to create special program features, such as logical tests, loops and branches
Many control statements require that other statements be embedded within them
The term white spacerefers to spaces, tabs, and blank lines in your source code
When the compiler reads a statement in your source code, it looks for the characters in the
statement and for the terminating semicolon, but it ignores white space
Instructions: Read and understand each given item carefully. Write your final answer clearly and
neatly. No Erasure. Erasure made is considered wrong.
a. a name
b. a data type
c. both of the above
d. none of the above
a. null
b. garbage
c. compost
d. its identifier
a. numeric variable
b. string variable
c. numeric constant
d. string constant
a. is a binary operator
b. has left-to-right associativity
c. is most often represented by a colon
d. two of the above
a. division
b. subtraction
c. assignment
d. none of the above
8. What are nonexecuting statements that programmers place within code to explain program
statements in English?
a. pseudocode
b. trivia
c. user documentation
d. comments
An operator is a symbol that instructs C to perform some operation, or action, on one or more
operands
Operators that require two operands are binary operators and operators that require one is unary
Operator Categories
Arithmetic Operators
C’s arithmetic operators perform mathematical operations such as addition and subtraction
Suppose that aand bare integer variables and cand dare floating-point variables. Also suppose
that c1and c2is a character variable. Their initial values is shown below.
If you use more than one operator in an expression, C uses precedence rule to find out which
operator’s calculation is to be formed.
When two operators have the same precedence, C uses associativityrule to determine which
operation is to be carried out first.
Operations with a higher precedence are carried out before operations having a lower
precedence.
The five arithmetic operators are divided into two precedence groups.
3 + 4 * 5 is equivalent to 3 + (4 * 5)
The natural order of evaluation can be altered through the use of parenthesis
Typecast
To change the type of an expression, precede the expression with name of type enclosed in
parenthesis
For example, if i is a type int, the expression (float) i casts ito type float. In other words, the
program makes an internal copy of the value of i in floating-point format.
A typecast, or simply cast does not change the data type associated with the expression itself
Multiple Assignment
Multiple assignments of the form identifier 1 = identifier 2 = ... = expression are permissible in C
- x = y = z = 10
- x = (y = (z = 10));
Assignment operators have lower precedence than other operators and their associativityis right
to left
Compound Assignment
C contains the following five additional assignment operators; +=, -=, /=, *=and %=, often known
as compound assignment
Unary Operators
Unary Minus(-)
- Increments/decrements the operand value and the resultant value is used in the
expression
- The current value of the operand is used in the expression and its value is
incremented/decremented
- A compile time operator and, when used with an operand, it returns the number of bytes
the operand occupies
- printf("int takes %d bytes", sizeof(int));
Unary operators have higher precedence than arithmetic operators and their associativityis right-
to-left
Logical Operators
Logical operators let you combine two or more relational expressions into a single expression that
evaluates to either true or false
Suppose i is an integer variable whose value is 7, f is a floating point variable whose value is 5.5,
and c is character constant that represents the character 'w'
The conditional operator is C’s only ternary operator, meaning that it takes three operands
If exp1 evaluates to true (that is, nonzero), the entire expression evaluates to the value of exp2. If
exp1 evaluates to false (that is, zero), the entire expression evaluates as the value of exp3
Instructions: Read and understand each given item carefully. Write your final answer clearly and
neatly. No Erasure. Erasure made is considered wrong.
C language does not define any keyword to perform these input/output operations
The getcharfunction reads the next character available from the standard input device (typically a
keyboard) and returns the character read
variable_name = getchar();
The putcharfunction can be used to write a single character to a standard output device (typically
a monitor)
Can perform rounding, aligning columns, right/left justification, inserting literal characters,
exponential format, hexadecimal format, and fixed width and precision
Other-arguments ( arg1 , arg2 , ..., argn ): correspond to each conversion specification in format-
string
Example
There must be exactly the same of number of arguments (after the format string) as there are
conversion specifications, and the conversion specifications and the arguments are matched in
order from left to right
The arguments can be any valid expression and they must match the data type as specified in
the conversion specification
Conversion Specifications
Each conversion specification begins with a %and ends with a conversion character.
Between the %and the conversion character there may be, in order:
Conversion Characters
Can read all the built-in data types and automatically convert numbers into the proper internal
format
scanf reads characters from the standard input, interprets them according to the specification in
format-string , and stores the results in the remaining arguments arg1 , arg2 , ..., argn , each of
which must be a pointer that indicate where the corresponding converted input should be stored
Format String
The format string usually contains conversion specifications, which are used to control conversion
of input. The format string may contain:
Any character that cannot be interpreted according to the conversion specification terminates the
current input field, andis put back into the input buffer. This character is then the firstone read for
the next input item
Conversion Character
Skipping Characters
A white-space character in format-string causes scanf to skip one or more white-space characters
A non-white-space character in format-string causes scanfto read and discard matching characters
in the input
Suppressing input
- An * placed before conversion character tells scanfto read a field but not assign to any
variable
- In effect, that input field is skipped. Such a conversion specification corresponds to no
variable argument
SELECTION
A selection statement is a one in which one group of statement is selected from several available
groups, depending on the outcome of a logical test
If condition true, print statement executed and program goes on to next statement
- If false, print statement is ignored and the program goes onto the next statement
The if statement
Allows your program to execute a single statement, or a block of statements enclosed between
braces, if a given condition is true
if ( expression )
statement
- In either case, execution then passes to whatever code follows the ifstatement
expression can be any valid C expression that produces a scalar value and statement can be
simple or compound or even another control statement
Flowchart of if
Examples of if
Using if-else, you can specify an action to be performed both when the condition is true and
when it is false
Flowchart of if - else
Nested-ifs
In a nested if, an elsestatement always refers to the nearest ifstatement that is within the same
block as the elseand that is not already associated with an else
Example
if-else-if ladder
The value of expression is tested against the constants present in the case labels
When a match is found, the statement sequence , if present, associated with that case is
executed until the break statement or the end of the switch statement is reached
- The default label is optional, and if it is not present, no action takes place if all matches
fail
Examples
The statement sequence after the default label is executed when no caseconstants matches the
expression value
REPETITION
Repetition is the process of executing a group of statements more than one time as long as some
condition remains true
Repetition in C can be implemented using three control statements: while, do –while, for
Psuedocode:
Counter-controlled repetition
Example
A class of ten students took a quiz. The grades (integers in the range 0 to 100) for this quiz are
available to you. Determine the class average on the quiz
Pseudocode:
while ( expression )
statement
As with if, expression can be any valid C expression that produces a scalar value and statement
can be simple or compound or may be a control statement
The statement inside the while loop must include some feature that eventually alters the value of
the expression , thus providing a stopping condition for the loop
More Examples
Sentinel-Controlled Repetition
Problem :
Typically:
- expr1 is used to initialize the loop control variable and is an assignment expression
- expr2 is a logical expression and represents a condition that must be true for the loop to
continue
- expr3 is used to alter the value of control variable and is often an increment/decrement or
assignment expression
printf("HelloWorld\n");
Examples
Similar to the whilestatement but condition for repetition tested after the body of the loop is
performed
do
statement
while (expr);
More Examples
The do-whilestatement is most appropriate when the loop body must be executed at least once
On Loop Statements
Because of the features that are built into the for statement, it is particularly well suited for loops
in which the number of passes is known in advance
while loops should be used when the no of times the statements inside the loop to be executed is
not known in advance
Use do-whileloop, when you want the loop body to execute at least once for the first time
regardless of the outcome of condition
Comma operator can be used for multiple initialization and multiple processing of loop control
variables in a forstatement
You can omit, any of the three expression of the for statement
If you omit first or third expression, nothing happens at the time of their evaluation
Instructions: Read and understand each given item carefully. Write your final answer clearly and
neatly. No Erasure. Erasure made is considered wrong.
I. Identification
1. A _________ is one that represents only one of two states, usually expressed as true or
false.
2. An if statement contains a tested condition and an action that is taken only when the
expression is _____.
3. An else statement holds the statements that execute only when the tested expression is
_____.
4. _________ operators are the symbols that express comparisons. Examples include ==, >, <,
>=, <=, and <>.
5. A _________ statement is a group of statements inclosed in a curly braces.
6. An ____ logical operator contains two or more decisions; all conditions must be true for an
action to take place.
7. A _______ is a decision within either the if or else of another decision.
8. An ____ logical operator contains two or more decisions; if at least one condition is met, the
resulting action takes place.
9. The logical ____ operator is a symbol that reverses the meaning of a conditional expression.
10. A ____ operator is one that uses only one operand.
7. If sales = 100, rate = 0.10, and expenses = 50, which of the following expressions is true?
a. sales >= expenses AND rate < 1 b. sales < 200 OR expenses < 100
c. expenses = rate OR sales = rate d. two of the above
10. When you use a range check, you compare a variable to the _________ value in the
range.
a. lowest b. middle c. highest d. lowest or
highest
1. The structure that allows you to write one set of instructions that operates on multiple,
separate sets of data is the __________.
A. Sequence B. Loop C. Selection D. Case
2. The loop that frequently appears in a program’s mainline logic __________.
A. Always depends on whether a variable equals 0.
B. Is an example of an infinite loop.
C. Is an unstructured loop.
D. Works correctly based on the same logic as other loops.
3. Which of the following is not a step that must occur with every correctly working loop?
A. Initialize a loop control variable before the loop starts.
B. Compare the loop control value to a sentinel during each iteration.
C. Set the loop control value equal to a sentinel during each iteration.
D. Alter the loop control variable during each iteration.
4. The statements executed within a loop are known collectively as the __________.
A. Loop body B. Loop controls C. Sequences D. Sentinels
5. A counter keeps track of _________.
A. The number of times an event has occurred.
B. The number of machine cycles required by a segment of a program.
C. The number of loop structures within a program.
D. The number of times software has been revised.
6. Adding 1 to a variable is also called _________ it.
A. Digesting B. Resetting C. Decrementing D. Incrementing
7. Which of the following is a definite loop?
A. A loop that executes as long as a user continues to enter valid data.
B. A loop that executes 1000 times
C. Both of the above
D. None of the above
8. Which of the following is an indefinite loop?
A. A loop that executes exactly 10 times.
B. A loop that follows a prompt that asks a user how many repetitions to make and uses
the value to control the loop.
C. Both of the above
D. None of the above
9. When you decrement a variable, you __________.
A. Set it to 0 B. Reduce it by one-tenth C. Subtract a value from it D.
Remove it from a program
10. When two loops are nested, the loop that is contained by the other is the __________
loop.
A. Captive B. Unstructured C. Inner D. Outer
11. When loops are nested, __________.
A. They typically share a loop control variable.
B. One must end before other begins.
C. Both must be the same type-definite or indefinite.
D. None of the above
12. Most programmers use a for loop __________.
A. For every loop they write.
B. When they know the exact number of times a loop will repeat.
C. When a loop must repeat many times.
D. When a loop will not repeat.
13. A report that lists only totals, with no details about individual records, is a(n)
__________ report.
A. Accumulator B. Final C. Group D. Summary
14. Typically, the value added to a counter variable is ___________.
A. 0 B. 1 C. The same for each iteration D. Different in each
iteration
15. Typically, the value added to an accumulator variable is __________.
A. 0 B. 1 C. The same for each iteration D. Different in each
iteration
16. After an accumulator or counter variable is displayed at the end of a program, it is best
to __________.
A. Delete the variable from the program.
B. Reset the variable to 0.
C. Subtract 1 from the variable.
D. None of the above.
17. When you __________, you make sure data items are the correct type and fall within
the correct range.
A. Validate data B. Employ offensive programming C. Use object
orientation
D. Count loop iterations.
18. Overriding a user’s entered value by setting it to a predetermined value is known as
__________.
A. Forcing B. Accumulating C. Validating D. Pushing
19. To ensure that a user’s entry is the correct data type, frequently you __________.
A. Prompt the user to verify that the type is correct.
B. Use a method built into the programming language.
C. include a statement at the beginning of the program that lists the data types allowed.
D. All of the above
20. A variable might hold an incorrect value even when it is __________.
A. The correct data type
B. Within a required range
C. A constant coded by the programmer
D. All of the above
C. D.
References