, 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;
}
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;
}