youtube.
com/@smartcomputing
FBISE Computer PBA Class 12
SECTION A (Marks 15)
Question No. 1: [8 marks]
The principal amount is the initial sum of money that is invested. Profit
refers to the financial gain or return on the principal amount.
• Write a C++ program that can be used to calculate profit.
• Your program must input principal amount in rupees and tenure in
years.
• Calculate and display the profit based on the following conditions:
i. If Principal amount is less than 25000 and Tenure is less than 10 years
Profit = 5% of Principal Amount
ii. If Principal amount is equals to 25000 and Tenure is equals to 10 years
Profit = 7% of Principal Amount
iii. If Principal amount is greater than 25000 and Tenure is greater than 10 years
Profit = 10% of Principal Amount
Program
#include <iostream.h>
void main()
{
float principal, profit;
int tenure;
//Input principal amount and tenure
cout << "Enter the principal amount (in rupees): ";
cin >> principal;
cout << "Enter the tenure (in years): ";
cin >> tenure;
// Calculate profit based on conditions
if (principal < 25000 && tenure < 10)
profit = 0.05 * principal;
else if (principal == 25000 && tenure == 10)
profit = 0.07 * principal;
else if (principal > 25000 && tenure > 10)
profit = 0.10 * principal;
else
profit = 0;
// Display the profit
cout << "The profit is: " << profit << " rupees" << endl;
youtube.com/@smartcomputing
}
Question No. 2: [7 marks]
Write a C++ program that lets the user enter the total rainfall for each
of 12 months into an array of doubles. The program should calculate and
display:
• The total rainfall for the year,
• The average monthly rainfall
• The months with the highest amount.
Program
#include <iostream.h>
#include <string.h>
int main()
{
const int MONTHS = 12;
double rainfall[MONTHS];
double totalRainfall=0.0, averageRainfall;
int highestMonth=0;
// Input rainfall for each month
cout << "Enter total rainfall (in mm) for 12 months:\n";
for (int i = 0; i < MONTHS; ++i)
{
cin >> rainfall[i];
totalRainfall += rainfall[i];
// Check if current month has the highest rainfall
if (rainfall[i] > rainfall[highestMonth])
highestMonth = i;
}
// Calculate average monthly rainfall
averageRainfall = totalRainfall/MONTHS;
// Display results
cout << "\nTotal rainfall for the year: " << totalRainfall << " mm" <<
endl;
cout << "Average monthly rainfall: " << averageRainfall << " mm" << endl;
cout << "Month with the highest rainfall: " << rainfall[highestMonth] <<
" mm" << endl;
}
youtube.com/@smartcomputing
Section B (Marks 10)
Q3. Write a C++ program that have a class named “Triangle” and calculate
the area of triangle with the following conditions: (2+3)
• Two private data members base and height
• Member function area( )
Program
#include <iostream.h>
class Triangle {
private:
float base;
float height;
public:
//constructor to initialize variables
Triangle(float b, float h) { base=b; height=h; }
float area() { return 0.5*base*height; }
}; //end of class
void main() {
float base, height;
cout<<”Enter base of triangle:“;
cin>>base;
cout<<”Enter height of triangle:”;
cin>>height;
Triangle tr(base,height);
cout<<”Area of triangle is:”<<tr.area()<<endl;
}
Q4. What will be the output of the following program segments? (2+3)
No. Program segment Output
i. int x=100,*myptr; 0x7ffee4c47b8c
myptr=&x; 100
cout<<myptr<<”\n”<<*myptr;
ii. int power(int n) { Result: 81
return (n*n*n*n); Result: 1377
} Result: 1378
int main()
{
int n=163;
int result=0;
int remainder;
while(n!=0) {
remainder=n%10;
result=result+power(remainder);
n=n/10;
cout<<”\n Result: “<<result;
}
return 0; }
youtube.com/@smartcomputing