- Given the names and marks of n=10 students in the course Introduction to C++
(a) Calculate their grades (0 – 49 = F, 50 – 64 = C, 65 – 79 = B, 80 – 100 = A).
(b) Calculate the average, minimum and maximum marks.
Write a program to generate a report that resembles the below.
No. | Student name | Mark | Grade |
1 | AAA | 88 | A |
2 | BBB | 45 | F |
3 | CCC | 60 | C |
…. |
- A factory has n=20 staff and they are paid an hourly rate of 50. Their salaries are calculated as follows:
salary | = hours * rate | for hours between 0 and <=40 |
= 300 + (hours – 40) * rate * 1.5 | for hours >40 and <= 60 | |
= 525 + (hours – 60) * rate * 2.0 | for hours > 60 |
Write a program to generate a report that resembles the below.
No. | Employee name | Hours | Salary (RM) |
1 | AAA | 10 | 75.00 |
2 | BBB | 45 | 356.25 |
3 | CCC | 60 | 675.00 |
…. |
- Write a program to generate 200 integer random numbers in the range [1000, 9999].
- How many of these numbers fall in the ranges 1000-2499, 2500-4999, 5000-7499 and 7500-9999?
- How many of these numbers are: (i) even, (ii) divisible by 5?
- Create a text file called contacts using Notepad (Programs > Accessories > Notepad) with n=15 records for storing their name, sex, age, telephone and email address that resembles the
Write a program to read the file and display your contact information.
- Write a program to simulate the sum of points on a pair of dice. If the user guesses it correctly, it displays the message “Good guess – Congratulations!” or the message “Bad guess – Try again!” if the guess is wrong. The program terminates when the user makes a correct guess within a maximum of 5
- Create a text file called countries to store n=12 country names and their Write a program to read the file and store the country names and their capitals in arrays country and capital respectively. Then when the user enters a country name, the program displays a message that resembles “The capital of … is ….” if there is a match or the message “The country name is not in the list.”
- The data below represents a list of products sold at My Street
ProdCode | Price (RM) |
AAA | 5.00 |
BBB | 7.00 |
CCC | 2.30 |
DDD | 1.70 |
EEE | 9.00 |
Write a program to print a receipt for the below purchase.
ProdCode | Quantity |
BBB | 2 |
DDD | 4 |
EEE | 1 |
The receipt should resemble something like the one shown below.
ProdCode |
My Street Shop
Quantity |
Price |
Amount (RM) |
BBB | 2 | 7.00 | 14.00 |
DDD | 4 | 1.70 | 6.80 |
EEE | 1 | 9.00 | 9.00 |
Total purchase = RM xxx.xx |
- Write a program using functions to calculate the areas and circumferences of circles given their radii 2, 7, 12,
7.7 and 23.5. Round your output to 4 decimal places.
- Given the following strings:
“It is a nice and beautiful day” “Time and tide waits for no man” “It is a small, small world”
Write a program to
- count the number of ‘a’s in each string
- replace all occurrence of ‘a’ with ‘A’
- remove all embedded blanks
- right and justify each string
- Given 10 countries and their Write a program to:
- Display the capital, given the country
- Display the country, given the capital
(If a country or capital is not in the list, display a suitable message.)
- What is a collection? Write a program to manipulate (add, insert, remove, reverse) a set of student objects using the collection
- Write a program using structure to store club members’ names, area codes and telephone Input values for these members and display them according to their area code.
- Generate 100 unique integer random numbers in array x[]. Sort the numbers in ascending order of Then, use a binary search to match a given number in the array. Display the position of the element in the array if a match is found; if not, display the message “No match”.
- Enter a string and store it in an Then determine the position(s) of a specified character in the array. (For example, if the input string is “I love Malaysia”, the positions of the character ‘a’ are 8, 10 and 14.)
- Write a program to compute the product of (a) two integer numbers and (b) two double numbers using a constructor and a destructor.
Answers to Above Questions on Programming Principles
Answer 1: The C++ codes that can be used to calculate the grades of 10 students are:
using namespace std; int main() { int marks[10] = {78, 92, 63, 45, 87, 50, 72, 91, 55, 81}; // example marks // loop through the marks array and calculate the grades for (int i = 0; i < 10; i++) { if (marks[i] >= 80) { cout << “Student “ << i+1 << ” got an A.” << endl; } else if (marks[i] >= 65) { cout << “Student “ << i+1 << ” got a B.” << endl; } else if (marks[i] >= 50) { cout << “Student “ << i+1 << ” got a C.” << endl; } else { cout << “Student “ << i+1 << ” got an F.” << endl; } } return 0; }
Get completed answers on the above questions on C++ from the best programming experts of Student Life Saviour in South Africa at affordable prices.
Content Removal Request
If you believe that the content above belongs to you, and you don’t want it to be published anymore, then request for its removal by filling the details below. It will only be removed if you can provide sufficient evidence of its ownership.