Continued From Overleaf                                           4
Total Pages
                      Invigilator’s Signature                                   Candidate’s SAP Code.
                      THE UNIVERSITY OF LAHORE
                               Faculty of Information Technology
                              Department of Software Engineering
                                     Spring Semester 2022
                                   Final Term Examination
                                Mr. Umar Rana
  Instructor’s Name:            Mr. Awais Shoukat               Paper:             Programming Fundamentals
  Date:                         01-06-2022                      Subject Code:      CS-02115|11
  Time Allowed:                 2 hour                          Total Marks:       50
Instructions for Candidates
  i.     Attempt all questions.
 ii.     The use of calculator or any electronic device is strictly prohibited.
iii.     Submit the question paper along with the answer sheet.
iv.      Cross blank pages before handing over Answer-book to the examination staff at completion of this
         section of the examination.
Question 1: Choose the right option from the following.                                    [Marks = 1x8 = 8]
       1. What are mandatory parts in function declaration?
       a) return type,function name                         c) both a and b
       b) return type,function name,parameters              d) none of the mentioned
       2. What is the scope of the variable declared in the user definied function?
       a) whole program                                      c) both a and b
       b) only inside the function’s {} block                d) none of the mentioned
       3. Which of the following correctly declares an array?
       a) int array[10];                                     c) array{10};
       b) int array;                                         d) array array[10];
       4. Which of the following gives the memory address of the first element in array?
       a) array[0];                                          c) array(2);
       b) array[1];                                          d) array;
                                                                                                 Page 1 of 4
                                                Please turn over
                                           Continued From Overleaf
   5. Choose the right option
   string* x, y;
   a) x is a pointer to a string, y is a string              c) both x and y are pointer to string types
   b) y is a pointer to a string, x is a string              d) none of the mentioned
   6. What will happen in this code?
       int a = 100, b = 200;
       int *p = &a, *q = &b;
       p = q;
   a) b is assigned to a                                     c) a is assigned to b
   b) p now points to b                                      d) q now points to a
   7. The result of a Relational operation is always
   a) either True or False                                   c) is equal or less or more
   b) is less than or is more than                           d) All of these
   8. What will be the output of the below mention statements?
               char c = 65;
               cout << c;
   a) B                                                 c) 65
   b) C                                                 d) A
Question 2:   Write Output of the following Codes.                                               [ 2x4=8 Marks]
 for (int i=2; i<8; i+=3){
         for (int j=1; j<=i; j++){
                 cout << j << " ";
                 cout << "\n";}
 }
 int arr[4][2] = {{1, 2},{3, 4},{5, 6},{7,8}};
 int i, j;
 cout<<"The Two-dimensional Array is:\n";
 for(i=0; i<4; i++)
 {
 for(j=0; j<1; j++)
 cout<<arr[i][j]+arr[i][j+1]<<" ";
 cout<<endl;
 }
 int vals[3]={25,14,99}, *valptr;
 valptr = vals;
 cout<<vals<<" "<<*vals<<" "<<*(valptr+1)<<"
 "<<*(valptr+2);
 const int SIZE=8;
 int set[SIZE]={5,10,15,20,25,30,35,40};
 int *numPtr,count;
 numPtr = &set[7];
 for (count=0;count<SIZE;count++)
 { cout << *numPtr << " ";
   numPtr--;}
                                                                                                    Page 2 of 4
                                                  Please turn over
                                          Continued From Overleaf
    Question 3: Write Short answers of the followings.                                        [ 2x9=18 Marks]
    1. What is the size of a pointer variable?
    2. Write difference between static and global variable? Explain with an example.
    3. What is the advantage of using file handling? Write down the steps to read data from a file
       (text/csv) and store it in variables?
    4. Differentiate between Seekg and Seekp function, also describe their use and working?
    5. Print the following shape using nested loops
                                     *
                                   ***
                                *****
    6. Write an input validation loop that asks the user to enter a number in the range of 10 through
       25. (No need to write complete code just write Logic)
    7. Write a function named timesTen The function should have an integer parameter named
       number. When timesTen is called, it should display the product of number times ten. (Note:
       just write the function. Do not write a complete program.).
    8. If you are writing a function that accepts an argument and you want to make sure the function
       cannot change the value of the argument, what do you do?
    9. When a function accepts multiple arguments, does it matter in what order the arguments are
       passed in?
Question 4                                                                                              [6]
Given the below searching algorithm, how many times a while loop runs to find the values (12, 35, 56) one
by one in the given below data?
 12         14         17       24       26        35         38        46          56        76
int binarySearch(const int list[], int listLength, int searchltem)
{
    int first = 0;
    int last = listLength - 1;
     int mid;
    bool found = false;
    while (first <= last && !found)                                  Write your answer in the below table:
    {
          mid = (first + last) / 2;                                   12
          if (list[mid] == searchltem)
                     found = true;                                    35
          else if (list[mid] > searchltem)
                                                                      56
                     last = mid - 1;
          else
                     first = mid + 1;
    }
    if (found)
          return mid;
    else
          return -1;
}
                                                                                                  Page 3 of 4
                                               Please turn over
                                        Continued From Overleaf
Question 4                                                                                              [10]
Design a structure named Employee. The structure should keep the following information of 100 employees in
member variables:
    •        Employee name
    •        Employee number
    •        Basic Salary
    •        Hiring year
    •        Net Pay
Write a function to calculate Net Pay of an employee on the basis of seniority. If the employee spent more than or
equal to 10 years, then he / she will get 60% bonus of the basic pay. If the employee spent more than 7 years but
less than 10 years, then he / she will get 40% bonus and 20% bonus for those who spent less than 5 years.
Hint: Net pay= Basic Pay + Bonus
                                                                                               Page 4 of 4
                                            Please turn over