100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Question and Answers (EXAM PACK) | COS1511 Programming I R50,00   Add to cart

Exam (elaborations)

Question and Answers (EXAM PACK) | COS1511 Programming I

 53 views  4 purchases

Question and Answers (EXAM PACK) | COS1511 Programming I | Answers to Jan 2022, Nov 2018, Nov 2021, Nov 2016, June 2016.

Preview 4 out of 212  pages

  • October 22, 2022
  • 212
  • 2022/2023
  • Exam (elaborations)
  • Questions & answers
All documents for this subject (37)
avatar-seller
robyn9745
OCT/NOV 2022




75




This examination question paper consists of 9 pages out of 75 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.




ALL THE BEST!




[TURN OVER]

, 2 COS1511
OCT/NOV 2022

QUESTION 1 6 MARKS

1.1 Consider the C++ code segment below. What value will newval have after this code has
been executed? (2)

int var1 = 4;
int var2 = 10;
int newval = 0;
if (var1 * 2 >= var2)
newval = 5 + 2 * var2;
else if (var1 < var2)
newval = var2 - var1 * 2;
else
newval = var1;

1.2 Suppose the input value for a is 5. What is the value of a after the following C++ code has
been executed? (2)

int a;
cin >> a;
switch (a)
{
case 1: a += 3;
case 3: a = a * 3; break;
case 5: a = ++a + 10;
case 6: a /= 2;
default: a = a + 1;
}

1.3 Consider the following C++ code segment: (2)

int findValue(int numberP)
{
int count = 0;
int value = 20;
while (count < numberP)
{
value += count;
count ++;
}
return value;
}

What will be the output of the following statement executed in the main function?

cout << findValue(3);




[TURN OVER]

, 3 COS1511
OCT/NOV 2022

QUESTION 2 4 MARKS

In Questions 2.1 and 2.2 you have to write down what the purpose of the segment of code is. Look at
the following example before answering the questions:

int a,b,c;
cin >> a >> b >> c;
cout << c + b + a;

The purpose of the above code segment is to input three integer values and display their sum.

Now answer questions 2.1 and 2.2 below:

2.1 Assume that s and n have been declared as integers. Explain in words what the purpose of
the following segment of code is: (2)

int s = 0;
int n = 0;
while (n <= 5)
{
s = s + n;
n++;
}

2.2 Explain the purpose of the following segment of code: (2)

int numbers[ ] = {11, 0, 15, 0, 16, 23};
int c = 0;
for (int i = 0; i <= 5; i++)
if (numbers[i] != 0)
c += 1;

QUESTION 3 8 MARKS

Consider the following C++ code segment below.

1 int result(int valueP)
2 {
3 int a = 2;
4 int count = 0;
5 while (count < valueP)
6 {
7 a += count + a / 2;
8 count += 2;
9 }
10 return a;
11 }

Demonstrate the execution and output of the program by drawing a variable diagram that traces each
line of code if the value of value P is 6. You are required to draw a variable diagram to illustrate
what the code does.

[TURN OVER]

, 4 COS1511
OCT/NOV 2022

QUESTION 4 8 MARKS

Karlton Learning wants a program that displays the amount of money a company owes for a seminar.
The fee per person is based on the number of people the company registers. For example, if the
company registers 7 people then the amount owed is R 560.00. If the user enters a number that is less
than or equal to 0, the program should display an appropriate error message.

Number of registrants Fee per person
1 through 4 R100.00
5 through 10 R 80.00
11 or more R 60.00

Complete the program below.

#include <iostream>
using namespace std;
int main()
{
// Question 4.1 (2)
// Declare a variable to hold the number of registrants and a
// variable to hold the amount a company owes for a seminar.

// Question 4.2 (2)
// Write statements to input the number of registrants. If the
// user enters a number that is less than or equal to 0, the
// program should display an appropriate error message.

// Question 4.3 (4)
// Write statements to calculate and display the amount of money
// a company owes for a seminar.

return 0;
}

QUESTION 5 5 MARKS

In order to plan road maintenance, the department of Road Works request that road usage must be
determined. This is done by counting the number of vehicles using the road with two wheels, four
wheels and more than four wheels respectively. Write down ONLY the necessary switch statement
to count the number of vehicles with two wheels, four wheels and more than four wheels. Do NOT write
a complete program.

Use the following variables:

int nrWheels; // number of wheels of a vehicle using the road

int countTwo, countFour, countMore; // the counters for the
// number of vehicles with
// two, four and more than
// four wheels respectively



[TURN OVER]

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller robyn9745. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for R50,00. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

60434 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Start selling
R50,00  4x  sold
  • (0)
  Buy now