Programming Fundamentals, Past Papers

Programming Fundamentals Past Paper 2019 – MSC IT (UOS)

Programming Fundamentals Past Paper 2019 MSc IT University of Sargodha

University: University of Sargodha (UOS)
Program: MSC IT – 1st Term
Subject: Programming Fundamentals (CMP-2122)
Year: 2019
Time Allowed: 2 Hours 30 Minutes
Maximum Marks: 80


Why Use This Programming Fundamentals Past Paper?

This past paper helps students understand programming basics, commonly repeated questions, and exam structure. It is useful for revision and conceptual clarity.

  • Understand core programming concepts
  • Practice short conceptual questions
  • Prepare logic-based programming problems
  • Improve problem-solving skills

Programming Fundamentals Past Paper 2019 (Complete)

Below is the complete text of the paper:

University of Sargodha
M.Sc. IT – 1st Term Examination 2019

Subject: IT
Paper: Programming Fundamentals (CMP-2122)
Time Allowed: 02:30 Hours
Maximum Marks: 80

Note: Objective part is compulsory. Attempt any three questions from subjective part.

Objective Part (Compulsory)

Q.1 Write short answers of the following in 2–3 lines each. (16×2)

  1. Differentiate between assembly languages and high-level languages.
  2. Define structured programming languages.
  3. Define algorithm.
  4. List the sub processes involved in program development.
  5. Discuss at least four data types of C/C++ with examples.
  6. Discuss input and output commands of C/C++ with examples.
  7. Discuss at least three selection control structures of C/C++ with examples.
  8. Differentiate between while and do-while loops.
  9. What does break statement do?
  10. What does continue statement do?
  11. What are the different types of user-defined functions available in C/C++?
  12. Differentiate between one-dimensional and two-dimensional arrays.
  13. What are pointers in C/C++?
  14. What are records in C/C++?
  15. How can files be handled in C/C++?
  16. What do you know about testing and debugging?

Subjective Part

Q.2 Given a string, count alphabetic letters and decimal digits.

Q.3 Find the number that occurs odd number of times in an array.

Q.4 Write a program to print all leaders in an array.

Q.5 Count number of words in a string.

Q.6 Write a program to find area of a triangle using Heron’s formula.


Solved Short Questions (Objective Section)

1. Difference between assembly and high-level languages

Assembly language is machine dependent and uses mnemonics, while high-level languages are machine independent and closer to human language.

Reference: GeeksforGeeks

2. Structured programming language

A structured programming language uses sequence, selection, and iteration constructs to improve code clarity and maintainability.

Reference: Encyclopedia Britannica

3. Algorithm

An algorithm is a finite set of well-defined steps used to solve a specific problem.

Reference: Khan Academy

4. Program development subprocesses

Problem analysis, algorithm design, coding, testing, debugging, and maintenance.

Reference: TutorialsPoint

5. Data types in C/C++

Common data types include int, float, char, and double, used to store different kinds of values.

Reference: cplusplus.com

6. Input and output commands

C uses scanf/printf, while C++ uses cin/cout for input and output operations.

Reference: GeeksforGeeks

7. Selection control structures

if, if-else, and switch statements are used for decision making in C/C++.

Reference: Programiz

8. While vs do-while loop

While loop checks condition first; do-while executes at least once before checking condition.

Reference: GeeksforGeeks

9. Break statement

Break immediately terminates the loop or switch statement.

Reference: cppreference

10. Continue statement

Continue skips the current iteration and moves to the next iteration of the loop.

Reference: cppreference

11. User-defined functions

User-defined functions can be categorized as functions with arguments and return values, without arguments, or without return values.

Reference: TutorialsPoint

12. One-dimensional vs two-dimensional arrays

One-dimensional arrays store linear data, while two-dimensional arrays store data in tabular form.

Reference: Programiz

13. Pointers

Pointers store the memory address of another variable and enable dynamic memory access.

Reference: GeeksforGeeks

14. Records

Records (structures) group variables of different data types under one name.

Reference: Programiz

15. File handling

