Blog
Programming Fundamentals Past Paper Spring 2025 – BS 2nd Semester Punjab University (CC-112)
University of the Punjab BS 4-year programme, second semester Spring 2025, Programming Fundamentals (CC-112) 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, logical AND, switch fall-through, pointers vs value parameters, array and pointer loop) and complete programs for the area of a sector, numberToTemperatureRange and mirrorOperators. All code was compiled and tested.
Solved answers
Q1 – Outputs of the programs (5 × 6)
Each program was compiled with g++ and run (with #include <iostream>, #include <cstdlib> and using namespace std; added).
Program 1. Output: 38, 19 --x first makes x = 19, then 19 * 2 = 38 is printed, followed by “, ”. x++ prints the current value 19 and then makes x = 20.
Program 2. Output: Fail status is 60. The condition status > 60 is false (60 is not greater than 60), so the whole && is false and the else part runs.
Program 3. Output:
two
threey = 2 jumps to case 2 and prints “two”. There is no break after it, so execution falls through into case 3 and prints “three”, then break stops it. “four” is not printed.Program 4. Output: 6 2 a is passed by address, so (*x) = (*x) + (*x) doubles a to 6. b is passed by value; y = y - y only changes the local copy y, so b stays 2.
Program 5. Output:
100*
52*27*21*28The while loop changes elements until it meets 100: 5 % 4 ≠ 0 → 7; 20 % 4 = 0 → 21; 25 → 27; 50 % 4 ≠ 0 → 52; then *p = 100 stops the loop. Array = {7, 21, 27, 52, 100}. The for loop prints X[4] = 100* and, since 4 % 4 == 0, a newline; then 52*, 27*, 21* (no more newlines). Finally X[0] * 4 = 28 is printed.Q2 (1) – Area of a sector
#include <iostream>
using namespace std;
int main() {
const double PI = 3.14159;
double r, theta;
cout << "Enter radius of the circle: ";
cin >> r;
cout << "Enter central angle in degrees: ";
cin >> theta;
if (r < 0 || theta < 0 || theta > 360) {
cout << "Invalid input" << endl;
return 1;
}
double area = (theta / 360.0) * PI * r * r;
cout << "Area of the sector = " << area << endl;
return 0;
}Sample run: radius 7, angle 60 → Area of the sector = 25.6563 (= 60/360 × 3.14159 × 49).
Q2 (2) – numberToTemperatureRange
#include <iostream>
#include <string>
using namespace std;
string numberToTemperatureRange(int t) {
if (t < -100 || t > 100)
return "Invalid temperature";
if (t < 0)
return "Cold";
else if (t <= 15)
return "Cool";
else if (t <= 25)
return "Warm";
else
return "Hot";
}
int main() {
int tests[] = { -5, 0, 15, 16, 25, 26, 40, 120, -101 };
for (int t : tests)
cout << t << " -> " << numberToTemperatureRange(t) << endl;
return 0;
}Output: -5 → Cold, 0 → Cool, 15 → Cool, 16 → Warm, 25 → Warm, 26 → Hot, 40 → Hot, 120 → Invalid temperature, -101 → Invalid temperature. The invalid range is checked first so that 120 does not return “Hot”.
Q2 (3) – mirrorOperators
#include <iostream>
using namespace std;
void mirrorOperators(char arr[], int n) {
int i = 0, j = n - 1;
while (i < j) {
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
}
int main() {
char ops[] = { '+', '-', '/', '*', '%' };
int n = 5;
mirrorOperators(ops, n);
for (int i = 0; i < n; i++)
cout << ops[i] << " ";
cout << endl;
return 0;
}Output: % * / - +. Two indexes move towards each other and swap the characters, so the array is reversed in place without a second array (O(n) time, O(1) extra space).
Upload a photo in 10 seconds — no form to fill. We clean it, solve it and credit you.
