100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

COS1512 EXAM PACK 2025 [DETAILED QUESTIONS AND ANSWERS]

Rating
1.0
(1)
Sold
6
Pages
85
Grade
A+
Uploaded on
20-01-2025
Written in
2024/2025

COS1512 EXAM PACK 2025 [DETAILED QUESTIONS AND ANSWERS]

Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Course

Document information

Uploaded on
January 20, 2025
File latest updated on
February 21, 2025
Number of pages
85
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

Downloaded by Vincent master ()

,Question 1
Correct
Mark 1.00 out of 1.00

Flag question
Question text
This question is based on question 1 in the written Assignment 4.
The program in question 1 of the written assignment, contains an incomplete recursive function
raised_to_power(). This function returns the value of the first parameter number of type float
raised to the value of the second parameter power of type int for all values of power greater than
or equal to 0.
The correct function header for the function raised_to_power() is
Select one:
float raised_to_power(float number, int power) int raised_to_power(float
number, int power) float raised_to_power(int number, float power) float
raised_to_power(float number, float power)


Feedback
The correct answer is: float raised_to_power(float number, int power)

Question 2
Correct
Mark 1.00 out of 1.00

Flag question
Question text
This question is based on question 1(b) in the written Assignment 4.
The program in question 1 of the written assignment, contains an incomplete recursive function
raised_to_power(). This function returns the value of the first parameter number of type float raised
to the value of the second parameter power of type int for all values of power greater than or equal
to 0.
Based on the fact that any value raised to the power of 0 is 1, the base case for this function is
Select one:
else if (power == 0) return
(1.0); else if (power == 1)
return (1.0); else if (power > 0)
return (1.0);




else if (power == 0)
return (number * raised_to_power(number, power - 1));




Downloaded by Vincent master ()

, Feedback
The correct answer is: else if (power == 0) return (1.0);


Question 3
Incorrect
Mark 0.00 out of 1.00

Flag question
Question text
This question is based on work for question 1 in the written Assignment 4.
With recursion, the base case must eventually be reduced to a general case.
Select one:
True
False
Feedback
The correct answer is ’False’.

Question 4
Incorrect
Mark 0.00 out of 1.00

Flag question
Question text
This question is based on question 2(a) in the written Assignment 4. Question 2 included a code
fragment that you had to answer questions on. This is an extract from the code fragment: 6: class A
7: {
8: private:
9: int x;
10: protected: 11: int
getX(); 12: public:
13: void setX(); 14: }; 15:
16: int A::getX()




Downloaded by Vincent master ()

, 17: {
18: return x; 19: } 20:
21: void A::setX()
22: {
23: x=10;
24: }


The reason why line 18 is a valid access in this code fragment, is because the variable x is a private
data member of the class A. Private data members can only be accessed by other member functions
and operators of the class A. getX() is a member function of class A and therefore line 18 is a valid
access.
Select one:
True
False



Feedback
The correct answer is ’True’.

Question 5
Incorrect
Mark 0.00 out of 1.00

Flag question
Question text
This question is based on question 2(c) in the written Assignment 4. Question 2 included a code
fragment that you had to answer questions on. This is an extract from the code fragment: 27: class B
28: {
29: private:
30: int y;
31: protected:
32: A objA; 33: int
getY(); 34: public:
35: void setY();
37: };




38:
39: void B::setY()
40: {




Downloaded by Vincent master ()

Reviews from verified buyers

Showing all reviews
2 months ago

1.0

1 reviews

5
0
4
0
3
0
2
0
1
1
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Academy360 University of south africa
Follow You need to be logged in order to follow users or courses
Sold
1101
Member since
1 year
Number of followers
202
Documents
1203
Last sold
1 day ago
Academy360

On this page, you find all documents, package deals, and flashcards offered by seller Academy360.

3.9

172 reviews

5
88
4
28
3
29
2
7
1
20

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions