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 | COMPLETE ANSWERS | DUE: 2 JUNE 2025

Rating
-
Sold
12
Pages
13
Grade
A+
Uploaded on
24-05-2025
Written in
2024/2025

COS1511 ASSIGNMENT 2 | COMPLETE ANSWERS | DUE: 2 JUNE 2025










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

Document information

Uploaded on
May 24, 2025
Number of pages
13
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

, QUESTION 1
NOTE: All answers are provided into the following box: (i), (ii), (iii), (iv)


#include <iostream>
#include <string>

using namespace std;

// (i) Function 'check' – takes an int and a float, returns nothing (i) The function check
#includenumber,
void check(int <iostream>
float value) {
#include <iomanip>
// This function might check or compare the two values.
#include
// For <string>
now, we'll just display them for testing.
cout << "Integer: " std;
using namespace << number << ", Float: " << value << endl;
}
// ------------------- Question 1 -------------------
// (ii) void check(int
Function 'mult'number,
– takesfloat value) {returns their product
two floats,
cout <<
float mult(float "Integer:
num1, " << number
float num2) { << ", Float: " << value << endl;
}
return num1 * num2;
}
float mult(float num1, float num2) {
return 'time'
// (iii) Function num1 * –num2;
takes 3 reference parameters (seconds, minutes, hours)
}
// Simulates getting time values and passes them back to caller
void time(int& seconds, int& minutes, int& hours) {
void time(int&
// Example seconds, int&
static assignment (in minutes,
real use,int& hours)
could { input or system time)
be user
seconds
seconds = 30; = 30;
minutes minutes
= 45; = 45;
hours = hours
12; = 12;
} }


// (iv) int countChar(const
Function 'countChar'string&
– countsstr, char ch) {of a character in a string
occurrences
int countstring&
int countChar(const = 0; str, char ch) {
for (char
int count = 0; current : str) {
if (current
for (char current : str)=={ ch) {
count++;
if (current == ch) {
}
count++;
} }
} return count;
} count;
return
}

(example, toCount);
cout << "The character '" << toCount << "' appears " << result << " time(s) in \"" <<
example << "\"." << endl;

return 0;
}

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.
TogetherWeGraduate Deutsche Internationale Schule Johannesburg
View profile
Follow You need to be logged in order to follow users or courses
Sold
889
Member since
3 year
Number of followers
627
Documents
565
Last sold
3 months ago

3,9

97 reviews

5
54
4
11
3
14
2
3
1
15

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