CS201 VU Current Final Paper Spring july 2012

PAPER 1

Classes defined inside other classes are called ________ classes

► looped

        nested

       ► overloaded

       ► none of the given options.

When the compiler overloads the assignment (=) operator by default then __________

        compiler does member wise assignment.

       ► compiler does not allow default overload of assignment (=) operator

► member of the class are not assigned properly

       ► None of the given options

YA QUESTION ESKSI AUR TARHAN POCHA THA JS KA JAWAB THA MEMBER WISE ASSIGNMENT

MCQ/Q:         Copy constructor       KY BOHAT QUESTION THAY ES KI CONCEPT CLEAR   HONY CHAIN

MCQ:           stream insertion and stream extraction operators

MCQ:           Unary and binary operators

Q: 2/ 3 number ka tha

How many bytes will the pointer iPtr of type hexadecimal aur sath mai value dee hoi thee

(x—ff51) and jump to the next position and what is the address  iPtr += 4 ;

 

Which programming tool is helpful in tracing the logical errors?

Debugger

A template function must have at least ———- generic data type

       ► Zero

        One

       ► Two

       ► Three

 

  • Dynamic memory allocation ky ab kuch question thay MCQ b aur 2 number ki b

 

  • Constructor enclose the other constructor and tells the how’s destructor call

 

  • For non-member operator function, object on left side of the operator may be

        ► Object of operator class

        ► Object of different class

         Built-in data type

        ► All of the given options

 

The operator function will be implemented as _____, if obj1 drive the – operator whereas obj2 is

passed as arguments to – operator in the statement given below.

              obj3   =   obj1 –   obj2;

       Member function

      ► Non-member function

       ► Friend function

       ► None of the given options

 

 

Which one of the following is the declaration of overloaded pre-increment operator implemented as

member function?


       ► Class-name operator +() ;

        ► Class-name operator +(int) ;

        ► Class-name operator ++() ;

         Class-name operator ++(int) ;check from book please


The static data members of a class are initialized _______

       at file scope

        ► within class definition

        ► within member function

        ► within main function

 

life time of static variable?

 

 

  • Es tarhan ka question tha lakin values change thee

What will be the output of following function if we call this function by passing int 5?

template <class T>

T reciprocal(T x)

{

return (1/x);

}

Answer:-

0

The output will zero as 1/5 and its .05 but conversion to int make it

zero

Above is prototype of template class so assume passing an int and

  • Post increment and pre increment k syntax btana thay(2 marks)

Answer:

Classname operator ++(); —- pre increment

Classname operator ++(int) —- post increment

 

  • Es ka pocha tha copy constructor  or assignment

 

Matrix m1 = m2;

 

  • How many arguments a Unary Operator take? Can we make a binary operator as unary operator?

Answer:-

Unary operator takes only one arguments like i++ or i– (Post increment or post decrement operators for

integers) or ++i,–i (Pre increment or pre decrement operators for integers) ,we can not make Unary

operator as binary or binary as Unary operator.

 

  • Simple function and class function explain

 

  • 5 mark ka ak question tha

 

To calculate the tax 5%  and 7 % to deduct the salary using the switch statement

Full concept of Midterm aur ya question book mai hay kafi ziyda milta hay lakin values change thee lakin idea same tha

 

5 marks ka 2nd question 

-Class String

-Delete pointer

-New sy allocate memory

-Strcpy(s2,s1)

 

Main()

-String  s, *sptr

 

Kuch assignment ki hoi thee baki yad nahi Kai problem kahn thee aur ya likha hoa tah kai bad

programming hay ap khud program lkihoo

And program mai sy error findout kerny thay aur khud program batana tha kai consi technique

bather hhay

  • *this ponter ka pocha tha

PAPER 2

Q.1. Let we have a class,

class String

{

char buf [25];

};

Write code for assignment (=) operator function which assign one String object to other object. Your code should also avoid self assignment.

 

Q2. Write a program which uses setflag function of cout to display hexadecimal and octal representation of number.

Q3: Write a program that defines a Template function named Square () which finds the square of a number and then return it. Define one variable of type int in main function and then call Square function on that.

Program output should look like this:

Enter an integer value to find its Square: 6
Square of integer number is: 36

Q4: What is the output of following code snippet.  (2)

// class templates
#include <iostream>
using namespace std;

template <class T>
class mypair {
T a, b;
public:
mypair (T first, T second)
{a=first; b=second;}
T getmax ();
};

template <class T>
T mypair<T>::getmax ()
{
T retval;
retval = a>b? a : b;
return retval;
}
int main () {
mypair <int> myobject (100, 75);
cout myobject.getmax();
system(“pause”);
}

