Sponsored Links


Results 1 to 4 of 4

Thread: cs201 Introduction to Programming final term solve paper January 2012

  1. #1
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578

    18 cs201 Introduction to Programming final term solve paper January 2012

    Sponsored Links1


    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

    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)





    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?

    Ans: Unary operator takes only one aurgument like i++ or i— (Post increment or post decrement operators for intergers) or ++i,--i (Pre increment or pre decrement operators for intergers) ,we can not make Unary operator as binary or binary as Unary operator.

    Question No: 28 ( Marks: 2 )

    Which arithmetic operators cannot have a floating point operand?

    Ans:

    Modulus operator

    This operator can only be used with integer operands ONLY

    Question No: 29 ( Marks: 2 )

    What are manipulators? Give one example.

    Ans:

    The manipulators are like something that can be inserted into stream, effecting a change in the behavior. For example, if we have a floating point number, say pi (л), and have written it as float pi = 3.1415926 ; Now there is need of printing the value of pi up to two decimal places i.e. 3.14 . This is a formatting functionality. For this, we have a manipulator that tells about width and number of decimal points of a number being printed.

    Some manipulators are parameter less. We simply use the name of the manipulator that works. For example, we have been using endl, which is actually a manipulator, not data. When we write cout endl ; a new line is output besides flushing the buffer.

    Actually, it manipulates the output stream.

    Question No: 30 ( Marks: 2 )

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

    Ans:

    int matrix [3] [3] ;

    matrix [0] [0] = 0;

    matrix [0] [1] = 0;

    matrix [0] [2] = 0;

    matrix [1] [0] = 0;

    matrix [1] [2] = 0;

    matrix [1] [2] = 0;

    matrix [2] [0] = 0;

    matrix [2] [1] = 0;

    matrix [2] [2] = 0;

    we can also do it as given below

    int matrix [3][3] = { 0 }; //all elements 0

    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;

    Ans:

    1) Matrix m1 (m2); copy constructor

    2) Matrix m1, m2;

    m1 = m2; assignment operator

    3) Matrix m1 = m2; assignment operator

    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); }

    Ans:

    1/5

    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;



    }

    ANS:

    The errors are in the arguments of the member operation function and also in the body of operator member function.

    Correct function should be

    math *operator(math *m);

    math *operator (math *m)

    {

    math temp;

    temp = m;

    temp.number= number * number;

    return temp.number;



    }

    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.

    Ans:

    #include

    #include

    int main ()

    {

    double x1 = 12345624.72345

    double x2 = 987654.12345

    double x3 = 1985.23456

    cout setprecision (3) x1 endl;

    cout setprecision (4) x2 endl;

    cout setprecision (5) x3 endl;

    return 0;

    }

    Question No: 35 ( Marks: 5 )

    What are the advantages and disadvantages of using templates?

    Ans:

    Many thing can be possible without using templates but it do offer several clear advantages not offered by any other techniques:

    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 ;

    Ans:

    #include

    math

    {

    mth operator + (obj1,obj2)

    mth operator + (obj1,obj2)

    {

    mth operator + (obj1,obj2)

    mth operator + (obj1,obj2)

    }

    }

    ……………………………………………………………………………



    FINALTERM EXAMINATION





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

    There are mainly -------------------- types of software

    ► Two

    ► Three

    ► Four

    ► Five

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

    seekg() and write() are functionally _________________ .

    ► Different

    ► Identical

    ► Two names of same function

    ► None of the above

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

    When a pointer is incremented, it actually jumps the number of memory addresses

    ► According to data type

    ► 1 byte exactly

    ► 1 bit exactly

    ► A pointer variable can not be incremented

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

    setw is a parameterized manipulator.

    ► True

    ► False

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

    eof( ), bad( ), good( ), clear( ) all are manipulators.

    ► True

    ► False

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

    In functions that return reference, use __________variables.

    ► Local

    ► Global

    ► Global or static

    ► None of the given option

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

    The declarator of Plus (+) member operator function is

    ► Class-Name operator + (Class-Name rhs)

    ► operator Class-Name + ( )

    ► operator Class-Name + ( rhs)

    ► Class-Name operator + ( )

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

    The compiler does not provide a copy constructor if we do not provide it.

    ► True

    ► False


  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    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 (any where in the class)

    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; ADEEL ABBAs

    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

    ADEEL ABBAs

    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

    A Matrix can be composed of ints, floats or doubles as their elements. Instead of handling these data types separately, we can write Matrix class as a template class and write code once for all native data types.

    Write Matrix class as a template class and write code once for all native data types

    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.

    Question No: 28 ( Marks: 2 )

    How can we initialize data members of contained object at construction time?

    Question No: 29 ( Marks: 2 )

    How the data members of a class are initialized with meaningful values?

    Question No: 30 ( Marks: 2 )

    Can we overload new and delete 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



  3. #3
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    FINALTERM EXAMINATION

    CS201 - Introduction to programming

    Final Term Spring 2010



    Operator overloading can be performed through__________________.

    ► Classes

    ► Functions

    ► Operators

    ► Reference



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

    When a value is referred by a normal variable then it is known as,

    ► Direct Reference

    ► Indirect Reference

    ► Partial Reference

    ► Proper Reference

    When a value is referred by a normal variable is known as direct reference

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

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



    ► malloc

    ► calloc

    ► realloc

    ► free

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

    Which of the following is NOT a preprocessor directive?

    ► #error

    ► #define

    ► #line

    ► #ndefine



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

    The stream objects cin and cout are included in which header file?

    ► iostream.h

    ► fstream.h

    ► istream.h

    ► ostream.h

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

    Overloaded delete operator function takes the same parameter as an argument returned by new operator function.

    ► True

    ► False



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

    When an array of object is created dynamically then there is no way to provide parameterized constructors for array of objects.

    ► True

    ► False



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

    C is widely known as development language of _______ operating system.

    ► Linux

    ► Windows

    ► Unix

    ► Mac OS

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

    Computer can understand only machine language code.

    ► True



    ► False

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

    We can not define a function as a friend of a Template class.

    ► True

    ► False



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

    What will be the value of ‘a’ and ‘b’ after executing the following statements?

    a = 3;

    b = a++;

    ► 3, 4

    ► 4, 4

    ► 3, 3

    ► 4, 3

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

    Consider the following code segment. What will be the output of following code?

    int addValue (int *a){

    int b = (*a) + 2;

    return b ;

    }

    main () {

    int x =6 ;

    cout x “,” ;

    cout addValue(&x) “,” ;

    cout x ;

    }

    ► 6,8,6

    ► 6,6,8

    ► 6,8,8

    ► 6,6,6



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

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

    ► Compiler

    ► Editor

    ► Linker

    ► Debugger



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

    new and delete are _____ whereas malloc and free are _____.

    ► Functions, operators

    ► Classes, operators

    ► Operators, functions

    ► Operators, classes



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

    Like member functions, ______ can also access the private data members of a class.

    ► Non-member functions

    ► Friend functions

    ► Any function outside class

    ► None of the given options

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

    Which situation would require the use of a non-member overloaded operator?

    ► The overloaded operator is an Assignment operator.

    ► The left most operand is an object of a class.

    ► The left operand is built-in data type.

    ► The operator returns a reference.


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

    The stream insertion and stream extraction operators are already overloaded for ______.

    ► User-defined data types

    ► Built-in data types

    ► User-defined and built-in data types

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

    ► None of the given options

    ► Remain constant.

    ► can be changed by some operation



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

    Assignment operator is -------------------------associative.

    ► right

    ► left

    ► binary

    ► unary



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

    When ever dynamic memory allocation is made in C/C++, it is freed_____________.

    ► Explicitly

    ► Implicitly

    ► Both explicitly and implicitly

    ► None of the given options

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

    The appropriate data type to store the number of rows and colums of the matrix is____________.

    ► float

    ► int

    ► char

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

    Which of the following function do NOT initialize the chunk of memory to all zero?

    ► calloc() function

    ► Both malloc() and calloc()

    ► None of the above

    ► malloc() function



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

    The function free() returns back the allocated memory got thorough calloc and malloc to _____ .

    ► stack

    ► heap

    ► stack and heap

    ► None of the given options



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

    width() is member function of _____________

    ► cin object

    ► cout object

    ► Both cin and cout object

    ► None of the given option





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

    Templates are not type safe.

    ► true

    ► false

    Question No: 26 ( 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: 27 ( Marks: 2 )

    Give the general syntax of class template.

    template

    class myclass { ---} ;

    Question No: 28 ( Marks: 2 )

    What is a truth Table?

    There are some areas where the decision structures become very complicated. Sometimes, we find it difficult to evaluate a complicated logical expression. Sometimes the logic becomes extremely complicated so that even writing it as a simple syntax statement in any language. It becomes complicated to determine what will be evaluated in what way. We know the concept of truth table. The truth tables are very important. These are still a tool available for analyzing logical expressions. We will read logic design in future, which is actually to do with chips and gates. How we put these things together.

    Question No: 29 ( Marks: 2 )



    What will be the output of following code, if user input a number 123?

    int input ;

    cin >> oct >> input;

    cout hex input ;



    53

    Rational: it will take 123 as octal and print it in hex form which is 53.



    Question No: 30 ( Marks: 2 )

    What is principle of friendship in the context of functions and classes?

    Class can declare a friend function and someone from outside the class cannot declare itself friend of a class.

    A friend function can access the private variables of class just like a member function



    Question No: 31 ( Marks: 3 )

    What are the limitations of the friendship relation between classes?

    Class can declare a friend class from inside and someone from outside the class cannot declare itself friend of a class.



    Question No: 32 ( 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? a

    (ii) The destructor of which class will be called first?b



    Question No: 33 ( Marks: 3 )

    Define static variable. Also explain life time of static variable?

    When you declare a static variable (native data type or object) inside a function, it is created and initialized only once during the lifetime of the program



    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.

    #include

    #include

    main () {

    double a = 12.12345;

    double b = 13.123456;

    double c = 14.1234567;

    cout setprecision (5) a endl;

    cout setprecision (2) a endl;

    cout setprecision (3) a endl;

    }

    Question No: 35 ( Marks: 5 )

    Let we have a class,

    class String

    {

    private:

    char buf[25];

    };

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



    Answer:

    void String:perator = ( const String &other )

    { int length ;

    length = other.length();

    delete buf;

    buf = new char [length + 1];

    strcpy( buf, other.buf ); }



    Question No: 36 ( Marks: 5 )

    Read the given below code and explain what task is being performed by this function

    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



  4. #4
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    FINALTERM EXAMINATION

    Fall 2008

    CS201- Introduction to Programming

    Time: 120 min Marks: 75



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

    There are mainly -------------------- types of software

    ► Two

    ► Three

    ► Four

    ► Five

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

    seekg() and write() are functionally _________________ .

    ► Different

    ► Identical

    ► Two names of same function

    ► None of the above

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

    When a pointer is incremented, it actually jumps the number of memory addresses

    ► According to data type

    ► 1 byte exactly

    ► 1 bit exactly

    ► A pointer variable can not be incremented

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

    setw is a parameterized manipulator.

    ► True

    ► False

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

    eof( ), bad( ), good( ), clear( ) all are manipulators.

    ► True

    ► False

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

    In functions that return reference, use __________variables.

    ► Local

    ► Global

    ► Global or static

    ► None of the given option

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

    The declarator of Plus (+) member operator function is

    ► Class-Name operator + (Class-Name rhs)

    ► operator Class-Name + ( )

    ► operator Class-Name + ( rhs)

    ► Class-Name operator + ( )

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

    The compiler does not provide a copy constructor if we do not provide it.

    ► True

    ► False


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

    What is the functionality of the following syntax to delete an array of 5 objects named arr allocated using new operator?

    delete arr ;

    ► Deletes all the objects of array

    ► Deletes one object of array

    ► Do not delete any object

    ► Results into syntax error

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

    What is the sequence of event(s) when allocating memory using new operator?

    ► Only block of memory is allocated for objects

    ► Only constructor is called for objects

    ► Memory is allocated first before calling constructor

    ► Constructor is called first before allocating memory

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

    What is the sequence of event(s) when deallocating memory using delete operator?

    ► Only block of memory is deallocated for objects

    ► Only destructor is called for objects

    ► Memory is deallocated first before calling destructor

    ► Destructor is called first before deallocating memory

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

    new and delete operators cannot be overloaded as member functions.

    ► True

    ► False

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

    The operator function of and >> operators are always the member function of a class.

    ► True

    ► False

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

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

    ► Zero

    ► One

    ► Two

    ► Three

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

    If we do not mention any return_value_type with a function, it will return an _____ value.

    ► int

    ► void

    ► double

    ► float

    Such function which do not return any value are called:

    ► int

    ► void

    ► double

    ► float


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

    Suppose a program contains an array declared as int arr[100]; what will be the size of array?

    ► 0

    ► 99

    ► 100

    ► 101

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

    The name of an array represents address of first location of array element.

    ► True

    ► False

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

    Reusing the variables in program helps to save the memory

    ► True

    ► False

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

    Which of the following option is true about new operator to dynamically allocate memory to an object?

    ► The new operator determines the size of an object

    ► Allocates memory to object and returns pointer of valid type

    ► Creates an object and calls the constructor to initialize the object

    ► All of the given options

    Sponsored Links

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

    new and delete are _____ whereas malloc and free are _____.

    ► Functions, operators

    ► Classes, operators

    ► Operators, functions

    ► Operators, classes

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

    Like member functions, ______ can also access the private data members of a class.

    ► Non-member functions

    ► Friend functions

    ► Any function outside class

    ► None of the given options

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

    Which of the following statement is best regarding declaration of friend function?

    ► Friend function must be declared after public keyword.

    ► Friend function must be declared after private keyword.

    ► Friend function must be declared at the top within class definition.

    ► It can be declared anywhere in class as these are not affected by the public and private keywords.

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

    The operator function overloaded for an Assignment operator (=) must be

    ► Non-member function of class

    ► Member function of class

    ► Friend function of class

    ► None of the given options


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

    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

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

    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

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

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

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

    The static data members of a class are initialized _______

    ► at file scope

    ► within class definition

    ► within member function

    ► within main function

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

    Class is a user defined___________.

    ► data type

    ► memory referee

    ► value

    ► none of the given options.

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

    We can also define a user-defines manipulators.

    ► True

    ► False

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

    Automatic variable are created on ________.

    ► Heap

    ► Free store

    ► static storage

    ► stack

    Question No: 31 ( Marks: 1 )

    How do we provide the default values of function parameters?



    Answer: The default value of a parameter is provided inside the function prototype or function definition. For example, we could declare the default function arguments for a function while declaring or defining it.



    Question No: 32 ( Marks: 1 )

    Why do java consider pointer as dangerous

    Answer:

    The concept of pointers is very important but quite limited to C and C++. The modern languages, for example JAVA, describe pointers as dangerous. We can go anywhere in the memory and can change a value. There is another problem with pointers, which is that these could be pointing to nowhere.



    Question No: 33 ( Marks: 2 )

    What is memory leak?

    Answer: size. When there is no memory on heap, the computer will stop running and there may be a system crash. This situation is called a memory leak.



    Question No: 34 ( Marks: 2 )

    What does optimization the of code means?

    Answer:

    Header file is a nice mechanism to put function prototypes and define constants (global constants) in a single file. That file can be included simply with a single line of code.



    Question No: 35 ( Marks: 3 )

    What is the difference between structure and class?
    Answer:

    In structures, some data variables are gathered, grouped and named as a single entity. Class and structure are very closely related. In classes, we group some data variables and functions. These functions normally manipulate these variables. Before going ahead, it is better to understand what a class is: “A class includes both data members as well as functions to manipulate that data”



    Question No: 36 ( Marks: 3 )

    See the following code segment.

    template <class T>

    class myclass {

    private:

    T x;

    public:

    myclass (T a) {

    x = a;

    }

    };

    Write the main function which creates two objects of class for int and double data types.

    Question No: 37 ( Marks: 3 )

    Is it possible to define two functions as given below? Justify your answer.

    func(int x, int y)

    func(int &x, int &y)

    Solution:

    No, it is impossible to define two functions as in the main function the way to call both functions is same. How does the compiler know that which functions is being called? There is no way for the compiler to find out. Therefore there is an ambiguity and that is not allowed. The only thing to realize is the side effect. Side effects are critical to take care of whenever you are doing call by reference.



    Question No: 38 ( Marks: 5 )

    Write a program using getline() member function to inputs a string up to delimiter character comma (,) and then display the string on the screen.

    Question No: 39 ( Marks: 5 )



    Do you think that friend functions violate encapsulation? Justify your answer.

    Answer:

    The friend functions of a class have access to the private data members of class. Despite being a good thing, there is possibility of vulnerability. We are opening our thoughts, inside view for somebody else. Without having 100% trust, it will be risky to make our thoughts and feelings public. We want that our private data is accessible to someone outside, not public for everybody. Otherwise, the data encapsulation and data-hiding concept will be violated. We keep the data members private and declare some specific functions that are not member of the class but friend of the class. As friends, they have access to the inside data structure of the class despite not being members.



    Question No: 40 (Marks: 10 )





    Write a simple program using the get() member function of cin object reading a text of 30 characters from the keyboard, store them in an array and then using put() member function of cout object to display them on the screen.



    Question No: 41 (Marks: 10 )





    Write a small program which defines two user-defined manipulators named octal and hexadecimal. These manipulators should display the decimal numbers into octal and hexadecimal.

    In the main function, input a decimal number from the user and then display this decimal number into octal and hexadecimal using user-define manipulators named octal and hexadecimal.



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 06-14-2012, 05:00 PM
  2. Replies: 0
    Last Post: 02-03-2012, 07:15 PM
  3. Replies: 0
    Last Post: 01-15-2012, 09:18 PM
  4. Replies: 0
    Last Post: 07-09-2011, 09:40 PM
  5. Replies: 0
    Last Post: 08-16-2010, 05:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft