You are on page 1of 8

Course Title: Programming Fundamentals

Mid Term Examination


Course Instructors :
Mahmood Siddique
Fawad Naseem
Hina Kirn
Hina Tahir
Ahmed Bilal
Semester: Spring 2014
Course Code: Percent Weight:
Duration : 90 Minutes Time:
Date : Program: BSCS
Room# : Review Date : TBA

Name: Registration Number

INSTRUCTIONS
1. Write your name and registration number on the Question Paper and Answer Sheet in
the spaces provided
2. Write with blue/black permanent ink pen
3. Avoid corrections in objective section of the exam paper
4. Try to finish your exam within prescribed time





Marks Allowed Marks Obtained



Instructor Signature



University Of Central Punjab
Faculty of Information Technology
Final Exam


X1
X1

2


Marks: 6 Time: 5 Min
Write a function that takes an integer (as a long value) as a parameter and returns the number of odd
digits in that integer.




























Question 1
X1

3

Marks: 10 Time: 10 Min
Write a C++ program which uses a 3x3 matrix A with pre-defined values as given below. Calculate the
transpose of the matrix and finally display the transpose. You may use a temporary array.
Initially your matrix should look like the following, DO NOT TAKE INPUT FROM USER:

=
3 8 4
9 7 1
6 2 5

Expected output is:

=
3 9 6
8 7 2
4 1 5

Question 2
X1

4

Marks: 6 Time: 10 Min
Write a C++ program that inputs a char array from user and toggle the case of the letters i.e. convert
all upper case letter to lower case and lower case letters to upper case.
Sample input: fUn Sample Output: FuN




















Question 3
X1

5

Marks: 10 Time: 10 Min
Write a recursive function to calculate the number of prime numbers occurring in array.































Question 4
X1

6


Marks: 10 Time: 10 Min
Write a C++ program that declares a double type array of size 20. Input the values from the user and
sort the array. Finally display the contents of the array. Use insertion sort.

Question 5
X1

7

Marks: 3
Write Down the output of the following Code.
#include<iostream> Output
#include<conio.h>
using namespace std;

void func(char[],int);
void main()
{
char arr[10]={"Character"};
char charac='c';
func(arr,charac);
getch();
}
void func(char s[],int c)
{
int i,j;

for(i=j=0;s[i]!='\0';i++)
if(s[i]!=c)
s[j++]=s[i];
s[j]='\0';

cout<<s;
}






Marks: 3
Re-Write following code after remove syntax and logical errors and write down the output if choice = 2

#include<iostream> Output
#include<conio.h>
using namespace std;

void main()
{
int choice = NULL;
cout <<"Enter your Choice: ";
cin >> choice;
switch(choice)
{
case '1';
cout << "Odd Number" << endl;
break:
case '2';
cout << "Even Number" << endl;
break:
default;
Question 6
Question 7
X1

8
cout << "Unknown Value" << endl;
break:
}

getch();
}




Marks: 3
Write Down the output of the following Code.
include<iostream> Output
#include<conio.h>
using namespace std;

void myFunc (int& x,int size)
{
for(;size>0;size--)
{
x=size;
x++;
}
}
void main()
{
int arr[5]={1,2,3,4,5};
myFunc(arr,5);
for(int i=0;i<5;i++)
cout<<arr[i]<<",";

getch();
}



Question 8

You might also like