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

1 - 1 Paper - PRG100S - MainTest - Nov2022 - 2

programming

Uploaded by

ndivhuwotroye
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)
29 views9 pages

1 - 1 Paper - PRG100S - MainTest - Nov2022 - 2

programming

Uploaded by

ndivhuwotroye
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

SECTION A 60 Marks

QUESTION 1 – MULTIPLE CHOICE

1.1. Business reports that list only totals, with no individual item details, are called
____.
a. detail reports
b. control-break reports
c. transaction reports
d. summary reports

1.2. Usually, when you create nested loops, each loop must have its own ____.
a. goto statement
b. entrance condition
c. loop control variable
d. sentinel value

1.3. The ____ loop provides three actions in one compact statement.
a. for
b. do until
c. repeat
d. while

1.4. Programmers employ the acronym ____ to mean that if your input is incorrect,
your output is worthless.
a. IBOW
b. IIOW
c. GIGO
d. GIGS

1.5. A mistake programmers often make with loops is that they ____.
a. initialize the loop control variable prior to entering the loop body
b. increment the loop control variable inside of the loop body
c. enclose the inner loop entirely within the outer loop in a nested loop
d. include statements inside the loop that belong outside the loop

1.6. You usually use the for loop with ____ loops.
a. outer
b. indefinite
c. definite
d. inner

1.7. Loops are frequently used to ____; that is, to make sure it is meaningful and
useful.
a. validate data
b. simulate data
c. restructure data
d. corroborate data

1.8. In a ____, the loop body executes at least one time because the loop control
variable is not tested until after one iteration.
a. nested loop
b. pretest loop
c. loop control
d. posttest loop

1.9. ____ a data item means you override incorrect data by setting the variable to
a specific value.
a. Tracing
b. Flexing
c. Blanking
d. Forcing

1.10. Programmers use the term ____ to describe programs that are well designed
and easy to understand and maintain.
a. industrial
b. intractable
c. well behaved
d. elegant

1.11. The first step in a while loop is typically to ____.


a. increment the loop control variable
b. execute the body of the loop
c. initialize the loop control variable
d. compare the loop control variable to a constant value

1.12. When one loop appears inside another, the loop that contains the other loop is
called the ____ loop.
a. outer
b. definite
c. inner
d. indefinite

1.13. A(n) ____ is very similar to a counter that you use to count loop iterations,
except that you usually add a value other than one to this type of variable.
a. validator
b. total
c. accumulator
d. transaction
1.14. Use a counter or a(n) ____ to control a loop’s repetitions.
a. end value
b. constant
c. end statement
d. sentinel value

1.15. A comparison is correct only when the correct ____ and operator are used.
a. operations
b. index
c. operands
d. totals

1.16. In all languages, subscript values must be sequential ____.


a. fractions
b. integers
c. characters
d. real numbers

1.17. In every programming language, when you access data stored in an array, you
must use a ____ containing a value that accesses memory occupied by the array.
a. condition
b. subscript
c. key
d. superscript

1.18. The true benefit of using an array lies in your ability to use a ____ as a subscript
to the array.
a. command
b. loop
c. variable
d. constant

1.19. Parallel arrays are most useful when value pairs have a(n) ____ relationship.
a. tiered
b. direct
c. indirect
d. linked

1.20. When you search through a list from one end to the other, you are performing
a ____.
a. quadratic search
b. linear search
c. single lookup
d. binary search
1.21. The number of elements in an array is called the ____ of the array.
a. size
b. height
c. depth
d. width

1.22. An array is a(n) ____ of values in computer memory.


a. range
b. record
c. list
d. accumulation

1.23. An array can be used to replace ____.


a. nested decisions
b. loops
c. methods
d. records

1.24. Besides making your code easier to modify, using a ____ makes the code
easier to understand.
a. standard constant
b. literal constant
c. named constant
d. named variable

1.25. Providing array values is sometimes called ____.


a. declaring the array
b. accumulating the array
c. creating the array
d. populating the array

QUESTION 2 – FILL IN THE BLAN KS

2.1. To add to a variable is to ____________________ the variable.

2.2. A posttest loop that continues while a condition is true is called a


____________________ loop.

2.3. In a for statement, a loop control variable is initialized, tested, and


____________________.

2.4. ____________________ can ensure that a value is the correct data type or
that it falls within an acceptable range.

2.5. ____________________ are frequently used to accumulate totals and to


validate data.
2.6. A subscript, also called a(n) ____________________, is a number that
indicates the position of a particular item within an array.

2.7. All array elements have the same ____________________ name, but each
individual element also has a unique subscript indicating how far away it is from
the first element.

