We are Permanently Move to www.VUpk.net Please Join us there.
Showing posts with label CS201. Show all posts
Showing posts with label CS201. Show all posts

CS201 Assignments Spring 2012

Sunday, 12 August 2012

CS201 Final Term Solved Subjective by Moaaz

Saturday, 4 August 2012
Attachments:
Download this file (CS201-Finalterm-subjective-solved-by-moaaz.pdf)CS201-Finalterm-solved-subjective[ ]492 Kb

Solved by Moaaz Siddiq










CS201 Final Term Solved MCQs by Moaaz & Asad

Attachment:
Download this file (CS201-finalterm-solved-mcqs-with-ref-by-Moaaz-and-Asad.pdf)CS201-finalterm-solved-mcqs[ ]2151 Kb

Solved by Moaaz Siddiq & Asad Ali

CS201 Final Term paper Solved 2009 - 6

FINALTERM  EXAMINATION
Fall 2009
CS201- Introduction to Programming
Time: 120 min
M a r k s: 75
 
Question No: 1      ( M a r k s: 1 ) http://vuzs.net
 In C/C++ if we define an array of size eight (8) i.e. int Arr [8]; then the last element of this array will be stored at,
 
       ► Arr[0]
       ► Arr[8]
       ► Arr[7]
       ► Arr[-1]
 
Question No: 2      ( M a r k s: 1 ) http://vuzs.net
 When an array is passed to a function then default way of passing this array is,
 
       ► By data
       ► By reference
       ► By value
       ► By data type
 
Question No: 3      ( M a r k s: 1 ) http://vuzs.net
 Array is a data structure which store
 
      ► Memory addresses
      ► Variables
      ► Data Type
      ► Data
 
Question No: 4      ( M a r k s: 1 ) http://vuzs.net
 We can also create an array of user define data type.
 
       ► True
       ► False
 
Question No: 5      ( M a r k s: 1 ) http://vuzs.net
When we define an array of objects then,
 
       ► Destructor will call once for whole array
       ► Destructor will call for each object of the array
       ► Destructor will never call
       ► Depends on the size of array
 
Question No: 6      ( M a r k s: 1 ) http://vuzs.net
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: 7      ( M a r k s: 1 ) http://vuzs.net
We can delete an array of objects without specifying [] brackets if a class is not doing dynamic memory allocation internally.
 
       ► True
       ► False
 
Question No: 8      ( M a r k s: 1 ) http://vuzs.net
The second parameter of operator functions for are objects of the class for which we are overloading these operators.
 
       ► True
       ► False
 
Question No: 9      ( M a r k s: 1 ) http://vuzs.net
 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: 10      ( M a r k s: 1 ) http://vuzs.net
 Default mechanism of function calling in case of array is _____ and in case of variable is ___.
 
       ► Call by value, call by reference
       ► Call by referene, call by reference
       ► Call by reference, call by value
       ► Call by value, call by value
 
Question No: 11      ( M a r k s: 1 ) http://vuzs.net
 What does STL stand for?
 
       ► Source template library
       ► Standard template library
       ► Stream template library
       ► Standard temporary library
 
Question No: 12      ( M a r k s: 1 ) http://vuzs.net
 Skill(s) that is/are needed by programmers _______________________.
 
       ► Paying attention to detail
       ► Think about the reusability
       ► Think about user interface
       ► All of the given options
 
Question No: 13      ( M a r k s: 1 ) http://vuzs.net
 For which array, the size of the array should be one more than the number of elements in an array?
 
       ► int
       ► double
       ► float 
       ► char
 
Question No: 14      ( M a r k s: 1 ) http://vuzs.net
 new and delete are _____ whereas malloc and free are _____.
 
       ► Functions, operators
       ► Classes, operators
       ► Operators, functions
       ► Operators, classes
 
Question No: 15      ( M a r k s: 1 ) http://vuzs.net
 Friend functions are _____ of a class.
 
       ► Member functions
       ► Public member functions
       ► Private member functions
       ► Non-member functions
 