File handling allows reading and writing data using file pointers such as fopen, fread, fwrite, and fclose.

Reference: GeeksforGeeks

16. Testing and debugging

Testing identifies errors, while debugging locates and fixes those errors in a program.

Reference: IBM


Download PDF

Download Programming Fundamentals Past Paper 2019 (PDF)


Related Past Papers


Frequently Asked Questions

Is this paper useful for exam preparation?
Yes, it helps understand real exam questions and marking patterns.

Is the PDF officially provided?
The paper is shared for educational and reference purposes.

Solved programs – Programming Fundamentals 2019 (subjective part)

Q.2 Count alphabetic letters and decimal digits in a string

#include <stdio.h>
#include <ctype.h>

int main(void) {
    char str[200];
    int letters = 0, digits = 0;

    printf("Enter a string: ");
    fgets(str, sizeof str, stdin);

    for (int i = 0; str[i] != '\0'; i++) {
        if (isalpha((unsigned char)str[i]))
            letters++;
        else if (isdigit((unsigned char)str[i]))
            digits++;
    }
    printf("Letters = %d, Digits = %d\n", letters, digits);
    return 0;
}

Sample: “Hello World 2019 is 7th” → Letters = 14, Digits = 5.

Q.3 Find the number that occurs an odd number of times

#include <stdio.h>

/* XOR of all elements cancels pairs; the value left
   is the one that occurs an odd number of times. */
int main(void) {
    int arr[] = {2, 3, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2};
    int n = sizeof arr / sizeof arr[0];
    int result = 0;

    for (int i = 0; i < n; i++)
        result ^= arr[i];

    printf("Number occurring odd number of times: %d\n", result);
    return 0;
}

Output: 5 (it appears three times; every other value appears an even number of times). XOR works because x ^ x = 0 and x ^ 0 = x. Time O(n), no extra memory.

Q.4 Print all leaders in an array

#include <stdio.h>

/* A leader is greater than every element to its right.
   The right-most element is always a leader. */
int main(void) {
    int arr[] = {16, 17, 4, 3, 5, 2};
    int n = sizeof arr / sizeof arr[0];
    int maxRight = arr[n - 1];

    printf("Leaders: %d", maxRight);
    for (int i = n - 2; i >= 0; i--) {
        if (arr[i] > maxRight) {
            maxRight = arr[i];
            printf(" %d", maxRight);
        }
    }
    printf("\n");
    return 0;
}

Output for {16, 17, 4, 3, 5, 2}: Leaders 2 5 17 (scanned from the right; 17, 5 and 2 are greater than everything to their right). Time O(n).

Q.5 Count the number of words in a string

#include <stdio.h>
#include <ctype.h>

int main(void) {
    char str[200];
    int words = 0, inWord = 0;

    printf("Enter a sentence: ");
    fgets(str, sizeof str, stdin);

    for (int i = 0; str[i] != '\0'; i++) {
        if (isspace((unsigned char)str[i]))
            inWord = 0;
        else if (!inWord) {      /* start of a new word */
            inWord = 1;
            words++;
        }
    }
    printf("Number of words = %d\n", words);
    return 0;
}

Sample: “ The quick brown fox ” → 4 (extra spaces are handled because a word is counted only when a non-space follows a space).

Q.6 Area of a triangle using Heron’s formula

#include <stdio.h>
#include <math.h>

int main(void) {
    double a, b, c, s, area;

    printf("Enter three sides: ");
    scanf("%lf %lf %lf", &a, &b, &c);

    if (a + b <= c || a + c <= b || b + c <= a) {
        printf("These sides do not form a triangle.\n");
        return 0;
    }
    s = (a + b + c) / 2;                       /* semi-perimeter */
    area = sqrt(s * (s - a) * (s - b) * (s - c));
    printf("Area = %.2f\n", area);
    return 0;
}

Heron’s formula: s = (a + b + c)/2, Area = √(s(s − a)(s − b)(s − c)). Sample: sides 3, 4, 5 → Area = 6.00. Compile with -lm on Linux for sqrt().

All programs were compiled and tested with GCC.

Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.