COS1511 January Examination 2023
COS1511 January Examination 2023
70 Marks
INSTRUCTIONS:
1. Answer all the questions on a Word document/by hand and convert to PDF.
2. Number your answers and label your rough work clearly.
4. Marks are awarded for part of an answer, so do whatever you are able to in each question.
[TURN OVER]
Open Rubric
COS1511
Jan/Feb 2023
Choose the correct option and write only the number
Question 1 [20]
1.What is the output of the following code fragment? (2)
int x = 0;
while( x < 8)
cout << x << " ";
x ++;
cout << x << endl;
1. 0
2. infinite loop
3. 1 2 3 4 5 6 7 8
4. 0 1 2 3 4 5 6 7 8
int x, y, z; y = 10;
z = 3;
x = y * z - 3;
1. 0
2. 3
3. 10
4. 27
int x;
x = x + 15;
1. 0
2. 14
3. 15
4. not defined
1. Where is the \
2.Where is the
3.Nothing, it is a syntax error
4.Where is the \ endl
int x;
x = 19 % 5;
1. 4.0
2. 4
3. 3.8
4. 8
6.Given the following code fragment and the input value of 5, what output is generated? (2)
cout << "Enter the cost of the item\n"; cin >> total;
if ( total >= 5.0)
COS1511
Jan/Feb 2023
{
tax = 0.14;
cout << total + (total * tax) << endl;
}
else
{
7.Given the following code fragment and the input value of 3.0, what output is generated? (2)
}
else
{
tax = 0.10;
cout << total + (total * tax) << endl;
1. 3.0
2. 2.0
3. 3.3
4. 2.3
8.If xhas the value of 3, yhas the value of -2, and wis 10, is the following condition true or false? (2)
int x;
COS1511
Jan/Feb 2023
else
{
1. x has no value
2. x is 8
3. x has a value
4. unable to determine
10.Which of the following data types cannot be used in a switch controlling expression? (2)
1. int
2. enum
3. array
4. char
QUESTION 2 [29]
Question 2a (6)
State what output, if any, results from each of the following statement by first working it out on paper
and then including it as a program. Submit a completed table as below:
CODE OUTPUT
Example for (int i = 0; i < 10; i++) 0123456789
cout << i;
cout << endl;
Question 2b (5)
Suppose we want to find a student that qualifies for an internship. For each student, we input the name, the
age of student and the final mark obtained for the examination in a while loop. To qualify, the student
should be younger than 30 with a final mark of more than 65%. Read in values until a suitable candidate is
found. Display appropriate messages, whether successful or not. The variable names are name, age and
finalMark respectively. Complete the while loop below. You only have to write down the completed
while loop.
Question 2c (8)
The program given below gives the output below. Fill in the missing values and write only the answer.
The output:
#include <iostream>
using namespace std;
int main ()
{
2d.2----- counter;
int number;
cout << "Please enter " << LIMIT << " integers, "
<< "positive, negative, or zeros." << endl;
2d.6-----:
2d.7-----;
}
}
cout << endl;
cout << "There are " << 2d.8----- << " evens, "
<< "which includes " << zeros << " zeros."
<< endl;
cout << "The number of odd numbers is: " << odds
<< endl;
return 0;
}
QUESTION 3 [21]
In this question, we describe the problem and then you have to decide yourself how you are going to tackle it.
Question 3a (11)
The cost of renting a room at a hotel is R900 per night. For special occasions, such as a wedding or
conference, the hotel offers a special discount as follows:
Question 3b (10)
Four experiments are performed, each consisting of five test results. The results for each experiment are
given in the following list.
#include <iostream>
using namespace std;
int main()
{
3b. 1-----result, average;
Question 3c (10)
The average life expectancy (in hours) of a lightbulb based on the bulb’s wattage is listed in the table
below:
Write a program that when given a bulb’s wattage, displays the average life expectancy.
©
UNISA
2023
[TURN OVER]