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

COS1511 Assignment 2 Semester 1 2024

Rating
-
Sold
-
Pages
18
Grade
A+
Uploaded on
23-05-2024
Written in
2023/2024

COS1511 Assignment 2 Semester 1 2024 questions with answers











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

Document information

Uploaded on
May 23, 2024
Number of pages
18
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

+254792947610



COS1511
Assignment 2
Semester 1 2024
QUESTIONS WITH DETAILED ANSWERS

, COS1511 Assignment 2 Semester 1 2024
Question 1
Write function headers for the functions described below:

(i) The function check has two parameters. The first parameter should be an
integer number and thesecond parameter a floating point number. The function
returns no value.

(ii) The function mult has two floating point numbers as parameters and
returns the result ofmultiplying them.

(iii) The function time inputs seconds, minutes and hours and returns them
as parameters to itscalling function.

(iv) The function countChar returns the number of occurrences of a character in a string, both
provided as
parameters.


(i) The function check has two parameters: an integer and a floating point number, and it returns no
value.

def check(integer_param: int, float_param: float) -> None:
pass

(ii) The function mult has two floating point numbers as parameters and returns their product.

def mult(float_param1: float, float_param2: float) -> float:
pass

(iii) The function time takes seconds, minutes, and hours as inputs and returns them to the calling
function.

def time(seconds: int, minutes: int, hours: int) -> (int, int, int):
pass

(iv) The function countChar returns the number of occurrences of a character in a string, both
provided as parameters.

def countChar(input_string: str, character: str) -> int:
pass


Question 2

Find the error(s) in each of the following program segments and explain how
the error(s) can becorrected:

(i) int function1()
{

cout << "Inside function function1 " <<

, endl; int function2()
{

cout << "Inside function function1 " << endl;
}
}

(ii) int sum(int x, int y)
{

int result;
result = x +
y;
}

(iii) int computeProd(int n)
{

if (n == 0)
return 0;

else

}


n * computeProd(n – 1);


(iv) void aFunction(float a)
{


float a;
cout << a << endl;
}


(v) void theProduct()
{

int
a;
int
b;
int
c;
int result;

cout << “Enter three integers “ <<
endl; cin >> a >> b >> c;
result = a * b * c;
cout << “Result is “ << result <<
endl; return result;
}
3

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.
pablitoh11 University of South Africa (Unisa)
View profile
Follow You need to be logged in order to follow users or courses
Sold
2483
Member since
2 year
Number of followers
1496
Documents
2138
Last sold
1 week ago

3,7

291 reviews

5
120
4
48
3
70
2
12
1
41

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 exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT 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