Blog
Programming Fundamentals Past Paper Spring 2025 – BS 2nd Semester Punjab University (IT-102)
University of the Punjab BS 4-year programme, second semester Spring 2025, Programming Fundamentals (IT-102) paper (60 marks, 3 hours). The question paper is the official University of the Punjab paper published on pu.edu.pk (BS 4-year programme past papers, Spring 2025); it is retyped here and the answers are written by Shining Study. Solved answers: outputs of five C++ programs (pre/post increment, switch fall-through, pointers, arrays) and three programs – hemisphere area, numberToRoman and flipSentence. All code was compiled and run.
Solved answers
Q1 – Output of the programs (5 × 6)
All five programs were compiled with g++ and run; the outputs below are the real outputs.
1. Program 1 Output: 17, 19--x is pre-decrement: x becomes 19 first, then 19 − 2 = 17 is printed. x++ is post-increment: the current value 19 is printed, then x becomes 20.
2. Program 2 Output: Fail
marks = 50, and the condition marks > 50 is false (50 is not greater than 50), so the whole && expression is false and the else part runs.
3. Program 3 Output: two
y = 2 jumps to case 2, prints “two”, and break exits the switch. (Without that break it would fall through to “three” and “four”.)
4. Program 4 Output: 6 2
a is passed by pointer, so *x = *x + *x changes a to 6. b is passed by value; the function doubles only its local copy y, so b stays 2.
5. Program 5
100*
53*26*
23*12The while loop changes each element until it meets 100: 5 (odd) → 6, 20 (even) → 23, 25 → 26, 50 → 53, then 100 stops the loop. Array = {6, 23, 26, 53, 100}. The for loop prints X[4]…X[1] followed by “*”, with a newline after even I (4 and 2): 100* ↵ 53*26* ↵ 23*, then X[0] × 2 = 12.Q2 (1) – Surface area of a hemisphere
#include <iostream>
using namespace std;
int main() {
const double PI = 3.14159;
double radius, area;
cout << "Enter the radius of the hemisphere: ";
cin >> radius;
area = 3 * PI * radius * radius; // Surface Area = 3 * pi * r^2
cout << "Surface area = " << area << endl;
return 0;
}Sample run: radius 7 → Surface area = 461.81.
Q2 (2) – numberToRoman
#include <iostream>
#include <string>
using namespace std;
string numberToRoman(int n) {
const string roman[] = {"I", "II", "III", "IV", "V",
"VI", "VII", "VIII", "IX", "X"};
if (n < 1 || n > 10)
return "Invalid number";
return roman[n - 1];
}
int main() {
cout << numberToRoman(1) << endl; // I
cout << numberToRoman(5) << endl; // V
cout << numberToRoman(11) << endl; // Invalid number
return 0;
}A switch statement with cases 1–10 is an equally correct answer.
Q2 (3) – flipSentence (reverse in place)
void flipSentence(char sentence[], int size) {
int i = 0, j = size - 1;
while (i < j) {
char temp = sentence[i]; // swap the two ends
sentence[i] = sentence[j];
sentence[j] = temp;
i++;
j--;
}
}
// Test
int main() {
char s[] = {'H', 'e', 'l', 'l', 'o', ' ', 'H', 'i'};
flipSentence(s, 8);
for (int k = 0; k < 8; k++) cout << s[k]; // iH olleH
return 0;
}Two indices move towards each other and swap characters, so no new array is created and the function returns nothing (void). Output order: i, H, space, o, l, l, e, H – exactly the expected table. Complexity O(n).
Upload a photo in 10 seconds — no form to fill. We clean it, solve it and credit you.
