Thursday, July 14, 2011

Re: [ vuZs.net ] CS201 Final Term Solved 1 Please check

Your all the MCQs are correct. I have different view on MCQ No.21

to me its answer should be 3rd option (Both a constructor and a destructor)


Almost same rules applicable on destructor which are meant for constructors.


A class can include a special function called constructor, which is automatically called whenever a new object of this class is created. This constructor function must have the same name as the class, and cannot have any return type; not even void.


The destructor fulfills the opposite functionality. It is automatically called when an object is destroyed, either because its scope of existence has finished (for example, if it was defined as a local object within a function and the function ends) or because it is an object dynamically assigned and it is released using the operator delete.



Question No: 21      ( Marks: 1 ) - Please choose one

 Every class contains _______________.

       ► Constructor

       ► Destructor

       ► Both a constructor and a destructor

       ► None of the given options



Regards

Zubair Hussain
www.vuzs.net



On Thu, Jul 14, 2011 at 10:36 AM, R@ïñßøwßrïgh± <dngdng101@gmail.com> wrote:

FINALTERM  EXAMINATION

Spring 2010

CS201- Introduction to Programming

Marks: 58

Question No: 1      ( Marks: 1 ) - Please choose one

*.doc is _____________ by type.

.

       Sequential File

       Random Access File

       Data File

       Record File

 

Question No: 2      ( Marks: 1 ) - Please choose one

Which of the following is NOT a preprocessor directive?

       #error

       #define

       #line

       #ndefine

Question No: 3      ( Marks: 1 ) - Please choose one

The return type of operator function must always be void.

       True

       False

 

Question No: 4      ( Marks: 1 ) - Please choose one

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

 

Question No: 5      ( Marks: 1 ) - Please choose one

The statement cin.get (); is used to,

       Read a string from keyboard

       Read a character from keyboard

       Read a string from file

       Read a character from file

 

Question No: 6      ( Marks: 1 ) - Please choose one

 When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a destructor.

       True

       False

 

Question No: 7      ( Marks: 1 ) - Please choose one

 Overloaded new operator function takes parameter of type size_t and returns

       void (nothing)

       void pointer

       object pointer

       int pointer

 

Question No: 8      ( Marks: 1 ) - Please choose one

The second parameter of operator functions for << and >> are objects of the class for which we are overloading these operators.

       True

       False

 

Question No: 9      ( Marks: 1 ) - Please choose one

 C++ is a case-sensitive language

       True

       False

 

Question No: 10      ( Marks: 1 ) - Please choose one

 To include code from the library in the program, such as iostream, a directive would be called up using this command.

       #include "iostream.h"

       include

       include

       #include

 

Question No: 11      ( Marks: 1 ) - Please choose one

 A template function must have only generic data types.

       True

       False

 

Question No: 12      ( Marks: 1 ) - Please choose one

 Template class can not have static variables.

       True

       False

 

Question No: 13      ( Marks: 1 ) - Please choose one

What will be the correct syntax to assign an array named arr of 5 elements to a pointer ptr?

       *ptr = arr ; 

       ptr = arr ;

       *ptr = arr[5] ;

       ptr = arr[5] ; 

 

Question No: 14      ( Marks: 1 ) - Please choose one

What will be the correct syntax to access the value of fourth element of an array using pointer ptr?

       ptr[3]

       (ptr+3)

       *(ptr+3)

       Both 1and 3

 

Question No: 15      ( Marks: 1 ) - Please choose one

 If most significant bit of un-signed number is 1 then it represents a positive number.

       True

       False

 

Question No: 16      ( Marks: 1 ) - Please choose one

 If there is a symbol (& sign) used with the variable name followed by data type then it refers to _____ and if & is being used with variable name then it refers to _____.

       Address of variable, reference variable

       Reference variable, value of variable

       Reference variable, address of variable

       Address of variable, value of variable

 

Question No: 17      ( Marks: 1 ) - Please choose one

 We can also do conditional compilation with preprocessor directives.

       True

       False

 

Question No: 18      ( Marks: 1 ) - Please choose one

 The default value of a parameter can be provided inside the ________________

       function prototype

       function definition

       both function prototype or function definition

       none of the given options.

 

Question No: 19      ( Marks: 1 ) - Please choose one

 Classes defined inside other classes are called ________ classes

       looped

       nested

       overloaded

       none of the given options.

 

Question No: 20      ( Marks: 1 ) - Please choose one

 What purpose do classes serve?

       Data encapsulation

       Providing a convenient way of modeling real-world objects

       Simplifying code reuse

       All of the given options

 

Question No: 21      ( Marks: 1 ) - Please choose one

 Every class contains _______________.

       Constructor

       Destructor

       Both a constructor and a destructor

       None of the given options

 

Question No: 22      ( Marks: 1 ) - Please choose one

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

       Compile Time

       Run Time

       Link Time

       None of the given options

 

Question No: 23      ( Marks: 1 ) - Please choose one

 When an object of a class is defined inside another class then,

       Destructor of enclosing class will be called first

       Destructor of inner object will be called first

       Constructor and Destructor will be called simultaneously

       None of the given options

 