2.8. A(n) ____________________ is a variable set to indicate whether some event


has occurred.

2.9. When working with arrays, you can use ____________________ in several
ways: To hold the size of an array, as the array values, and as a subscript.

2.10. Use a(n) ____________________ to indicate the position of a particular item


within an array.

QUESTION 3 – SHORT ANSWERS


3 . 1 . What are common mistakes made by programmers in coding loops?

3.2. What are the three steps that should occur in every loop?

3.3. When are you required to use a for statement, and what are the advantages
of for statements?

3.4. What is an accumulator?

3.5. Explain when it would be appropriate to write an indefinite loop.

3.6. What happens when a beginning programmer forgets that array subscripts
start with 0?

3.7. What is the advantage of using an array to match a value in a range of


values?

3.8. Describe an array and provide an example of a real-life equivalent to an array.

3.9. How do you reference the elements in an array?

3.10. What are the steps to verify that an item number exists in an array? Provide
an example.
SECTION B 40 Marks

QUESTION 4
The following html and javascript calculates the total and average of a array of 10
Prices.
Using Notepad++ complete the following html with javascript so that it displays that which is
shown in the OUTPUT below:

<!DOCTYPE html>
<html>
<head> </head>
<body>
<h2>JavaScript For Loop</h2>
<p id="demo"></p>
<p id="totPrice"></p>
<script>
const Prices = [102, 114, 85, 65, 108, 98, 12, 36, 58, 19];
let text = "";
let total = 0;
let average = 0;
4.1 for (let i = 0; i < ___________; ______) { //loop header (3)
4.2 _______________ + "<br>"; //add price string to text (2)
4.3 ________________; //add current price to total (2)
}
4.4 average = __________________; //calculate the average (3)

document.getElementById("demo").innerHTML = text;
document.getElementById("totPrice").innerHTML = "Total: " + total + "<br>" + "Average: " +
average;
</script>
</body>
</html>

OUTPUT
QUESTION 5
The following html and javascript code performs a nested loop to display five rows and 4 columns as
shown in the output below.
Using Notepad++ complete the following html with javascript so that it displays that which is
shown in the OUTPUT below:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Nested Loops</title>
<style>

</style>
</head>
<body>
<p> <h2>Displaying five rows and four columns</h1></p>
<script>
var row = 5;
var col = 4;
var value = 1;
var text = "";
5.1 for (_____; _____; ____) { //(3) outer loop to process the rows

text =+ i + ": ";


5.2 for(_____; ______; ____){ // (3) inner loop to process the columns
5.3 if(________) //(2) check if value is less than 10
text += "0" + value + " "; // add a 0
else
text += value + " ";

5.4 _________; // (2) increment value by 1


}
document.write(text + "<br>");
text = "";
}
// document.write(text);

</script>
</body>
</html>

OUTPUT
QUESTION 6
The follow html and javascript code calculates the results of students and displays there
average, grade and results.
Using Notepad++ complete the following html with javascript so that it displays that which is
shown in the OUTPUT below:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Compute student Results</title>
</head>
<body>
<p id="averagemark"> Average </p>
<p id="grade"> Grade </p>
<p id="result"> Result </p>
<script>
let Marks = [0,0,0,0,0,0,0];
for (let i = 0; i < 6; i++) {
Marks[i] = Math.floor((Math.random() * 100) + 1); //generating random numbers
}
//declare the following variables and initialize accordingly
6.1 ___________________; //(2) average and total initialize to 0
6.2 ___________________;
6.3 ___________________; //(2) grade and results initialized to spaces
6.4 ___________________;

for(var i = 0; i<5; i++)


{
6.5 _________________; //2 add marks to total
}

document.getElementById("averagemark").innerHTML = "Average: " + average;

6.6 ________________ { //2 if the average mark is below 50


grade = "F";
}
6.7 _________________ { //2 else if the average mark is between 50 and 60
grade = "E"
}
6.8 __________________ { //2 else if the average mark is between 61 and 70
grade = "D";
}
6.9 ________________ { //2 else if the average mark is between 71 and 80
grade = "C"
}
6.10 _________________{ //2 else if the average mark is between 81 and 90
grade = "B";
}
6.11 _________________ { //2 if average mark is above 90
grade = "A";
}
document.getElementById("grade").innerHTML = "Grade: " + grade;

6.12 _________________{ //2 if the grade is E


document.getElementById("result").innerHTML = "Result: Fail";
else if(grade == "B" && grade == "A") //
document.getElementById("result").innerHTML = "Result: Pass with distinction";
else
document.getElementById("result").innerHTML = "Result: Pass";

</script>
</body>
</html>

OUTPUT

You might also like