Hsscii Pba Question Bank
Hsscii Pba Question Bank
return 0;
}
Output:
Escape Sequences Example:
1. Newline (\n)
2. Tab (\t) This is tabbed
3. Backslash (\\)
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
Q.2: Write a program that #include <iostream>
demonstrates the use of setw() for #include <iomanip> // Include for
formatting output. setw
What is the compulsion for using setw() using namespace std;
manipulator?
int main() {
// Using setw for formatting
output
cout << "Item" << setw(15) <<
"Quantity" << setw(10) << "Price" <<
endl;
cout << "Apples" << setw(10) << 5
<< setw(10) << "$2.50" << endl;
cout << "Bananas" << setw(9) <<
12 << setw(10) << "$1.20" << endl;
cout << "Oranges" << setw(9) << 7
<< setw(10) << "$3.00" << endl;
return 0;
}
Output:
Item Quantity Price
Apples 5 $2.50
Bananas 12 $1.20
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
Oranges 7 $3.00
int main() {
float principal, rate, time, interest;
return 0;
}
Q.4 : Solving arithmetic problems to Formula:
(calculate ratio) Ratio of a to b=a/b
#include <iostream>
using namespace std;
int main() {
float a, b;
return 0;
}
return 0;
}
2 Q.1: Write a program that takes a #include <iostream>
person's age and categorizes them as using namespace std;
"Child", "Teenager", "Adult", or "Senior
Citizen" using the following rules: int main() {
Age < 13: Child int age;
13 <= Age < 20: Teenager
20 <= Age < 60: Adult // Input age
Section Age >= 60: Senior Citizen cout << "Enter the person's age: ";
Control Structure(unit 4) A cin >> age;
return 0;
}
Q.2: Write a program that takes an
integer input from the user and checks
if the number is even or odd.
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
Q.3:Write a program that takes an
integer (1 to 7) as input and prints the
corresponding day of the week using a
switch statement.
Q.4 #include <iostream>
Write a program that accepts the using namespace std;
lengths of three sides of a triangle and
determines whether the triangle is int main() {
equilateral, isosceles, or scalene. float side1, side2, side3;
return 0;
}
Q.5 Write a C++ program to perform int main() {
basic arithmetic operations (+, -, *, /) char op;
using a switch statement. float num1, num2;
switch (op) {
case '+': cout << num1 << " + "
<< num2 << " = " << num1 + num2
<< endl; break;
case '-': cout << num1 << " - " <<
num2 << " = " << num1 - num2 <<
endl; break;
case '*': cout << num1 << " * "
<< num2 << " = " << num1 * num2
<< endl; break;
case '/':
if (num2 != 0)
cout << num1 << " / " <<
num2 << " = " << num1 / num2 <<
endl;
else
cout << "Division by zero
error!" << endl;
break;
default: cout << "Invalid
operator" << endl;
}
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
return 0;
}
2 Loops (unit 5) Q.1 write a program Finding out the #include <iostream>
GCD. using namespace std;
int main() {
int num1, num2;
return 0;
}
Q.2 write a program Finding out the #include <iostream>
LCM. using namespace std;
int main() {
int num1, num2;
return 0;
}
Q.3 write a program for Sorting a list of #include <iostream>
items (string) #include <vector>
#include <algorithm> // for sort()
using namespace std;
int main() {
int n;
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
cout << "Enter the number of
strings: ";
cin >> n;
vector<string> strings(n);
return 0;
}
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
Q.4 write a program for Sorting a list of #include <iostream>
items (numeric) #include <algorithm> // for sort()
using namespace std;
int main() {
int n;
int numbers[n];
return 0;
}
Q.5 Generating random numbers for a #include <iostream>
dice using function #include <cstdlib> // for rand() and
srand()
#include <ctime> // for time()
using namespace std;
int main() {
// Initialize random seed based on
current time
srand(time(0));
char choice;
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
do {
// Roll the dice
int result = rollDice();
cout << "You rolled a " << result
<< endl;
return 0;
}
2 Q.1 Finding multiplication of a matrices #include <iostream>
( Maximum 3 x 3) using namespace std;
void multiplyMatrices(int
mat1[3][3], int mat2[3][3], int
result[3][3]) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
result[i][j] = 0; // Initialize the
result matrix element
for (int k = 0; k < 3; k++) {
result[i][j] += mat1[i][k] *
mat2[k][j];
}
}
}
}
int main() {
int mat1[3][3], mat2[3][3],
result[3][3];
// Input matrices
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
cout << "Enter elements of 3x3
matrix 1:\n";
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
cin >> mat1[i][j];
// Multiply matrices
multiplyMatrices(mat1, mat2,
result);
return 0;
}
Q.2 write code for #include <iostream>
using namespace std;
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
*
** int main() {
*** int rows;
****
***** cout << "Enter the number of
rows: ";
cin >> rows;
return 0;
}
Q.3 code to display the following #include <iostream>
1 2 3 4 5 using namespace std;
2 4 6 8 10
3 6 9 12 15 int main() {
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
4 8 12 16 20 int n;
5 10 15 20 25
cout << "Enter the size of the
multiplication table: ";
cin >> n;
return 0;
}
Q.4 write code for #include <iostream>
Printing a Right-Aligned Triangle Pattern using namespace std;
*
** int main() {
*** int rows;
****
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
***** cout << "Enter number of rows: ";
cin >> rows;
return 0;
}
Q.5 write Example of Array Declaration #include <iostream>
and Initialization using namespace std;
int main() {
// Declaration of an array of
integers with size 5
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
int numbers[5] = {10, 20, 30, 40,
50};
// Modifying an element
numbers[3] = 100;
cout << "Modified fourth element:
" << numbers[3] << endl;
return 0;
}
2 Q.1 write Array Input and Output #include <iostream>
Example using namespace std;
int main() {
int n;
return 0;
}
Q.2 write code for Finding the Largest #include <iostream>
Element in an Array using namespace std;
int main() {
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
int n;
int arr[n];
int main() {
int choice;
switch (choice) {
case 1:
cout << "Starting the game..."
<< endl;
break;
case 2:
cout << "Loading game..." <<
endl;
break;
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
case 3:
cout << "Displaying high
scores..." << endl;
break;
case 4:
cout << "Exiting the program.
Goodbye!" << endl;
break;
default:
cout << "Invalid choice!
Please select from the menu." <<
endl;
}
return 0;
}
Q.4
Q.5
2 Q.1
Q.2
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
Q.3
Q.4
Q.5
2 Q.1
Q.2
Q.3
Q.4
Q.5
2 Q.1
Q.2
Q.3
Q.4
Q.5
Annex B
To APSACS Sectt ltr no
APSACS/Exam/FBISE
Dated _____ Sep 2024
MS WORD FILE FORMAT FOR QUESTION ITEM BANK (QIB) DEVELOPMENT
PBA – SSC-II & HSSC-II
2 Q.1
Q.2
Q.3
Q.4
Q.5
2 Q.1
Q.2
Q.3
Q.4
Q.5