0% found this document useful (0 votes)
4 views29 pages

Hsscii Pba Question Bank

The document outlines the format for developing a Question Item Bank (QIB) for PBA – SSC-II & HSSC-II exams, specifically for the subject of Computer Science. It includes various programming questions and solutions related to Object Oriented Programming, Control Structures, and arithmetic operations in C++. Each question is designed to assess students' understanding of C++ programming concepts and includes sample code and expected outputs.

Uploaded by

zeshanabdullah49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views29 pages

Hsscii Pba Question Bank

The document outlines the format for developing a Question Item Bank (QIB) for PBA – SSC-II & HSSC-II exams, specifically for the subject of Computer Science. It includes various programming questions and solutions related to Object Oriented Programming, Control Structures, and arithmetic operations in C++. Each question is designed to assess students' understanding of C++ programming concepts and includes sample code and expected outputs.

Uploaded by

zeshanabdullah49
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

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
Region: _______warm______ Class: _____HSSC-II______ Subject: Computer Science
Total SLO: ___________ Total Qs: ____________

Ser. SLO Sec A/B Questions Answer


1. Object Oriented Programming Part 1 Q.1: Write a program that #include <iostream>
in C++ (unit 3) demonstrates the use of escape using namespace std;
& sequences such as \n (newline), \t
Control Structure (unit 4) (tab), and \\ (backslash). int main() {
// Using escape sequences
cout << "Escape Sequences
Example:\n";
Section cout << "1. Newline (\\n)\n";
A cout << "2. Tab (\\t)\tThis is
tabbed\n";
cout << "3. Backslash (\\\\)\n";

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

Q.3: Solving arithmetic problems to Formula: simple


(calculate interest) interst=(principal*rate*time)/100
using namespace std;

int main() {
float principal, rate, time, interest;

// Input the principal, rate, and


time
cout << "Enter the principal
amount: ";
cin >> principal;
cout << "Enter the rate of interest:
";
cin >> rate;
cout << "Enter the time (in years):
";
cin >> time;

// Calculate simple interest


interest = (principal * rate * time)
/ 100;
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
// Output the result
cout << "The simple interest is: "
<< interest << endl;

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;

// Input the two numbers for ratio


cout << "Enter the first number
(a): ";
cin >> a;
cout << "Enter the second number
(b): ";
cin >> b;

// Output the ratio


if (b != 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
cout << "The ratio of " << a << "
to " << b << " is: " << a / b << endl;
} else {
cout << "Error: Division by zero
is not allowed!" << endl;
}

return 0;
}

Q.5: Solving arithmetic problems to #include <iostream>


(calculate grades.) using namespace std;
Grading System:
• Marks ≥ 90: Grade A int main() {
• Marks ≥ 80 and < 90: Grade B float marks;
• Marks ≥ 70 and < 80: Grade C
• Marks ≥ 60 and < 70: Grade D // Input the marks
• Marks < 60: Grade F cout << "Enter the marks: ";
cin >> marks;

// Determine the grade based on


marks
if (marks >= 90) {
cout << "Grade: A" << endl;
} else if (marks >= 80) {
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 << "Grade: B" << endl;
} else if (marks >= 70) {
cout << "Grade: C" << endl;
} else if (marks >= 60) {
cout << "Grade: D" << endl;
} else {
cout << "Grade: F" << endl;
}

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;

// Categorize the person based on


age
if (age < 13) {
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 << "The person is a Child."
<< endl;
}
else if (age >= 13 && age < 20) {
cout << "The person is a
Teenager." << endl;
}
else if (age >= 20 && age < 60) {
cout << "The person is an
Adult." << endl;
}
else if (age >= 60) {
cout << "The person is a Senior
Citizen." << endl;
}
else {
cout << "Invalid input!" << endl;
}

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;

// Input the sides of the triangle


cout << "Enter the lengths of the
three sides of the triangle: ";
cin >> side1 >> side2 >> side3;

// Check if the sides form a valid


triangle
if (side1 + side2 > side3 && side1
+ side3 > side2 && side2 + side3 >
side1) {
// Determine the type of
triangle
if (side1 == side2 && side2 ==
side3) {
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 << "The triangle is
Equilateral." << endl;
} else if (side1 == side2 || side1
== side3 || side2 == side3) {
cout << "The triangle is
Isosceles." << endl;
} else {
cout << "The triangle is
Scalene." << endl;
}
} else {
cout << "The given sides do not
form a valid triangle." << endl;
}

return 0;
}
Q.5 Write a C++ program to perform int main() {
basic arithmetic operations (+, -, *, /) char op;
using a switch statement. float num1, num2;

cout << "Enter an operator (+, -, *,


/): ";
cin >> op;
cout << "Enter two operands: ";
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
cin >> 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;

// Function to find GCD using


Euclidean algorithm
int findGCD(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}

int main() {
int num1, num2;

// Input two numbers from user


cout << "Enter two numbers: ";
cin >> num1 >> num2;

// Calculate and display GCD


int gcd = findGCD(num1, num2);
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 << "GCD of " << num1 << "
and " << num2 << " is: " << gcd <<
endl;

return 0;
}
Q.2 write a program Finding out the #include <iostream>
LCM. using namespace std;

// Function to find GCD using


Euclidean algorithm
int findGCD(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}

// Function to find LCM using the


relationship LCM(a, b) = (a * b) /
GCD(a, b)
int findLCM(int a, int b) {
return (a * b) / findGCD(a, b);
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 num1, num2;

// Input two numbers from user


cout << "Enter two numbers: ";
cin >> num1 >> num2;

// Calculate and display LCM


int lcm = findLCM(num1, num2);
cout << "LCM of " << num1 << "
and " << num2 << " is: " << lcm <<
endl;

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);

// Input the list of strings


cout << "Enter the strings: ";
for (int i = 0; i < n; ++i) {
cin >> strings[i];
}

// Sort the list of strings


sort(strings.begin(), strings.end());

// Display the sorted list


cout << "Sorted list: ";
for (const string& str : strings) {
cout << str << " ";
}
cout << endl;

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;

cout << "Enter the number of


elements: ";
cin >> n;

int numbers[n];

// Input the list of numbers


cout << "Enter the numbers: ";
for (int i = 0; i < n; ++i) {
cin >> numbers[i];
}

// Sort the array of numbers


sort(numbers, numbers + n);

// Display the sorted list


cout << "Sorted list: ";
for (int i = 0; i < n; ++i) {
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 << numbers[i] << " ";
}
cout << endl;

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;

// Function to simulate rolling a dice


int rollDice() {
return (rand() % 6) + 1; //
Generates a random number
between 1 and 6
}

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;

// Ask the user if they want to


roll again
cout << "Roll again? (y/n): ";
cin >> choice;

} while (choice == 'y' || choice ==


'Y');

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