Question No: 16      ( M a r k s: 1 ) http://vuzs.net
 The prototype of friend functions must be written ____ the class and its definition must be written ____
 
       ► inside, inside the class
       ► inside, outside the class
       ► outside, inside the class
       ► outside, outside the class
 
Question No: 17      ( M a r k s: 1 ) http://vuzs.net
 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 will drive 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
       ► Any of the objects (obj1, obj2) can drive the + operator

Question No: 18      ( M a r k s: 1 ) http://vuzs.net
 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: 19      ( M a r k s: 1 ) http://vuzs.net
 For cin, the source is normally a ________ and destination can be ______.
 
       ► File, native data type
       ► Disk, user-define type
       ► Keyboard, variable
       ► File, user-define type
 
Question No: 20      ( M a r k s: 1 ) http://vuzs.net
 We can also do conditional compilation with preprocessor directives.
 
      ► True
      ► False

Question No: 21      ( M a r k s: 1 ) http://vuzs.net
 The programs, in which we allocate static memory, run essentially on ________
 
       ► Heap
       ► System Cache
       ► None of the given options
       ► Stack

Question No: 22      ( M a r k s: 1 ) http://vuzs.net
 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: 23      ( M a r k s: 1 ) http://vuzs.net
 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: 24      ( M a r k s: 1 ) http://vuzs.net
 When an operator function is defined as member function for a binary Plus (+) operator then the number of argument it take is/are.
 
       ► Zero
       ► One
       ► Two
       ► N arguments
 
Question No: 25      ( M a r k s: 1 ) http://vuzs.net
 With user-defined data type variables (Objects), self assignment can produce __________.
 
       ► Syntax error
       ► Logical error
       ► Link error
       ► Non of the given options
 
Question No: 26      ( M a r k s: 1 ) http://vuzs.net
 Assignment operator is used to initialize a newly declared object from existing object.
 
       ► True
       ► False
 
Question No: 27      ( M a r k s: 1 ) http://vuzs.net
 When an object of a class is defined inside an other class then,
 
       ► Constructor of enclosing class will be called first
       ► Constructor of inner object will be called first
       ► Constructor and Destructor will be called simultaneously
       ► None of the given options
 
Question No: 28      ( M a r k s: 1 ) http://vuzs.net
 In the member initializer list, the data members are initialized,
 
       ► From left to right
       ► From right to left
       ► In the order in which they are defined within class
       ► None of the given options
 
Question No: 29      ( M a r k s: 1 ) http://vuzs.net
 new operator allocates memory from free store and return _____________.
 
       ► A pointer
       ► A reference
       ► An integer
       ► A float
 
Question No: 30      ( M a r k s: 1 ) http://vuzs.net
 "new" and "delete" keywords are _____________ in C++ language.
 
       ► Built-in- Function
       ► Operators
       ► Memory Allocation Function
       ► None of  the given options
 
Question No: 31      ( M a r k s: 1 )
 What is a constructor in class?
 
Answer:
 
Constructors are used to create, and can initialize, objects of their class type.
The name of this function is same as the name of the class, having no return type.
This is in the public section of our class.
If we do not write a constructor, C++ writes a default constructor for us.
 
Question No: 32      ( M a r k s: 1 )
What are the two types of conversion for user-defined data types?
 
Answer:
  • Conversion by constructor
  • Constructor by operator
 
Question No: 33      ( M a r k s: 2 )
Is there a way to increase the size of already allocated memory chunk ? Can the same chunk be increased or not?
 
Answer:
#include
main()
{
            char *ptr;
            ptr=(char*)malloc(20*sizeof(char));
            realloc(ptr,25*sizeof(char));
 
/*        
            char *ptr1;
            ptr1=new char[20];
            delete ptr1;
            ptr1=new char[25];
            system("pause");
*/
}
Question No: 34      ( M a r k s: 2 )
 Give the general syntax of class template.
 
Answer:
 
template // T is generic data type
class class-name
{
            //class definition;
};
 
 
Question No: 35      ( M a r k s: 3 )
What is the difference between structure and class? 
Answer:
 
