0% found this document useful (0 votes)
0 views4 pages

Janfeb2024 Memo

The document contains a series of programming questions and code snippets related to basic calculations, conditionals, loops, and functions in C++. It includes examples of calculating amounts owed based on registrants, counting non-zero values, and displaying initials from a full name. Additionally, it covers topics such as arrays, sales calculations, and product records.

Uploaded by

Laila Makunje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

Janfeb2024 Memo

The document contains a series of programming questions and code snippets related to basic calculations, conditionals, loops, and functions in C++. It includes examples of calculating amounts owed based on registrants, counting non-zero values, and displaying initials from a full name. Additionally, it covers topics such as arrays, sales calculations, and product records.

Uploaded by

Laila Makunje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

QUESTION 1

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.

cout << "Enter number of registrants: ";


cin >> registrants;
if (registrants <= 0) {
cout << "Error: Invalid number of registrants." << endl;
return 1; // Exit the program with error
}

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

for (int i = 1; i <= 10; i++) {


cout << i << endl;
}

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

float sales = 0.0;


float commission = 0.0;
cout << "Enter a sales amount: ";
cin >> sales;
while (sales > 0.0) {
commission = sales * 0.1; // Correct capitalization of 'commission'
cout << commission << endl;
cout << "Enter a sales amount: "; // Prompt again for new sales input
cin >> sales; // Add input for sales in loop
}

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

void check(int integerValue, float floatValue);

8.2

float mult(float num1, float num2);

8.3

void time(int &seconds, int &minutes, int &hours);

8.4

int countLets(char character, string str);

8.5

float calcFinal(float baseAmount, float &markup, float &discount, int


quantity);

calcDiscount(discount, productCode, number, dayOfWeek);

QUESTION 9
9.1

int sales[NUM_WEEKS][NAME];

9.2

for (int week = 0; week < NUM_WEEKS; week++) {


highest = sales[week][0];
for (int branch = 1; branch < NAME; branch++) {
if (sales[week][branch] > highest) {
highest = sales[week][branch];
}
}
cout << "The highest sales in week " << (week + 1) << " were " <<
highest << " books." << endl;
}
QUESTION 10
10.1

cout << "Product Name: " << p1.name << ", Weight: " << p1.weight << ",
Price: R" << p1.price << endl;

10.2

void read_Product_Record(Product &new_Product) {


cout << "Enter product name: ";
cin >> new_Product.name;
cout << "Enter product weight: ";
cin >> new_Product.weight;
cout << "Enter product price: ";
cin >> new_Product.price;

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

You might also like