50% found this document useful (2 votes)
5K views5 pages

Computer Science HSSC II Model PBA Solution

Uploaded by

iqra ilyas
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
50% found this document useful (2 votes)
5K views5 pages

Computer Science HSSC II Model PBA Solution

Uploaded by

iqra ilyas
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/ 5

1|Page

COMPUTER SCIENCE 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;

// Input the principal amount and tenure


cout << "Enter the principal amount (in rupees): ";
cin >> principal;
cout << "Enter the tenure (in years): ";
cin >> tenure;
2|Page

// Calculate profit based on conditions


if (principal < 25000 && tenure < 10) {
profit = 0.05 * principal; // 5% of principal amount
} else if (principal == 25000 && tenure == 10) {
profit = 0.07 * principal; // 7% of principal amount
} else if (principal > 25000 && tenure > 10) {
profit = 0.10 * principal; // 10% of principal amount
} else {
profit = 0; // No profit for other cases
cout << "No profit calculated based on the given conditions.\n";
return 0;
}

// Output the profit


cout << "The profit based on the given conditions is: " << profit << " rupees.\n";

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

// Variables for calculations


double totalRainfall = 0, averageRainfall = 0, maxRainfall = 0;
int maxMonthIndex = 0;
4|Page

// Input rainfall data


cout << "Enter the total rainfall (in mm) for each month:\n";
for (int i = 0; i < 12; i++) {
cout << months[i] << ": ";
cin >> rainfall[i];

// Update total rainfall


totalRainfall += rainfall[i];

// Find the maximum rainfall


if (rainfall[i] > maxRainfall) {
maxRainfall = rainfall[i];
maxMonthIndex = i;
}
}

// Calculate average rainfall


averageRainfall = totalRainfall / 12;

// Output the results


cout << "\nTotal rainfall for the year: " << totalRainfall << " mm\n";
cout << "Average monthly rainfall: " << averageRainfall << " mm\n";
cout << "Month with the highest rainfall: " << months[maxMonthIndex]
<< " (" << maxRainfall << " mm)\n";

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)

You might also like