Janfeb2024 Memo
Janfeb2024 Memo
1.1
QUESTION 2
2.1 The purpose is to calculate the sum of numbers from 0 to 5.
2.2
The purpose is to count how many non-zero values are in the numbers array.
QUESTION 3
QUESTION 4
int registrants;
float amountOwed;
1.
2.
if (registrants <= 4)
amountOwed = registrants * 100;
else if (registrants <= 10)
amountOwed = registrants * 80;
else
amountOwed = registrants * 60;
cout << "The amount owed is: R" << amountOwed << endl;
QUESTION 5
switch (nrWheels) {
case 2:
countTwo++;
break;
case 4:
countFour++;
break;
default:
if (nrWheels > 4)
countMore++;
break;
}
QUESTION 6
6.1
6.2
int i = 1;
while (i <= 10) {
cout << i << endl;
i++;
}
6.3
int num = 1;
while (num <= 4) { // Change < to <=
cout << num << endl;
num++; // Add increment for num
}
6.4
QUESTION 7
int calcAverage(int crates[]) {
int total = 0;
for (int i = 0; i < NUM_DAYS; i++) {
total += crates[i];
}
return total / NUM_DAYS; // Return the average
QUESTION 8
8.1
8.2
8.3
8.4
8.5
QUESTION 9
9.1
int sales[NUM_WEEKS][NAME];
9.2
cout << "Product Name: " << p1.name << ", Weight: " << p1.weight << ",
Price: R" << p1.price << endl;
10.2
QUESTION 11
void displayInitials(string fullName) {
string initials = "";
initials += toupper(fullName[0]); // First initial
for (int i = 1; i < fullName.length(); i++) {
if (fullName[i] == ' ') {
initials += toupper(fullName[i + 1]); // Initial after each
space
}
}
cout << "Initials: " << initials << endl;
}