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.
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
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 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 these notes 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 these notes for $3.00. You're not tied to anything after your purchase.