# CS201 Introduction to Programming Final Paper March 2014

Total MCQ = 40 Each of 1 marks
Total Short Questions = 4 Each of 2 marks
Total Short Questions = 4 Each of 3 marks
Total Long Questions = 4 Each of 5 marks

Q41: What will be the output of following code snippet? (2 Marks)

Q42: Write down the general syntax for unary operator function? (2 Marks)

Q43: Why it is meaningless to declare a static variable inside main () function? (2 Marks)

Q44: Read the given code and explain the code functionality? (2 Marks)

Matrix :: Matrix ( int row , int col )

{

numRows = row ;

numCols = col ;

elements = new ( double * ) [ numRows ] ;

for ( int i = 0 ; i < numRows ; i ++ )

{

elements [ i ] = new double [ numCols ] ;

for ( int j = 0 ; j < numCols ; j ++ )

elements [ i ] [ j ] = 0.0 ;

}

}

Hint : This function belong to a matrix class, having

Number of Rows = numRows

Number of Columns = numCols

Q45: Write equivalent template function for the given function? (3 Marks)

Float Celsius (float Fahrenheit)

{

Float Celsius = 0.0;

Celsius = ((Fahrenheit – 32)*5/9;

Return Celsius

}

Q46: Which one of the given two methods is better to read from a file and why? (3 Marks)

Using stream insertion operator>>
Using get() function

Q47: Identify the errors in following member operator function and also correct them? (3 Marks)

math * operator (math m)

{

math temp;

temp.number= number * number;.2

return number;

Q48: Which one (copy constructor or assignment constructor) will be called in each of the following code segment? (3 Marks)

1) Matrix m1 (m2);

2) Matrix m1, m2;

m1 = m2;

3) Matrix m1 = m2;

Q49: Write a program using do-while loop to compute and display the product of all integers from 1 to 10? (5 Marks)

Q50: Write the main function in which you have to add three integer elements in template class queue, and then call print function. After that, remove two elements from the queue. (5 Marks)

Iss ke baad ik lengthy program or code likha hoa tha due to shortage of time I can’t wrote it.

Q51: Given is the code of Date Class. (5 Marks)

Class Date

{

Private:

Int Day;

Int month;

Int year;

Public:

Date ()

{

Day = 01;

Month = 01;

Year = 2000;

}

};

Write the code for a class person which contain three data number name, and DOB, where Name and Address are char pointer while DOB (Date of Birth) is an object of type Date. This class should also contain a default constructor to initialize all its data members using same default values.

Q52: Suppose an object has a pointer type as its data member. (5 Marks)

What happen when we assign that object using default assignment operator?
What happen if we use delete one object in the above mentioned situation?