Computer Science HSSC II Model PBA Solution
Computer Science HSSC II Model PBA Solution
Note: You are supposed to write only the program in the PBA. Here, the explanation is
only for the sake of your better understanding.
Program:
#include <iostream>
using namespace std;
int main() {
// Declare variables
double principal, profit;
int tenure;
return 0;
}
Explanation:
1. Input Reading:
o The program prompts the user to enter the principal amount and tenure in
years.
o Both inputs are stored in their respective variables.
2. Conditions:
o If the principal is less than 25,000 and the tenure is less than 10 years, the
profit is 5% of the principal amount.
o If the principal is exactly 25,000 and the tenure is exactly 10 years, the profit
is 7% of the principal amount.
o If the principal is greater than 25,000 and the tenure is greater than 10 years,
the profit is 10% of the principal amount.
3. Default Case:
3|Page
o If none of the above conditions are met, the program outputs a message that no
profit is calculated and exits.
4. Output:
o If a profit is calculated, the program displays the calculated profit in rupees.
Sample Input/Output:
Input:
Enter the principal amount (in rupees): 20000
Enter the tenure (in years): 8
Output:
The profit based on the given conditions is: 1000 rupees.
Program:
#include <iostream>
#include <string>
using namespace std;
int main() {
// Declare an array to store rainfall for 12 months
double rainfall[12];
string months[12] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
return 0;
}
Explanation:
1. Data Input:
o The program uses an array of double to store the rainfall data for 12 months.
o A parallel string array is used to store the names of the months for easier
output.
2. Calculations:
5|Page
o The total rainfall is calculated by summing up all the elements of the rainfall
array.
o The average rainfall is obtained by dividing the total rainfall by 12.
o The month with the highest rainfall is determined by iterating through the
array and comparing values.
3. Output:
o The program outputs the total rainfall for the year, the average monthly
rainfall, and the name and amount of the month with the highest rainfall.
Sample Input/Output:
Input:
January: 80
February: 120
March: 90
April: 70
May: 110
June: 50
July: 200
August: 160
September: 130
October: 100
November: 60
December: 90
Output:
Total rainfall for the year: 1260 mm
Average monthly rainfall: 105 mm
Month with the highest rainfall: July (200 mm)