FINALTERM EXAMINATION
Spring 2009
CS201- Introduction to Programming (Session - 1)
(Note answers are not cofirmed)
Question No: 1 ( M a r k s: 1 ) http://vuzs.net
To access the data members of structure _______ is used.
► dot operator (.)
► * operator
► à operator
► None of given.
Question No: 2 ( M a r k s: 1 ) http://vuzs.net
What does 5 ^ 6 , evaluate to in decimal where ‘^’ is Exclusive OR operator?
► 1
► 2
► 3
► 4
Question No: 3 ( M a r k s: 1 ) http://vuzs.net
If constructor contains a return statement in its body then compiler will give __________
► No error
► Syntax error
► Logical error
► Run time error
Question No: 4 ( M a r k s: 1 ) http://vuzs.net
We can use New keyword inside of Class Constructor.
►True
►False
Question No: 5 ( M a r k s: 1 ) http://vuzs.net
When an operator function is define as member function for a Unary operator then the number of argument it take is/are,
►Zero
►One
►Two
►N arguments
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: 7 ( M a r k s: 1 ) http://vuzs.net
Friend function of a class is ______________ .
►Member function
►Non-member function
►Private function
►Public function
Question No: 8 ( M a r k s: 1 ) http://vuzs.net
We can also create an array of user define data type.
►True
►False
Question No: 9 ( M a r k s: 1 ) http://vuzs.net
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: 10 ( M a r k s: 1 ) http://vuzs.net
Deleting an array of objects without specifying [] brackets may lead to memory leak
►True
►False
Question No: 11 ( M a r k s: 1 ) http://vuzs.net
Which of the following data type(s) can operate on modulus operator ‘%’?
► float, int
► float, double
► int
► char
Question No: 12 ( M a r k s: 1 ) http://vuzs.net
Array is passed by value to a function by default.
►True
►False
Question No: 13 ( M a r k s: 1 ) http://vuzs.net
With template function, the compiler automatically detects the passed data and generates a new copy of function using passed data.
►True
►False
Question No: 14 ( M a r k s: 1 ) http://vuzs.net
What will be the correct syntax to initialize all elements of two-dimensional array to value 0?
►int arr[2][3] = {0,0} ;
►int arr[2][3] = {{0},{0}} ;
►int arr[2][3] = {0},{0} ;
►int arr[2][3] = {0} ;
Question No: 15 ( M a r k s: 1 ) http://vuzs.net
When an operator function is define as member function then operand on the left side of operator must be an object.
►True
►False
Question No: 16 ( M a r k s: 1 ) http://vuzs.net
break statement can be used outside a loop or switch statement.
►True
►False
Question No: 17 ( M a r k s: 1 ) http://vuzs.net
The keyword_______ is used to return some value from a function.
►return
►break
►continue
►goto
Question No: 18 ( M a r k s: 1 ) http://vuzs.net
Every data member or function inside the structure is ___ by default whereas everything declared inside a class is ____ by default.
►private, public
►public, private
►private, protected
►public, protected
Question No: 19 ( M a r k s: 1 ) http://vuzs.net
Which of the following is true for the C++ statement given below?
int &ref = val ;
►It creates a synonym for variable ‘val’
►It creates an alias for variable ‘val’
►It’s a new name for variable ‘val’
►All of the given options
Question No: 20 ( 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: 21 ( M a r k s: 1 ) http://vuzs.net
Unary operator implemented as member function takes ____ arguments whereas non-member function takes _____ arguments.
►One, zero
►Zero, one
►One, two
►Two, one
Question No: 22 ( M a r k s: 1 ) http://vuzs.net
The input/output streams cin and cout are ________ therefore have _______.
► Structures, function
► Objects, member functions
► Functions, objects
► None of the given options
Question No: 23 ( M a r k s: 1 ) http://vuzs.net
If a symbolic constant has been defined, it will be an error to define it again.
► True
► False
Question No: 24 ( M a r k s: 1 ) http://vuzs.net
Every class contains _______________.
► Constructor
► Destructor
► Both a constructor and a destructor
► None of the given options
Question No: 25 ( 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: 26 ( M a r k s: 1 ) http://vuzs.net
Consider the following code segment.
class M {
public:
M &operator+(const M &);
...
};
p + q //code of line implies that p.operator+(q)
...
Let assume if p and q are class objects then function is implemented as _______
►Member function
►Non-member function
►Friend function
►None of the given options
Question No: 27 ( M a r k s: 1 ) http://vuzs.net
Assignment operator is -------------------------associative.
►right
►left
►binary
►unary
Question No: 28 ( M a r k s: 1 ) http://vuzs.net
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
Question No: 29 ( M a r k s: 1 ) http://vuzs.net
Wecan not define a variable of user-defined data type in the class.
►True
►False
Question No: 30 ( M a r k s: 1 ) http://vuzs.net
A constructor that will create a new object with a full copy of the other object, is copy is known as ___________
►deep copy
►shallow copy
►constructor copy
►none of the options
Question No: 31 ( M a r k s: 1 )
What is the use of reference data type?
A reference data type is a variable that can contain an address. The reference data types in Java are arrays, classes and interfaces. You'll hear often say that Java does not have pointers. Yet, you could consider a reference data type to be a pointer
Question No: 32 ( M a r k s: 1 )
What are the main types of operators in terms of number of arguments they take?
The difference is in the number of arguments used by the function. In the case of binary operator overloading, when the function is a member function then the number of arguments used by the operator member function is one (see below example). When the function defined for the binary operator overloading is a friend function, then it uses two arguments.
Question No: 33 ( M a r k s: 2 )
What is the this pointer? Give an example of its use
In a C++ program, if you create object A of class X, you can then obtain the address of A by using the "this" pointer. The address is available as a local variable in the non-static member functions of X, and its type is const X*. The "this" pointer works because C++ creates instances of its data members, and it keeps one copy of each member function.
Question No: 34 ( M a r k s: 2 )
What are manipulators? Give one example.
Manipulators are operators used in C++ for formatting output. The data is manipulated by the programmer’s choice of displayed endl manipulator. This manipulator has the same functionality as the ‘\n’ newline character.
Question No: 35 ( M a r k s: 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;
}
Output will be:
1
1
1
2)
void func2(){
static int x = 0 ;
x++;
cout << x << endl ;
}
Output will be:
1
2
3
Question No: 36 ( M a r k s: 3 )
If the requested memory is not available in the system then what does calloc/malloc and new operator return?
malloc returns a void pointer to the allocated space or NULL if there is insufficient memory available. To return a pointer to a type other than void, use a type cast on the return value. The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object. If size is 0, malloc allocates a zero-length item in the heap and returns a valid pointer to that item.
By default, malloc does not call the new handler routine on failure to allocate memory. You can override this default behavior so that, when malloc fails to allocate memory, malloc calls the new handler routine in the same way that the new operator does when it fails for the same reason.
Question No: 37 ( M a r k s: 3 )
If we want to send the data by reference and don’t want that original data should be affected then what can we do to prevent any change?
Question No: 38 ( M a r k s: 5 )
Write down the disadvantages of the templates.
The disadvantages of templates are:
• 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: 39 ( M a r k s: 5 )
The following code segment has errors. Locate as many as you can and explain briefly.
class Circle // no need to enter colon here , so I removed it
{
private : //colon missing
double centerX;
double centerY;
double radius;
public: //colon missing
void setCenter(double, double);
void setRadius(int);
};//semi colon missing
Question No: 40 ( M a r k s: 10 )
Write a program which consists of two classes, Date and Person.
Date class should contain three data members day, month, year and setter and getter function for these data members. Date class should also contain showdate() member function to display date.
Person class should contain three data members Name, Address, and Bday, where Name and Address are char pointer while Bday(Date of birth) is of type Date, Person class should further contain two member functions Display() and setdate().
In main program Create an object of Class person and call the member functions with it.
Please find the Answer in following Box
#include
#include
#include
using namespace std;
class Date
{
public:
int day;
int month;
int year;
public:
Date()
{
day=0;
month=0;
year=0;
}
void setDay(int);
void setMonth (int);
void setYear(int);
int getDay();
int getMonth();
int getYear();
void showDate();
};
void Date: :setDay(int d)
{
if{d31)
cout< A default constructor which must initialize all the data members to their meaningful values.
· A destructor with no implementation.
· Setter member functions to set all data members of class
· Getter member functions to get all data members of class
In main function of the program
5. Prompt the user to enter the number of objects to be created.
6. Dynamically allocate memory to objects according to the size entered by user.
7. De-allocate memory that was allocated to objects
Find solution in following box:
#include
#include
#include
using namespace std;
class myclass
{
public:
int a;
int b;
int *iptr, *sptr;
construct{int,int.int}
void seta(int);
void setb(int);
void setc(int);
int geta();
int getb();
int getc();
};
void Person: :seta(int aa)
{
a=aa;
}
void Person: :setb (int bb)
{
b=bb;
}
void Person: :setc (int cc)
{
c=cc;
}
main()
{
int num;
cout<<"enter the="" number="" of="" objects="" to="" be="" created="" span="" div="" style="margin: 0in 0in 0pt" cin="" num="" for="" int="" i="1;i==num;i++)