XII Computer PBA List of FBISE Practicals Solution
XII Computer PBA List of FBISE Practicals Solution
// Using setw
cout << setw(10) << "Name" << setw(10) << "Age" << endl;
cout << setw(10) << "Alice" << setw(10) << 30 << endl;
cout << setw(10) << "Bob" << setw(10) << 25 << endl;
return 0;
}
switch (choice)
{
case 1: // Area of Square
cout << "Enter side length: ";
cin >> side;
cout << "Area: " << side * side << endl;
break;
case 2: // Area of Rectangle
cout << "Enter length: ";
cin >> length;
cout << "Enter width: ";
cin >> width;
cout << "Area: " << length * width << endl;
break;
case 3: // Area of Triangle
cout << "Enter base: ";
cin >> base;
cout << "Enter height: ";
cin >> height;
cout << "Area: " << 0.5 * base * height << endl;
break;
case 4: // Area of Circle
cout << "Enter radius: ";
cin >> radius;
cout << "Area: " << M_PI * pow(radius, 2) << endl;
int main()
{
double a, b, c, discriminant, root1, root2;
ii. Write a program to sum two and three numbers of different date types.
#include<iostream>
using namespace std;
int addTwoNumbers(int x, float y)
{
float sum=x+y;
return sum;
}
float addThreeNumbers(int x, float y, float z)
{
float sum= x+y+z;
return sum;
}
int main( ) {
int a;
float b, c;
cout<<"Enter 3 values of different data types\nNote: First value should be of integer type and other should
be of floating types:\n";
cin>>a>>b>>c;
cout<<"\nThe sum of two different numbers are"<<addTwoNumbers(a,b);
cout<<"\n\nThe sum of two different numbers are"<<addThreeNumbers(a,b,c);
return 0;
}
iii. Write a programme to display the address and the value of a variable using pointer
#include<iostream>
using namespace std;
int main(){
int var= 3, *pvar;
pvar= &var;
cout<<pvar<<"\n"<<*pvar;
return 0;
}
{
Student S1;
S1.inputData("Saim", 17, 7);
S1.displaystd();
return 0;
}
v. Write a program to create and read a data file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
// Write to a file
ofstream outFile("data.txt"); // Create or open a file for writing
if (outFile.is_open())
{
outFile << "This is a line of text.\n";
outFile << "Another line with numbers: 123 45.6\n";
outFile.close(); // Close the file
cout << "Data written to file successfully.\n";
}
else
{
cerr << "Unable to open file for writing.\n";
return 1; // Indicate an error
}
// Read from a file
***************************************************