0% found this document useful (0 votes)
32 views8 pages

Mid2 - ITC - F14 - DONE

This document is an exam paper for the course CS101: Introduction to Computing at the National University of Computer and Emerging Sciences, Fall 2014. It includes instructions for the exam, a breakdown of marks for each question, and a series of programming questions in C++ and Python. The exam covers topics such as code output prediction, function writing, and string manipulation.

Uploaded by

i210865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views8 pages

Mid2 - ITC - F14 - DONE

This document is an exam paper for the course CS101: Introduction to Computing at the National University of Computer and Emerging Sciences, Fall 2014. It includes instructions for the exam, a breakdown of marks for each question, and a series of programming questions in C++ and Python. The exam covers topics such as code output prediction, function writing, and string manipulation.

Uploaded by

i210865
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

National University of Computer and Emerging Sciences

School of Computing Fall 2014 Islamabad Campus

Serial No:
CS101
Sessional II
Introduction to Computing Total Time: 1 Hour
Monday, November 10, 2014 Total Marks: 75
Course Instructor
Dr. Sibt ul Hussain, Dr. Hassan Mujtaba, ________________
Ms. Uzma Marooof Signature of Invigilator

____________ ______________ ___________________ _____________________


Student Name Roll No Section Signature

DO NOT OPEN THE QUESTION BOOK OR START UNTIL INSTRUCTED.


Instructions:
1. Attempt on question paper. Attempt all of them. Read the question carefully,
understand the question, and then attempt it.
2. Please read the complete paper before attempting any question and manage your time
intelligently.
3. No additional sheet will be provided for rough work. Use the back of the last page for
rough work.
4. If you need more space write on the back side of the paper and clearly mark question
and part number etc.
5. After asked to commence the exam, please verify that you have eight (8) different
printed pages including this title page. There are total of 4 questions.
6. Use permanent ink pens only. Any part done using soft pencil will not be marked and
cannot be claimed for rechecking.
7. Use proper indentation while writing code and make sure that your code is legible.
Failing to do so can cost you marks.

Q-1 Q-2 Q-3 Q-4 Total


Marks
Obtained
Total
30 20 15 10 75
Marks

Vetted By: _____________________________Vetter Signature: _____________________

Page 1 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus

Q. No. 8.1: Please read the questions carefully and do look


for both syntax as well semantics errors.
30
(a) What is the output of the following C++ code?

int main() Output:


{

float j = 9;
float k=10;
float l= j/k *(2/4)+ 30%4; 5
int m=l + 32.0/3.0+6;
int c, d=0;
d= c + d+1 ;
cout << m <<" "<<l<<endl;
cout << c <<" "<<d<<endl;

(b) What is the output of the following python code?


Output:
def funA(str):
print ' Hello ' + str,
return str
print 'Students '

def funB(a):
print 'Hello',
c=funA(a) 5
return c + ' Students '
print c

a='xyz'
str='ITC'
z=funB(str)
print z

(c) What is the output of the following code?

Output:
int main()
{
int x=-20;
while(x)
5
{
int j=0;
while(++j < 4);
cout<<" Hello "<<endl;
if(j==4);
else
cout<<" OK ";
x+=10;
}
}

Page 2 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus

(d) What is the output of the following code?

int i=-5,j=0; Output:

for(i; i ;)
{
j=0; 5
for (j; j < 5; ++j);
cout<< " * ";
cout<<endl;
i++;
}

(e) What is the output of the following code?

int i=-5,j=0; Output:


5
for(i; i ;)
{
j=0;
for (j=0; j < 5; ++j)
cout<< " * ";
cout<<endl;
i++;
}

(f) What is the output of the following code?

int i=1,j=1,k=1; Output:


while (i <= 2) { 5
j=1;
while (j <= 3) {
k=2;
while(k <= 4)
{
cout<<("*");
k++;
}

cout<<("!");
j++;
}
cout<<endl;
i++;
}

Page 3 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus

Q. No. 2
20
a) Write a Python function named minGap that accepts an integer list as a
parameter and returns the minimum 'gap' between adjacent values in the list. The gap
between two adjacent values in a list is defined as the second value minus the first value.

For example, suppose a variable called train is a list of integers that stores the following
sequence of values:
10
train = [1, 3, 6, 7, 12]

The first gap is 2 (3 - 1), the second gap is 3 (6 - 3), the third gap is 1 (7 - 6) and the fourth
gap is 5 (12 - 7). Thus, the call of minGap(train) should return 1 because that is the
smallest gap in the array. If you are passed a list with fewer than 2 elements, you should
return -1.

Page 4 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus
b) Write a program (C++ or Python) that displays the following output on screen:

10

Page 5 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus

Q. No. 3

Write a C++ program that accepts two integer inputs rows and cols and 15
outputs a comma separated grid of numbers where the first input (rows)
represents the number of rows of the grid and the second input (cols)
represents the number of columns. The numbers count up from 1 to (rows X cols).

Input: Rows=3, Cols=6 Rows=5, Cols=3 Rows=4, Cols=1 Rows=1, Cols=3

Page 6 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus

Q. No. 4

Suppose you are given two strings (they may be empty), s1 and s2. You 10
would like to "lace" these strings together, by successively alternating
elements of each string (starting with the first character of s1). If one string is
longer than the other, then the remaining elements of the longer string should simply be
added at the end of the new string. For example, if we lace 'abcd' and 'efghi', we would
get the new string: 'aebfcgdhi'

def laceStrings(s1, s2):


"""
s1 and s2 are strings.

Returns a new str with elements of s1 and s2 interlaced,


beginning with s1. If strings are not of same length,
then the extra elements should appear at the end.
Draw a Smiley on the top of front page to gain two bonus
marks

"""
# Your Code Here

Page 7 of 8
National University of Computer and Emerging Sciences
School of Computing Fall 2014 Islamabad Campus

Page 8 of 8

You might also like