void displayMatrix(int mat[3][3]) {


for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cout << mat[i][j] << " ";
}
cout << endl;
}
}

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];

cout << "Enter elements of 3x3


matrix 2:\n";
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
cin >> mat2[i][j];

// Multiply matrices
multiplyMatrices(mat1, mat2,
result);

// Display the result


cout << "Result of matrix
multiplication:\n";
displayMatrix(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;

// Outer loop controls the number


of rows
for (int i = 1; i <= rows; ++i) {
// Inner loop controls the
number of columns
for (int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << endl;
}

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;

// Outer loop for rows


for (int i = 1; i <= n; ++i) {
// Inner loop for columns
for (int j = 1; j <= n; ++j) {
cout << i * j << "\t"; // Display
the product of i and j
}
cout << endl; // Move to the
next line after each row
}

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;

// Outer loop for rows


for (int i = 1; i <= rows; ++i) {
// Inner loop for printing spaces
for (int j = 1; j <= rows - i; ++j) {
cout << " ";
}
// Inner loop for printing stars
for (int k = 1; k <= i; ++k) {
cout << "*";
}
cout << endl;
}

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

// Accessing elements of the array


cout << "First element: " <<
numbers[0] << endl;
cout << "Third element: " <<
numbers[2] << endl;

// 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;

cout << "Enter the size of the


array: ";
cin >> 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

int arr[n]; // Declare an array with


user-specified size

// Input elements in the array


cout << "Enter " << n << "
elements:\n";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}

// Output the elements of the


array
cout << "The elements of the
array are:\n";
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}

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;

cout << "Enter the number of


elements: ";
cin >> n;

int arr[n];

// Input elements into the array


cout << "Enter the elements:\n";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}

// Find the largest element


int largest = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > largest) {
largest = arr[i];
}
}

cout << "The largest element is: "


<< largest << 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;
}
Q.3 display Simple Menu System by #include <iostream>
using switch statement using namespace std;

int main() {
int choice;

cout << "Menu: \n";


cout << "1. Start Game\n";
cout << "2. Load Game\n";
cout << "3. View High Scores\n";
cout << "4. Exit\n";
cout << "Enter your choice: ";
cin >> 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

You might also like