Question No: 24      ( Marks: 1 ) - Please choose one

 It is possible to define a class within another class.

       True

       False

 

Question No: 25      ( Marks: 1 ) - Please choose one

 New and Delete are also used with ___________ and data types as well.

       Class, Objects @@@@

       Structures, Pointers

       Both Class and structures @@@@

       None of above

 

Question No: 26      ( Marks: 1 ) - Please choose one

 With New keyword, data types and class members are initialized with meaningful values instead of garbage.

 

       True

       False

 

Question No: 27      ( Marks: 2 )

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

 

Question No: 28      ( Marks: 2 )

 Which arithmetic operators cannot have a floating point operand?

 

Question No: 29      ( Marks: 2 )

 What are manipulators? Give one example.

 

Question No: 30      ( Marks: 2 )

 Write down piece of code that will declare a matrix of 3x3. And initialize all its locations with 0;

 

int m[3][3]={0};

 

Question No: 31      ( Marks: 3 )

 Which one (copy constructor or assignment operator) will be called in each of the following code segment?

1) Matrix m1 (m2);

2) Matrix m1, m2;

m1 = m2;

3) Matrix m1 = m2;

 

Question No: 32      ( Marks: 3 )

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

template T reciprocal(T x) {return (1/x); }

 

Question No: 33      ( Marks: 3 )

 Identify the errors in the following member operator function and also correct them.

math * operator(math m);

math * operator (math m)

{

     math temp;

     temp.number= number * number;

     return number;

   

}

 

Answer

 

math operator *(math );

math math :: operator * ( math m)

{

    math temp;

    temp.number = number * m.number;

    return temp;  

}

 

Question No: 34      ( Marks: 5 )

 Write a program which defines three variables of type double which store three different values including decimal points, using setprecision manipulators to print all these values with different number of digits after the decimal number.

 

Answer

 

#include<iostream.h>

#include<iomanip.h>

main()

{

            double first=0.223, second=2223.1, third=4423323.6664;

            cout << setprecision(2) << first <<endl;

            cout << setprecision(6) << second <<endl;

            cout << setprecision(7) << third <<endl;

            system("pause");

}

 

Question No: 35      ( Marks: 5 )

 What are the advantages and disadvantages of using templates?

 

Answer

 

Advanatages:

         Templates are easier to write than writing several versions of your similar code for different types. You create only one generic version of your class or function instead of manually creating specializations.

         Templates are type-safe. This is because the types that templates act upon are known at compile time, so the compiler can perform type checking before errors occur.

         Templates can be easier to understand, since they can provide a straightforward way of abstracting type information.

         It help in utilizing compiler optimizations to the extreme. Then of course there is room for misuse of the templates. On one hand they provide an excellent mechanism to create specific type-safe classes from a generic definition with little overhead.

Disadvantages:

On the other hand, if misused

         Templates can make code difficult to read and follow depending upon coding style.

         They can present seriously confusing syntactical problems esp. when the code is large and spread over several header and source files.

         Then, there are times, when templates can "excellently" produce nearly meaningless compiler errors thus requiring extra care to enforce syntactical and other design constraints. A common mistake is the angle bracket problem.

 

 

Question No: 36      ( Marks: 5 )

 Suppose a program has a math class having only one data member number.

Write the declaration and definition of operator function to overload + operator for the statements of main function.

         math obj1, obj2;

         obj2= 10 + obj1  ;  

 

#include <iostream.h>

class math

{

            private:

                       

            public:

                        int number;

                        math()

                        {

                                    number=0;

                        }

                        friend math operator + (int, math);

};

math operator + (int a , math m)

{

            math temp;

            temp.number = a + m.number;

            return temp;

}

main()

{

            math m,n;

            m.number=100;

            n= 10 + m;

            cout << n.number;

            system("pause");

}

 

--
--
Please visit www.vuzs.net For Current & Old Papers, Quizzes, Assignments and study material.
--
You received this message because you are subscribed to the Google
Groups "vuZs" group.
--
To post a new message on this group, send email to vuZs@googlegroups.com
--
Message Posting Rules: http://vuzs.net/faq/4795-vuzs-google-groups-basic-rules-for-posting-messages.html
--
To unsubscribe from this group, send email to vuZs+unsubscribe@googlegroups.com
--
To join this group Send blank email from your virtual university email address to
vuZs+subscribe@googlegroups.com
or visit
http://groups.google.com/group/vuZs/subscribe
---
For more information Contact vuZs Manager at info@vuzs.net

--
--
Please visit www.vuzs.net For Current & Old Papers, Quizzes, Assignments and study material.
--
You received this message because you are subscribed to the Google
Groups "vuZs" group.
--
To post a new message on this group, send email to vuZs@googlegroups.com
--
Message Posting Rules: http://vuzs.net/faq/4795-vuzs-google-groups-basic-rules-for-posting-messages.html
--
To unsubscribe from this group, send email to vuZs+unsubscribe@googlegroups.com
--
To join this group Send blank email from your virtual university email address to
vuZs+subscribe@googlegroups.com
or visit
http://groups.google.com/group/vuZs/subscribe
---
For more information Contact vuZs Manager at info@vuzs.net

No comments:

Post a Comment