Sunday, July 17, 2011

Re: (VU Structure) [ vuZs.net ] CS201 Final Term Solved 5 Please check

Right should be 4th
Question No: 5      ( Marks: 1 ) - Please choose one

Which kind of functions can access private member variables of a class?

      ► Friend functions of the class  

      ► Private member functions of the class

      ► Public member functions of the class

      ► Friend, private and public functions

Rational:

By default any class function either its public or private has access to its private variable. 
Only these private members are not accessible by function of other class.

Only friend function has special privilege that it has access to any private variable of its friend class.

If we take option No.1 as correct then it will negate the very basic rule of class definition.
As we know that any variable with in the class by default is a private variable, which can be used in the public and private functions of that class freely.


Our Question does not speak about the outer classes, it  points only to function level that which kind of function can access the private variable.

I hope It will clear the concept. 




Regards

Zubair Hussain
www.vuzs.net



On Sun, Jul 17, 2011 at 8:34 AM, bc100402458 Anila Ghaffar <bc100402458@vu.edu.pk> wrote:
....[ON PAGE NUBMER "346"] ...

(THE FRIEND FUNCTIONS OF A CLASS HAVE ACCESS TO THE PRIVATE DATA
MEMBERS OF THE CLASS...)

On 7/17/11, bc100402458 Anila Ghaffar <bc100402458@vu.edu.pk> wrote:
> NO THIS IS WRONG....ONLY FRIEND FUNCTION OF A CLASS ALSO HAS ACCESS TO
> THE PVT MEMBERS OF THE CLASS....(PAGE NUMBER 374)
>
>
>
> On 7/17/11, R@ïñßøwßrïgh± <dngdng101@gmail.com> wrote:
>> Private and public members of class can also access the private member
>> variables of a class
>>
>>
>> ----- Original Message -----
>> From: "bc100402458 Anila Ghaffar" <bc100402458@vu.edu.pk>
>> To: <vu-structure@googlegroups.com>
>> Sent: Saturday, July 16, 2011 7:44 PM
>> Subject: Re: (VU Structure) [ vuZs.net ] CS201 Final Term Solved 5 Please
>> check
>>
>>
>> Question No: 5      ( Marks: 1 ) - Please choose one
>>
>> Which kind of functions can access private member variables of a class?
>>
>>        ► Friend functions of the class    (CORRECT SEE THE LECTURE NUMBER
>> 30)
>>
>>        ► Private member functions of the class
>>
>>        ► Public member functions of the class
>>
>>        ► Friend, private and public functions
>>
>>
>>
>>
>>
>> On 7/16/11, 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
>>>
>>> In if structure the block of statements is executed only,
>>>
>>>        ? When the condition is false
>>>
>>>        ? When it contain arithmetic operators
>>>
>>>        ? When it contain logical operators
>>>
>>>        ? When the condition is true
>>>
>>>
>>>
>>> Question No: 2      ( Marks: 1 ) - Please choose one
>>>
>>> Header file: fstream.h includes the definition of the stream classes
>>> __________.
>>>
>>>        ? ifstream, fstream, cout
>>>
>>>        ? ifstream, fstream, ofstream
>>>
>>>        ? fstream, cin, cout
>>>
>>>        ? None of the above
>>>
>>>
>>>
>>> Question No: 3      ( Marks: 1 ) - Please choose one
>>>
>>> To access the data members of structure _______ is used.
>>>
>>>        ? dot operator (.)
>>>
>>>        ? * operator
>>>
>>>        ?  operatorà
>>>
>>>        ? None of given.
>>>
>>>
>>>
>>> Question No: 4      ( Marks: 1 ) - Please choose one
>>>
>>> eof( ), bad( ), good( ), clear( ) all are manipulators.
>>>
>>>        ? True
>>>
>>>        ? False
>>>
>>>
>>>
>>> Question No: 5      ( Marks: 1 ) - Please choose one
>>>
>>> Which kind of functions can access private member variables of a class?
>>>
>>>        ? Friend functions of the class
>>>
>>>        ? Private member functions of the class
>>>
>>>        ? Public member functions of the class
>>>
>>>        ? Friend, private and public functions
>>>
>>>
>>>
>>> Question No: 6      ( Marks: 1 ) - Please choose one
>>>
>>> The return type of operator function must always be void.
>>>
>>>        ? True
>>>
>>>        ? False
>>>
>>>
>>>
>>> Question No: 7      ( Marks: 1 ) - Please choose one
>>>
>>> Friend function of a class is ______________ .
>>>
>>>        ? Member function
>>>
>>>        ? Non-member function
>>>
>>>        ? Private function
>>>
>>>        ? Public function
>>>
>>>
>>>
>>> Question No: 8      ( Marks: 1 ) - Please choose one
>>>
>>> Function implementation of friend function must be defined outside the
>>> class.
>>>
>>>        ? True
>>>
>>>        ? False
>>>
>>>
>>>
>>> Question No: 9      ( Marks: 1 ) - Please choose one
>>>
>>> The normal source of cin object is,
>>>
>>>        ? File
>>>
>>>        ? Disk
>>>
>>>        ? Keyboard
>>>
>>>        ? RAM
>>>
>>>
>>>
>>> Question No: 10      ( Marks: 1 ) - Please choose one
>>>
>>> Which of the following is correct way to initialize a variable x of int
>>> type
>>> with value 10?
>>>
>>>        ? int x ; x = 10;
>>>
>>>        ? int x = 10;
>>>
>>>        ? int x, x = 10;
>>>
>>>        ? x = 10;
>>>
>>>
>>>
>>> Question No: 11      ( Marks: 1 ) - Please choose one
>>>
>>> Consider the following code segment. What will be the output of the
>>> following program?
>>>
>>> int func(int) ;
>>>
>>> int num = 10 ;
>>>
>>> int main(){
>>>
>>> int num ;
>>>
>>> num = 5 ;
>>>
>>> cout << num ;
>>>
>>> cout << func(num) ;
>>>
>>> }
>>>
>>> int func(int x){
>>>
>>> return num ;
>>>
>>> }
>>>
>>>        ? 5, 5
>>>
>>>        ? 10, 5
>>>
>>>        ? 5, 10
>>>
>>>        ? 10, 10
>>>
>>>
>>>
>>> Question No: 12      ( Marks: 1 ) - Please choose one
>>>
>>> With template function, the compiler automatically detects the passed
>>> data
>>> and generates a new copy of function using passed data.
>>>
>>>        ? True
>>>
>>>        ? False
>>>
>>>
>>>
>>> Question No: 13      ( Marks: 1 ) - Please choose one
>>>
>>> What will be the correct syntax to declare two-dimensional array of
>>> float
>>> data type?
>>>
>>>        ? float arr{2}{2} ;
>>>
>>>        ? float arr[2][2] ;
>>>
>>>        ? float arr[2,2] ;
>>>
>>>        ? float[2][2] arr ;
>>>
>>>
>>>
>>> Question No: 14      ( Marks: 1 ) - Please choose one
>>>
>>> The first parameter of operator function for << operator,
>>>
>>>        ? Must be passed by value
>>>
>>>        ? Must be passed by reference
>>>
>>>        ? Can be passed by value or reference
>>>
>>>        ? Must be object of class
>>>
>>>
>>>
>>> Question No: 15      ( Marks: 1 ) - Please choose one
>>>
>>> Heap is constantly changing in size.
>>>
>>>        ? True
>>>
>>>        ? False
>>>
>>>
>>>
>>> Question No: 16      ( Marks: 1 ) - Please choose one
>>>
>>> While calling function, the arguments are assigned to the parameters
>>> from
>>>
>>>        ? left to right.
>>>
>>>        ? right to left
>>>
>>>        ? no specific order is followed
>>>
>>>        ? none of the given options.
>>>
>>>
>>>
>>> Question No: 17      ( Marks: 1 ) - Please choose one
>>>
>>> Classes defined inside other classes are called ________ classes
>>>
>>>        ? looped
>>>
>>>        ? nested
>>>
>>>        ? overloaded
>>>
>>>        ? none of the given options.
>>>
>>>
>>>
>>> Question No: 18      ( Marks: 1 ) - Please choose one
>>>
>>> If we define an identifier with the statement #define PI 3.1415926 then
>>> during the execution of the program the value of PI __________
>>>
>>>        ? can not be replace
>>>
>>>        ? None of the given options
>>>
>>>        ? Remain constant.
>>>
>>>        ? can be changed by some operation
>>>
>>>
>>>
>>> Question No: 19      ( Marks: 1 ) - Please choose one
>>>
>>> Which value is returned by the destructor of a class?
>>>
>>>        ? A pointer to the class.
>>>
>>>        ? An object of the class.
>>>
>>>        ? A status code determining whether the class was destructed
>>> correctl
>>>
>>>        ? Destructors do not return a value.
>>>
>>>
>>>
>>> Question No: 20      ( Marks: 1 ) - Please choose one
>>>
>>> Every class contains _______________.
>>>
>>>        ? Constructor
>>>
>>>        ? Destructor
>>>
>>>        ? Both a constructor and a destructor
>>>
>>>        ? None of the given options
>>>
>>>
>>>
>>> Question No: 21      ( Marks: 1 ) - Please choose one
>>>
>>> A template function must have
>>>
>>>        ? One or more than one arguments
>>>
>>>        ? Only one argument
>>>
>>>        ? Zero argument
>>>
>>>        ? None of the given options
>>>
>>>
>>>
>>> Question No: 22      ( Marks: 1 ) - Please choose one
>>>
>>> Structured Query Language is used for ______________
>>>
>>>        ? Databases Management
>>>
>>>        ? Networks
>>>
>>>        ? Writing Operating System
>>>
>>>        ? none of the given options
>>>
>>>
>>>
>>> Question No: 23      ( Marks: 1 ) - Please choose one
>>>
>>> When a call to a user-defined function finishes, the variable defined
>>> inside
>>> the function is still in existence.
>>>
>>>        ? True
>>>
>>>        ? False
>>>
>>>
>>>
>>> Question No: 24      ( Marks: 1 ) - Please choose one
>>>
>>> The precedence of an operator can be changed through operator
>>> overloading.
>>>
>>>        ? True
>>>
>>>        ? False
>>>
>>>
>>>
>>> Question No: 25      ( Marks: 1 ) - Please choose one
>>>
>>> A Matrix can be composed of ints, floats or doubles as their elements.
>>> Best
>>> way is to handle this , _______________
>>>
>>>        ? Write a separate class to handle each
>>>
>>>        ? Use templates
>>>
>>>        ? Use strings to store all types
>>>
>>>        ? None of the given options
>>>
>>>
>>>
>>> Question No: 26      ( Marks: 1 ) - Please choose one
>>>
>>> "delete" operator is used to return memory to free store, which is
>>> allocated
>>> by the "new" operator.
>>>
>>>        ? True
>>>
>>>        ? False
>>>
>>>
>>>
>>> Question No: 27      ( Marks: 2 )
>>>
>>> What is the difference between switch statement and if statement.
>>>
>>>
>>>
>>> Answer:
>>>
>>> The if statement is used to select among two alternatives. It uses a
>>> boolean
>>> expression to decide which alternative should be executed. The switch
>>> statement is used to select among multiple alternatives. It uses an int
>>> expression to determine which alternative should be executed.
>>>
>>>
>>>
>>> Question No: 28      ( Marks: 2 )
>>>
>>> How can we initialize data members of contained object at construction
>>> time?
>>>
>>>
>>>
>>> Answer:
>>>
>>> A constructor (sometimes shortened to ctor) in a class is a special type
>>> of
>>> subroutine called at the creation of an object. It prepares the new
>>> object
>>> for use, often accepting parameters which the constructor uses to set
>>> any
>>> member variables required when the object is first created.
>>>
>>>
>>>
>>> Question No: 29      ( Marks: 2 )
>>>
>>> How the data members of a class are initialized with meaningful values?
>>>
>>>
>>>
>>> Using new operator, a constructor is called
>>>
>>>
>>>
>>> Question No: 30      ( Marks: 2 )
>>>
>>> Can we overload new and delete operators?
>>>
>>>
>>>
>>> Answer:
>>>
>>>
>>>
>>> Yes, it is possible to overload new and delete operators to customize
>>> memory
>>> management. These operators can be overloaded in global (non-member)
>>> scope
>>> and in class scope as member operators
>>>
>>>
>>>
>>> Question No: 31      ( Marks: 3 )
>>>
>>> What will be the output of following functions if we call these
>>> functions
>>> three times?
>>>
>>> 1)
>>>
>>> void func1(){
>>>
>>> int x = 0;
>>>
>>> x++;
>>>
>>> cout << x << endl;
>>>
>>> }
>>>
>>> 2)
>>>
>>> void func2(){
>>>
>>> static int x = 0 ;
>>>
>>> x++;
>>>
>>> cout << x << endl ;
>>>
>>> }
>>>
>>>
>>>
>>> Question No: 32      ( Marks: 3 )
>>>
>>>  What is the keyword 'this' and what are the uses of 'this' pointer?
>>>
>>>
>>>
>>> Question No: 33      ( Marks: 3 )
>>>
>>> Suppose an object of class A is declared as data member of class B.
>>>
>>> (i) The constructor of which class will be called first?
>>>
>>> (ii) The destructor of which class will be called first?
>>>
>>>
>>>
>>> Question No: 34      ( Marks: 5 )
>>>
>>> Write the general syntax of a class that has one function as a friend of
>>> a
>>> class along with definition of friend function.
>>>
>>>
>>>
>>> Question No: 35      ( Marks: 5 )
>>>
>>> Write down the disadvantages of the templates.
>>>
>>>
>>>
>>> Question No: 36      ( Marks: 5 )
>>>
>>> Write a program which defines five variables which store the salaries of
>>> five employees, using setw and setfill manipulators to display all these
>>> salaries in a column.
>>>
>>> Note: Display all data with in a particular width and the empty space
>>> should
>>> be filled with character x
>>>
>>> Output should be displayed as given below:
>>>
>>> xxxxxx1000
>>>
>>> xxxxxx1500
>>>
>>> xxxxx20000
>>>
>>> xxxxx30000
>>>
>>> xxxxx60000
>>>
>>>
>>>
>>> --
>>> --
>>> 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
>>>
>>> --
>>> Thanks to ::: vuaskari.com :::  &  [Pak Youth]
>>>
>>
>> --
>> Thanks to ::: vuaskari.com :::  &  [Pak Youth]
>>
>> --
>> --
>> 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
>>
>> --
>> Thanks to ::: vuaskari.com :::  &  [Pak Youth]
>>
>

--
Thanks to ::: vuaskari.com :::  &  [Pak Youth]

--
--
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