TUTORIAL MATTER: Chapters 14, 15 and 17 of the Study Guide
(Tutorial Letter 102 available under Additional
Resources on the COS1512 website on
myUnisa )
Chapters 14 (excluding section 14.3), 15
(excluding sections 15.2 and 15.3) and 17 of
Savitch
WEIGHT: 25%
QUIZ AVAILABLE: 26 August 2023
DUE DATE: 18 September 2022
CUT-OFF DATE 18 September 2022
NB: This assignment consists of two parts:
• a part where you write and implement program code (this part) and
• an MCQ part where you answer questions on the code you have written,
and the material covered in this assignment.
The MCQ part of the assignment will be available in the Assessment Shell for
Assignment 4 on the myModules site for COS1512.
You will not be able to do the MCQ part unless you have completed the
coding part.
Question 1
The program below contains an incomplete recursive functionraised_to_power().
The function returns the value of the first parameternumber of type float raised to
the value of the second parameterpower of type int for all values of power greater
than or equal to 0.
The algorithm used in this question to write a recursive function to raise a float
value number to a positive power uses repeated multiplication as follows:
numberpower =1 if power = 0
= number x numberpower-1 otherwise
In other words, number raised to power gives 1 if power is 0;
Open Rubric
, and otherwise numberpower can be calculated with the formula:
number x numberpower-1
(a) Complete the function header in line 3.
(b) Using the fact that any value raised to the power of 0 is 1, complete the base
case in line 10 and 11.
(c) Why do we need a base case in a recursive function?
(d) What is the purpose of the general case?
Question 2
Examine the code fragment below and answer the questions that follow:
1: #include <iostream>
2: using namespace std;
3:
4: //
5:
6: class A
7: {
8: private:
9: int x;
10: protected:
11: int getX();
12: public:
13: void setX();
14: };
The benefits of buying summaries with Stuvia:
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
You can quickly pay through EFT, credit card or Stuvia-credit for the summaries. There is no membership needed.
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 LIBRARYpro. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy this summary for R49,97. You're not tied to anything after your purchase.