In C++ structures are very similar to classes except the default visibility i-e default visibility in structure is public and private in classes
 
Question No: 36      ( M a r k s: 3 )
How many arguments does binary member operator function and binary non-member operator function take?
 
Answer:
 
member function with one parameter
 
and
 
 non-member function with two parameters.
 
Question No: 37      ( M a r k s: 3 )
Find the error in the given code  
for ( int i=0; i
{
for(int j=0; j
{
elements[i , j] = m.elements[i][j];       
}
}
 
Answer:
 
elements[i , j] should be elements[i] [ j]
 
 
Question No: 38      ( M a r k s: 5 )
Write the C++ syntax for making a class friend of other class.
 
Answer:
 
friend class Y;
 
or
 
class myclass
{
friend class otherClass;
}
 
Question No: 39      ( M a r k s: 5 )
What is a template function? Give the general syntax of writing a template function.
 
template // T is generic data type
class my-class-name
{
            //class definition;
};
 
template
class name :: functionname(argument list)
{
            //function body;
};
 
Question No: 40      ( M a r k s: 10 )
Write a program which contains a class student. The class should contain two char pointer variablesName, and department. The class should further contain constructors, overload the stream insertion operator (<<) for this class.
 
In main function create two objects and display these objects.
 
 
 
#include
class student
{
            private:
                        char Name[100];
                        char department[100];
            public:
                        student()
                        {
                                    cout << "object created" <
                        }
                        void setname()
                        {
                                    cout << "name ?" <
                                    cin >> Name;
                        }
                        void setdepartment()
                        {
                                    cout << "dep name ?" << endl;
                                    cin >> department;
                        }
                        friend ostream & operator << (ostream &  , student );
};
ostream & operator << (ostream & out , student s)
{
            cout << s.Name << endl;
            cout << s.department << endl;
            return out;
}
main()
{
            student a,b;
            a.setname();
            a.setdepartment();
           
            b.setname();
            b.setdepartment();
            cout << a <
            cout << b <
            system("pause");
}
Question No: 41      ( M a r k s: 10 )
What is Standard Template Library (STL) also describe its advantages?

CS201 Final Term Paper Solved 2009 - 5

FINALTERM  EXAMINATION
Fall 2009
CS201- Introduction to Programming
 
Time: 120 min
M a r k s: 75
If we write a statement like s2 = s1; ___ will be the calling object and ____ will be passed to the = operator as an argument.
        s1, s1
        s1, s2
        s2, s1
        s2, s2
If we write a statement like s2 = s1; s2 will be the calling object and s1 will be passed to the = operator as an argument. P# 397

cout <<setfill('0')<<setw(7)<<br /></span></div> <div style=


Overloaded new operator function takes parameter of type size_t and returns
        void (nothing)
        void pointer
        object pointer
        int pointer

Also note that the new operator returns a void pointer. Any new operator we write must have this parameter and return type.
 
 
Which of the following is the correct way to declare a variable x of integer type?
        x int ;
        integer x ;
        int x;
        x integer

 
Reserve words cannot be used as a variable name.
        True
        False
There are few data types in C language. These data types are reserved words of C language. The reserve words can not be used as a variable manes. P#  17


A template function must have at least ---------- generic data type
 
        Zero
        One
        Two
        Three

The function arguments must contain at least one generic data type. P#  499
 
 
Template functions can also be overloaded
        True
        False

We can write overloaded template functions as long as there is use of different number or type of arguments.. P # 503
 
 
We can not make a member function of a class as template function.
        True
        False not sure

When break statement is encountered in switch statement, it
        Stops the entire program
        Stops the execution of current statement
        Exits from switch statement
        None of the given options


We can also define a variable of user define data type (object) as static.
        True
        False


The declarator of Plus (+) member operator function is
 
        Class-Name  operator + (Class-Name  rhs)
        operator Class-Name + ( )
        operator Class-Name + ( rhs)
        Class-Name  operator + ( )


 Let suppose
    int a, b, c, d, e;
  a = b = c = d = e = 42;
This can be interpreted by the complier as:
 
        a = (b = (c = (d = (e = 42))));
        (a = b = (c = (d = (e = 42))));
        a = b = (c = (d = (e = 42)));
        (a = b) = (c = d) = (e = 42);
a = (b = (c = (d = (e = 42) ) ) );
 
 
 
What will be the range of numbers generated by function rand () % 9?
        0 to 9
        1 to 9
        0 to 8
        1 to 8
When 6 divides any number, the remainder will always be less than 6. Ther
result will be between therefore we will add 1. 1 + rand ( ) % 6;
Which of the following is the correct function call having array named student of 10 elements as a parameter.
        addRecord(student[]) ;
        addRecord(student) ;
        addRecord(student[10]) ;
        addRecord(*student) ;
when we pass array we don’t give limit of array
Example:
Pass array to function

#include
   #include
   void read(int *,int);
   void dis(int *,int);
  
   void main()
   {
    int a[5],b[5],c[5],i;

    printf("Enter the elements of first list \n");
    read(a,5);
    printf("The elements of first list are \n");
    dis(a,5);
   }

   void read(int c[],int i)
   {
    int j;
    for(j=0;j       scanf("%d",&c[j]);
    fflush(stdin);
   }

   void dis(int d[],int i)
   {
    int j;
    for(j=0;j
     printf("%d ",d[j]);
    printf("\n");
   }
 
 
Declaring structures does not mean that memory is allocated.
Example:
        True
        False

structures do not occupy any memory until it is associated with the structure variable
 
Identifier is a name that can be given to variables, labels and functions.
        True
        False

An 'Identifier' means any name that the user creates in his/her program. These names can be of variables, functions and labels
 
If a class A declares itself a friend of class B and a class B declares itself a friend of class C then
        Class A is also a friend of class C.
        Class B is also a friend of class A.
        Class A is also a friend of class C if A declares C as its friend.
        Class A is also a friend of class C if C declares A as its friend.
If we want a two-way relationship, OtherClass will have to declare ClassOne as a friend class, resulting in a complete two-way relationship



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.



Friend is a very strong statement. It is too strong to be affected by public or private we can put it anywhere in the class
 
A pointer is a special type of variable that contain ___________
        Memory Address
        Data values
        Both Values and Memory
        None of given of options

Pointer is a special type of variable that contains a memory address.
 
When memory for a program is allocated at run time then it is called ________
 
        static memory allocation 
        dynamic memory allocation 
        stack memory allocation
        virtual memory allocation 
When we create an object of the class at run time, it will allocate memory according to our requirement. So there is no waste of memory and the situations in which we want to store large data in small memory or vice versa are prevented. So we do dynamic memory allocation inside these classes.
 
What purpose do classes serve?
        Data encapsulation
        Providing a convenient way of modeling real-world objects
        Simplifying code reuse
        All of the given options



Which of the following function cannot be overloaded?
        Member functions
        Utility functions
        Constructor
        Destructor
The destructors can be summarized as The destructors cannot be overloaded. The destructors take no arguments. The destructors don’t return a value



The following prototype of unary operator function indicates that it is ____________ .
Date operator++(int )
 
        Member functions of post increment operator
        Member functions of  pre increment operator
        Non-member functions of post increment operator
        Non-member functions of  pre increment operator
Overloading Unary Operators
// Preincrement operator overloaded as a member function.
Date Date::operator++()
{
   helpIncrement();
   return *this;  // value return; not a reference return
}
 
// Postincrement operator overloaded as a member function.
// Note that the dummy integer parameter does not have a
// parameter name.
Date Date::operator++(int)
{
   Date temp = *this;
   helpIncrement();
 
   // return non-incremented, saved, temporary object
   return temp;   // value return; not a reference return
} // This paper was solved by vuzs Team and meant for hosting
at vuzs otherwise its stolen contents



Static variable which is defined in a function is initialized __________.
        Only once during its life time
        Every time the function call
        Compile time of the program
        None of the above

Once the static variables are created, they exist for the life of the program. They do not die.
 
In the member initialize list, the data members are initialized,
        From left to right
        From right to left
        In the order in which they are defined within class
        None of the given options



If we do not indent the code properly it will __________________
        Be a syntax error
        Be a logical error
        Not be an error at all
        None of the given options



we Indent the code for better readability and understanding
 
 
Truth tables are used for analyzing ___________.
        logical expressions
        arithmetic expressions
        both logical and arithmetic expressions
        none of the given options.

The truth tables are very important. These are still a tool available for analyzing logical expressions.
 
 
Static memory allocation is also known as ____________
        Dynamic allocation
        Compile time allocation
        Run time allocation
        None of the given options
This type of memory static allocation. It is also known as compile time allocation.


 
 ( M a r k s: 1 )
What does getline() member function of cin stream do?
  
Another member function of cin is getline(). It reads a complete buffer i.e. the number of character specified up to a delimiter we specify. We can write something like:
            cin.getline(char *buffer, int buff_size, char delimiter = ‘\n’)
   ( M a r k s: 1 )
When memory is allocated dynamically using new operator within the constructor of class then what is an appropriate place to de-allocate the memory?
 
Whenever we allocate memory with the new operator, it is our responsibility to de-allocate this memory after the termination of the program. To do this de-allocation, we have an operator delete. To de-allocate the memory, allocated with p = new int ; we will write delete
 
(p) ;
It will not delete the p rather, it will send the memory gotten and pointed by pback to the free store.
( M a r k s: 2 )
What will be the output of following code, if user input a number 123?
int

 
 
( M a r k s: 2 
 
 
What is memory leak?
suppose, the heap size is decreased as we had allocated memory from it despite the fact that it was never utilized. If this step of allocating memory and then destroy the pointer to this memory carries on then the size of the heap will going on to decrease. It may become of zero 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
 
 ( M a r k s: 3 )
When we call calloc function to allocate memory and its return a NULL pointer what does it mean?
 
Calloc function takes two arguments. The first argument is the required space in terms of numbers while the second one is the size of the space
Now we have to see what happens when either we ask for too much memory at a time of non-availability of enough memory on the heap or we ask for memory that is available on the heap , but not available as a single chunk?. In this case, the call to calloc will fail. When a call to memory allocation functions fails, it returns a NULL pointer.
 
 ( M a r k s: 3 )
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 ] ;
    }
}
( M a r k s: 3 )
What is the keyword ‘this’ and what are the uses of ‘this’ pointer?
 
Whenever an object calls a member function, the function implicitly gets a pointer from the calling object. That pointer is known as this pointer. ‘this’ is a key word. We cannot use it as a variable name. ‘this’ pointer is present in the function, referring to the calling object.
this pointer points to the current object.
 ( M a r k s: 5 )
 
What do you mean by garbage collection and how it works in JAVA and C++ ?
 
JAVA gives the concept of garbage collection with the use of references. Due to this garbage collection, we are free from the headache of de- allocating the memory. We allocate and use the memory. When it is no longer in use, JAVA automatically deletes (frees) it through garbage collection But in C and C++ languages, we have to take care of de-allocating the memory. In classes where we use dynamic memory, we have to provide destructors to free this memory. The languages keep evolving, new constructs will keep evolving in existing or new languages.
 ( M a r k s: 5 )
 
Explain the concept of separation of interface from the implementation in the context of classes, using a real world example.
 ( M a r k s: 10 )
 
Write a simple program using the get() member function of cin object reading a text of 30characters from the keyboard, store them in an array and then using put() member function of cout object to display them on the screen.
 ( M a r k s: 10 )
 
Overload the Binary Assignment (=) Operator.
Write a program which has a class List, This class should have Two data members, an array of integers list[] and an integer variable length (i.e. number of elements in the list).The class should further contain a default  constructor,  a Print() function which display the list and a Function insert() which insert an element in the list and  Assignment (= ) Operator function, which contain code for the assignment of one object to other. .
In main function define two objects list1 and list2 and use the statement list2 = list1; and use (call ) print function with both objects

Related Posts Plugin for WordPress, Blogger...