Q5. Write output pf the given code   (2)

a=10 b=5 c=0

a+(2*5)+c/2

 

Q6.Can we call new operator inside constructor function?

Q7. We comment our program liberally. How comment help us? Also tell is they affect the performance.

Q8. what is the source and destination of cin stream?

Q9 and Q10:

2 question thay jin mai code diya hua tha aur us ka output daina tha. Aik template wala tha aur dusara string wala.

PAPER 3:

Questions

1. Find the error in following syntax,

while(i<=100)

sum+=i*i;

 

2. General syntax of declaring and initializing the data members.

3. class String

{

char buf [25];

};

Write code for assignment (=) operator function which assign one String object to other object. Your code should also avoid self assignment.

 

4. Write a simple program, which will get a stream of character and output the stream of characters using cin and cout.
PAPER 4

40 MCQs Few Mcqs was from past papers mostly was new.

5 Qs of 2 Marks mostly code output required

5 Qs of 3 Marks                3 Qs of 5 Marks

some Qs are as under;

Q:Read the given code and explain code functionality.

Matrix :: Matrix ( const Matrix & m )
{
numRows = m.numRows ;
numCols = m.numCols ;
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 ] = m.elements [ i ] [ j ] ;
}
}

Hint : This function belong to a matrix class, having
Number of Rows = numRows
Number of Columns = numCols

Q: Write down piece of code that will declare a matrix of 3×3 using stream

Q: What is the keyword ‘this’ and what are the uses of ‘this’ pointer?

Q: Write a C++ program that contains a class ‘myClass’ having two data members of type int.

In main function of the program

1. Prompt the user to enter the number of objects to be created.
2. Dynamically allocate memory to objects according to the size entered by user.

3. De-allocate memory that was allocated to objects

Q: one code was to convert in seconds to  hr, min & sec..i dont remember exactly 

Q: new, delet operator, stream insertion, nested classes, templates nd bla bla bla 
PAPER 5

Operator overloading can be performed through__________________.

 Classes

► Function

 Operators

 Reference

 

Which of the following function is used to increase the size of already allocated memory chunk?

 malloc

 calloc

► realloc

 free

 

_______ is used to trace the logic of the program and correct the logical errors.

 Compiler

 Editor

 Linker

► Debugger

 

All preprocessor directives are started with the symbol______.

 *

 +

 @

► #

 

If text is a pointer of class String then what is meant by the following statement?

text = new String [5];

 Creates an array of 5 string objects statically

 creates an array of 5 string objects dynamically

 

The code is written to __________ the program.

► implement

 design

 analysis

 none of the given options.

 

What does (*this) represents?

 The current function of the class

 The current pointer of the class

► The current object of the class

 A value of the data member

 

new operator is used to allocate memory from the free store during

 

 Compile Time

► Run Time

 Link Time

 None of the given options

 

NULL value has been defined in ______ and _________ header files.

 strings.h and iostream.h

 ctype.h and conio.c

 conio.c and conio.h

► stdlib.h and stddef.h

 

Array is a data structure which store

► Memory addresses

 Variables

► Data Type

 Data

 

What does STL stand for?

 Source template library

► Standard template library (Page 519)

 Stream template library

 Standard temporary library

 

If overloaded plus operator is implemented as non-member function then which

of the following statement will be true for the statement given below?

obj3 = obj1 + obj2 ;

► obj2 will be passed as an argument to + operator whereas obj2 willdrive the + operator

 obj1 will drive the + operator whereas obj2 will be passed as an argument

to + operator

► Both objects (obj1, obj2) will be passed as arguments to the + operator (not sure)

 Any of the objects (obj1, obj2) can drive the + operator

 

The programs, in which we allocate static memory, run essentially on ________

 Heap

 System Cache

 None of the given options

► Stack (Page 280)

 

What should be the return type of the constructor?

 void pointer

 int

 same as object type

► constructors do not return any thing

 

In functions that return reference, use __________variables.

 Local

 Global

► Global or static (Page 369)

 None of the given option

 

What will be the output of the following statement?

cout setbase(16) 52 ;

Ø 74

Ø 52

Ø 34

  

With user-defined data type variables (Objects), self assignment can produce __________.

Ø Syntax error

Ø Logical error

Ø Link error

Ø Non of the given options

 

Or baki which statement is used to get control anywhere

I think goto

Baki programs the or sntax the

Short long totally programme

Correct error  and write a programme

Aik tha after writing a programme efficiency and or pata nai kiya of a program evaluated  write 3 technologies to do that evaluation

 

DOWNLOAD SOLUTION HERE
loading...