100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS1511 Assignment 2 Semester 1 2024 R56,23   Add to cart

Exam (elaborations)

COS1511 Assignment 2 Semester 1 2024

 11 views  0 purchase

COS1511 Assignment 2 Semester 1 2024 QUESTIONS WITH ANSWERS

Preview 3 out of 18  pages

  • May 23, 2024
  • 18
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
All documents for this subject (26)
avatar-seller
smillanih
COS1511
ASSIGNMENT 2
SEMESTER 1 2024
QUESTIONS WITH COMPLETE ANSWERS




[DATE]
musyokah11@gmail.com
[Company address]

, 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

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 smillanih. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

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

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67232 documents were sold in the last 30 days

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

Start selling
R56,23
  • (0)
  Buy now