FBISE-Computer-PBA-Class-12-Solution
FBISE-Computer-PBA-Class-12-Solution
com/@smartcomputing
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
}
Program
#include <iostream.h>
#include <string.h>
int main()
{
const int MONTHS = 12;
double rainfall[MONTHS];
double totalRainfall=0.0, averageRainfall;
int highestMonth=0;
// 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; }
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)