We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More


Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

How to Add New Discussion in Study Group ? Step By Step Guide Click Here.

CS201 Solved Final Term Papers Mega Mega ZIP Folders

See the attached 04 ZIP Folders

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 4524

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Attachments:

Replies to This Discussion

One more ZIP Folder

Attachments:

Note: (This is Featured Discussion)

For Important Helping Material related to this subject (Solved MCQs, Short Notes, Solved past Papers, E-Books, FAQ,Short Questions Answers & more). You must view all the featured Discussion in this subject group.

For how you can view all the Featured discussions click on the Back to Subject Name Discussions link below the title of this Discussion & then under featured Discussion corner click on the view all link.

CS201 – Introduction to Programmming

Solved Subjective Questions

From spring 2010 Final Term Papers

vuattach.ning.com

 

Question No: 1      ( Marks: 2 )

 

Write a declaration statement for an array of 10 elements of type float. Include an initialization statement of the first four elements to 1.0, 2.0, 3.0 and 4.0.

 

Answer:

float  floatArry[10] = {1.0,2.0,3.0,4.0};

 

Question No: 2      ( Marks: 2 )

 

Write the general syntax for the declaration of pre-increment and post-increment member operator function.

 

Answer:

Classname operator ++(); ---- pre increment

Classname operator ++(int)  ---- post increment

 

 

Question No: 3      ( Marks: 2 )

 

Give the general syntax of class template.

 

Answer:

template

class myclass { ---} ;

 

Question No: 4      ( Marks: 2 )

 

What is a truth Table?

 

Answer:

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: 5      ( Marks: 2 )

 

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

 

int input ;

cin >> oct >> input;

cout hex input ;

 

Answer:

 

53

 

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

 

 

Question No: 6      ( Marks: 2 )

 

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

 

Answer:

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: 7      ( Marks: 2 )

 

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

 

Answer:

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

 

Question No: 8      ( Marks: 2 )

 

Which arithmetic operators cannot have a floating point operand?

 

Answer:

Modulus operator:

This operator can only be used with integer operands ONLY

 

Question No: 9      ( Marks: 2 )

 

What are manipulators? Give one example.

 

Answer:

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.

 

Question No: 10      ( Marks: 2 )

 

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

 

Answer:

int matrix [3] [3] ;

 

include

 

 

main () {

    int matrix [3][3];

    int inivalue = 0;

  

    for (int a=0;a<3;a++)

    { for (int b = 0;b<3;b++)

   { matrix[a][b]= inivalue;

    cout/p>

}

 

Question No: 11      ( 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: 12      ( Marks: 2 ) 

 

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

 

Answer:

Initializer list is used to initialize the contained objects at the construction time.

 

Question No: 13      ( 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: 14      ( Marks: 2 )

 

 Suppose there is a template function ‘func’ having argument of type U and return type T. What will be the C++ syntax to call this function, passing a variable ‘x’ of type double and returning an int type?

 

Answer:

template

T func (T a, U b) {

  return (a

}

calling

int  i;

double x;

x = func

Question No: 15      ( Marks: 2 )

 

Which variable will be used in inner code block if we have the same names of variable at outer code block and inner code block?

 

Answer:

Simply: variable of the inner code is use in the inner code block.

 

Question No: 16      ( Marks: 2 )

 

 

What is the benefit of reference and where can we use it?

 

 Answer:

In references we give the memory address of the object, due to references we pass values without making the copy. Hence, when we have many values & we want efficiency we use references to avoid copy.

 

 

Question No: 17      ( Marks: 2 )

 

Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator for the object d of type Date.

 

Answer:

Date operator >> (date & d1){

cout<”-”<”-”/p>

}

 

 

 

Question No: 18      ( Marks: 2 )

 

What is difference between endl and \n? 

 

Answer:

Endl is manipulator and it inserts new line character and flushes the stream.

 

\n is control character which is used to insert line break.

 

Question No: 19      ( Marks: 2 )

 

What does code optimization mean?

 

Answer:

It is process by which we make our code in such a way that it improves the speed of program. By use of optimization we refine program codes in such a way that it run faster and consume less memory. We do it in such a way that output quality is not compromised.

 

Question No: 20      ( Marks: 3 )

 

How is the following cout statement interpreted by compiler?

 

cout a b c ;

 

Answer:

It will give a compiler error because a,b,c are not declared.

 

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

Answer: A

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

Answer: B

 

 

Question No: 22      ( 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;

}

 

Answer:

 

1

1

1

2)

void func2(){

static int x = 0 ;

x++;

cout x endl ;

 

Answer:

1

2

3

 

Question No: 23      ( Marks: 3 )

 

If is not available in the system then what does calloc/malloc and new operator return?

 

Answer:

calloc/malloc and new operator return returns a null pointer to indicate that no memory is available

 

 Question No: 24      ( Marks: 3 )

 

What is the keyword ‘this’ and what are the uses of ‘this’ pointer?

 

Answer:

'this' is use to refer the current class member without using the name of the class.

 

 

Question No: 25      ( 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;

 

Answer:

 

1) Matrix m1 (m2);   copy constructor

2) Matrix m1, m2;   

m1 = m2;               assignment operator

3) Matrix m1 = m2; assignment operator

 

Question No: 26      ( 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); }

 

Answer:

 

0

The output will zero as 1/5 and its .05 but conversion to int make it zero

Above is prototype of template class so assume passing an int and returning an int

 

 

 

Question No: 27      ( Marks: 3 )

 

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

 

math * operator(math m);

math * operator (math m)

{

     math temp;

     temp.number= number * number;

     return number;

   

}

 

Answer:

 

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

     temp = m;

     temp.number= number * number;

     return temp.number;

   

}

 

 

Question No: 28      ( Marks: 3 )

 

What are the limitations of the friendship relation between classes?

 

Answer:

friendship relation between classes is a one way relation that is if one class declare friend another class then the another class is the friend of first class but not the first class if the friend of another class.

 

 

Question No: 29      ( Marks: 3 )

 

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

 

Answer:

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: 30      ( Marks: 5 )

 

What is difference between Unary and binary operators and how they can be overloaded?

 

Answer:

Unary operator takes one argument.

a ++ is an example of unary operator

 

Binary take two operators

+,-,* are example of binary operators

Overloaded binary operator may return any type

 

Here is general syntax of overloading

Return-type operator symbol (parameters);

 

Operator is keyword

Question No: 31      ( Marks: 5 )

 

What steps we must follow to design good program?

 

Answer 1:

 

Hence to design a program properly, we must:

  • Analyze a problem statement, typically expressed as a word problem.
  • Express its essence, abstractly and with examples.
  • Formulate statements and comments in a precise language.
  • Evaluate and revise the activities in light of checks and tests and
  • Pay attention to detail.

 

Answer 2:

 

Details:  we must check very details of any program. It is very important aspect of any program.  We must pay complete attention to calculation.

We must give attention to logic and its flow should be smooth.

 

Reusable: We must write program in such a way that we can reuse them in other program. Like we define function in such a way that in future if we need any similar kind of function is requires in that case we can easily modify or reuse it.

 

Comments: we write the details of important steps in the form of comments. We should use comments in such a way if any body else wanted to reuse or debug or codes he can easily understand it.

 

 

Code readability: We should use Tab and spaces so codes are easily readable.

 

User interface: we make interface user friendly. Use polite prompts for user while take input.

 

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

 

Answer:

 

#include

#include

main(){

       int sal1 =1000;

       int sal2 =1500;

       int sal3 =20000;

       int sal4 =30000;

       int sal5 =60000;

            

       

cout setfill ('x') setw (10);

cout sal1/p>

cout setfill ('x') setw (10);

cout sal2/p>

cout setfill ('x') setw (10);

cout sal3/p>

cout setfill ('x') setw (10);

cout sal4/p>

cout setfill ('x') setw (10);

cout sal5/p>

int i=0; 

cin>>i; // to stop the screen to show the output

}

 

 

 

Question No: 33      ( Marks: 5 )

 

Suppose we have the following class.

 

class Matrix

{

private:

int Elements[3][3];

};

 

Write the operator function of stream extraction operator (>>) for this class.

 

Answer:

Element operator >> (Element &element){

cout/p>

cout/p>

cout/p>

}

 

Question No: 34      ( Marks: 5 )

 

 

What is meant by user interface and class interface in C++ ? And what role a class interfaces can play in user interface [Marks 5]

 

Answer:

 

 

 

Question No: 35      ( 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.

 

Answer:

class frinedclass{

public:

friend int compute(exforsys e1)

};

Int compute(exforsys e1)
{
//Friend Function Definition which has access to private data
return int(e1.a+e2.b)-5;
}

 

Question No: 36      ( Marks: 5 )

 

What are the advantages and disadvantages of using templates?

 

Answer:

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

 

Advantages:

  • 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 helps 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: 37      ( 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  ; 

 

Answer:

#include

math

{

mth operator + (obj1,int x)

{

 

number temp;

temp=obj1.number+x;

return temp.number;

}

}

 

Question No: 38      ( Marks: 5 )

 

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

 

Answer:

 

#include

#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: 39      ( 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::operator = ( const String &other )

 { int length ;

 length = other.length();

delete buf;

 buf = new char [length + 1];

 strcpy( buf, other.buf ); }

 

Question No: 40      ( 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

 

Answer:

In the above mentioned code, first of all programmer call the constructor who have two parameters for the number of rows & columns in the matrix. Then this constructor also dynamically allocates the memory for the elements of the matrix & also initializes the value of the all elements of matrix with 0.0

 

CS201 solved MCQS

The statement cout yptr will show the __________the yptr points to.
Value
Memory Address
Variabvle
None of given


char **argv can be read as__________________.
Pointer to Pimter
Pointer to Char
Pointer to Pointer to Char  (page 177)
None of given

_______________are conventional names of the command line parameters of the ‘main()’ function.
‘argb’ and ‘argv’
‘argc’ and ‘argv’
‘argc’ and ‘argu’
None of Given
___________ Returns true if c is a digit and false otherwise.
int isalpha( int c )
int isalnum( int c )
int isxdigit( int c )
int isdigit( int c )


In the case of pointer to pointer or _______________, the first pointer contains the address of the second pointer, which contains the address of the variable, which contains the desired value.
double dereference (page 175)
Single dereference
dereference
None of the given
_______________________ contains functions for manipulations of character data.
ctype.h
iostream.h
string.h
None of the given


dereferencing operator is represented by _______
*
+
-
None of the given

http://vuzs.net/

In_________, we try to have a precise problem statement
Analysis
Design
Coding
None of the given 

1- Memory allocated from heap or free store _____________________.

Select correct option:

can be returned back to the system automatically

can be allocated to classes only

cannot be returned back unless freed explicitly using malloc and realloc

cannot be returned back unless freed explicitly using free and delete operators

 

 

2- Once the _______________ are created, they exist for the life time of the program

Select correct option:

local variables

non static variables

static variables

automatic variables

 

Once the static variables are created, they exist for the life of the program. They do not die. So returning their reference is all right.3- The members of a class declared with the keyword struct are _____________by default.

Select correct option:

static

private

protected

public.

 

The members of a class declared with the keyword struct are public by default. A structure is inherited publicly by default.

 www.vuzs.net

4- If the memory in the free store is not sufficient ____________________.

Select correct option:

malloc function returns 1

malloc function returns 0

malloc functions returns NULL pointer

malloc function returns free space

 

if the memory in the free store is not sufficient enough to fulfill the request. malloc() function returns NULL pointer if the memory is not enough. In C++, 0 is returned instead of NULL pointer.

5. This reference to a variable can be obtained by preceding the identifier of a variable with ________________.

Select correct option:

dot operator

ampersand sign &

^ sign

  • operator

 

6- Once an object is declared as a friend, _________________________.

Select correct option:

it has access to all non-public members as if they were public

it has access to public members only

it has no access to data members of the class

it has to protected data members only

  • Friend declarations introduce extra coupling between classes
  • Once an object is declared as a friend, it has access to all non-public members as if they were public
  • Access is unidirectionalIf B is designated as friend of A, B can access A’s non-public members; A cannot access B’s
  • A friend function of a class is defined outsideof that class's scope

 

7- Reference variables must _________________.

Select correct option:

not be initialized after they are declared

be initialized after they are declared

contain integer value

contain zero value

 

8- If the request of new operator is not fulfilled due to insufficient memory in the heap ____________________.

Select correct option:

the new operator returns 2

the new operator returns 1

malloc functions returns NULL pointer

malloc function returns free space

 

 

9- Reference is not really an address it is ______________.

Select correct option:

a synonym

an antonym

a value

a number

 

10- If the request of new operator is not fulfilled due to insufficient memory in the heap ____________________.

Select correct option:

the new operator returns 2

the new operator returns 1

the operator returns 0

free operator returns nothing 

 

11- Functions declared with the _______________ specifier in a class member list are called friend functions of that class. 
Select correct option:
 

protected
 
private

Public

friend

Functions declared with the friend specifier in a class member list are called friend functions of that class. Classes declared with the friend specifier in the member list of another class are called friend classes of that class.

 

12- public or private keywords can be ____________ 
Select correct option:
 

written only for once in the class or structure declaration
 
written multiple times in the class or structure declaration
 
written only twice in the class declaration 
written outside the class

good practice is to write public or private keywords only once in the class or structure declaration, though there is no syntactical or logical problem in writing them multiple times.

 

13-The friend keyword provides access _____________. 
Select correct option:
 

in one direction only
 
in two directions 
to all classes
 
to the data members of the friend class only

The friend keyword provides access in one direction only. This means that while OtherClass is a friend of ClassOne, the reverse is not true.

14- References cannot be uninitialized. Because it is impossible to _______________ 
Select correct option:

 reinitialize a pointer 
reinitialize a reference
 
initialize a NULL pointer 
cast a pointer

http://en.wikipedia.org/wiki/Reference_(C%2B%2B)

References cannot be uninitialized. Because it is impossible to reinitialize a reference, 

15- new operator can be used for ______________.

Select correct option:

only integer data type

only char and integer data types

integer , float, char and double data types

dot operator

Similarly, new operator can be used for other data types like char, float and double etc.

 

16- The destructor is used to ______________.

Select correct option:

allocate memory

deallocate memory

create objects

allocate static memory

16- If we want to allocate memory to an array of 5 integers dynamically, the syntax will be _____________.

Select correct option:

int *iptr ; iptr = new int[5] ;

integer iptr** ; iptr= new int[5]

int iptr ; iptr= int [5]

iptr= new[5]  

17- Memory allocated from heap or free store _____________________.

Select correct option:

can be returned back to the system automatically

can be allocated to classes only

cannot be returned back unless freed explicitly using malloc and realloc

cannot be returned back unless freed explicitly using free and delete operators 

The memory allocated from free store or heap is a system resource and is not returned back to the system unless explicitly freed using delete or freeoperators.

 

18- Operator overloading is to allow the same operator to be bound to more than one implementation, depending on the types of the _________.

Select correct option:

Compilers

Operands

Function names

Applications 

Operator overloading is to allow the same operator to be bound to more than one

implementation, depending on the types of the operands.

 

19- The operator to free the allocated memory using new operator is ________________.

Select correct option:

free

del

delete

remove

The operator to free the allocated memory using new operator is delete. So whenever,

we use new to allocate memory, it will be necessary to make use of ‘delete’ to deallocate

the allocated memory. 

20- The concept of friend function negates the concept of _________________.

Select correct option:

inheritance

polymorphism

persistence

encapsulation

 Functions declared with the _______________ specifier in a class member list are called friend functions of that class. 
Select correct option: 

protected 
private

ple select all and paste

public 
friend

Functions declared with the friend specifier in a class member list are called friend functions of that class. Classes declared with the friend specifier in the member list of another class are called friend classes of that class.

 

public or private keywords can be ____________ 
Select correct option: 

written only for once in the class or structure declaration 
written multiple times in the class or structure declaration 
written only twice in the class declaration 
written outside the class

 

good practice is to write public or private keywords only once in the class or structure declaration, though there is no syntactical or logical problem in writing them multiple times.

 

The friend keyword provides access _____________
Select correct option: 

in one direction only 
in two directions 
to all classes 
to the data members of the friend class only

 

The friend keyword provides access in one direction only. This means that while OtherClass is a friend of ClassOne, the reverse is not true.

 

References cannot be uninitialized. Because it is impossible to _______________ 
Select correct option:

 reinitialize a pointer 
reinitialize a reference 
initialize a NULL pointer 
cast a pointer

 

 

http://en.wikipedia.org/wiki/Reference_(C%2B%2B)

References cannot be uninitialized. Because it is impossible to reinitialize a reference, 

 

Question # 1 of 10 ( Start time: 11:45:30 PM ) Total Marks: 1

new operator can be used for ______________.

Select correct option:

only integer data type

only char and integer data types

integer , float, char and double data types

dot operator

 

Similarly, new operator can be used for other data types like char, float and double etc.

 

Question # 3 of 10 ( Start time: 11:48:09 PM ) Total Marks: 1

The destructor is used to ______________.

Select correct option:

allocate memory

deallocate memory

create objects

allocate static memory

 

Question # 4 of 10 ( Start time: 11:48:31 PM ) Total Marks: 1

Reference is not really an address it is ______________.

Select correct option:

a synonym

an antonym

a value

a number

 

Difference Between References and Pointers

The reference in a way keeps the address of the data entity. But it is not really an

address it is a synonym,

 

 

Question # 5 of 10 ( Start time: 11:49:30 PM ) Total Marks: 1

If we want to allocate memory to an array of 5 integers dynamically, the syntax will be _____________.

Select correct option:

int *iptr ; iptr = new int[5] ;

integer iptr** ; iptr= new int[5]

int iptr ; iptr= int [5]

iptr= new[5]

  

  

Question # 7 of 10 ( Start time: 11:51:42 PM ) Total Marks: 1

Memory allocated from heap or free store _____________________.

Select correct option:

can be returned back to the system automatically

can be allocated to classes only

cannot be returned back unless freed explicitly using malloc and realloc

cannot be returned back unless freed explicitly using free and delete operators

 

The memory allocated from free store or heap is a system resource and is not returned back to the system unless explicitly freed using delete or free operators.

 

Question # 8 of 10 ( Start time: 11:52:11 PM ) Total Marks: 1

Operator overloading is to allow the same operator to be bound to more than one implementation, depending on the types of the _________.

Select correct option:

Compilers

Operands

Function names

Applications

MCQS SOLVED BY: _ALIMS_

 

 

Question: 1

New operator is used to allocate memory from the free store during ______________

 

Compile Time

Run Time

Link Time

None of above

 

 

Question: 2

To get the memory address of a variable we use _____

 

&

&&

*

|

 

 

Question: 3

 

If we have a program that writes the output data (numbers) to the disc, and if we collect the output Data and write it on the disc in one write operation instead of writing the numbers one by one. In the above situation the area where we will gather the number is called

 

Buffer

Stream

Memory

None of these

 

 

Question: 4

 

What functionality the following program is performing?

 

#include <iostream.h>

 

int main()

{

            const int SIZE = 80;

            char buffer[SIZE];

            cout " Enter a sentence : ";

            cin.getline(buffer, SIZE);

            coutbuffer endl;

            system("pause");

           

}

 

objects are used respectively to read a sentence from the key board and then print it on the screen.

Using getline function

using character arrays

Doing nothing  

 

 

Question: 5

 

The get member function, when passed no arguments, inputs an entire stream and returns it as the value of the function call.

 

True

False

 

Question: 6

New operator allocates memory from free store and returns ___________

 

Void

NULL

Nothing return

None of above

 

 

Question: 7

 

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

 

Read a character from keyboard

Read a an entire string

Read integer values

Read float values

 

 

Question: 8

Suppose int i = 10; then what will be the value of i after being converted in to octal value

 

10

12

14

16

 

Question: 9

Which of the following is a destination of cout stream?

 

Monitor /screen

Keyboard

Memory

None of these

 

Question: 10

Which of the following is the correct definition of streams ?

 

streams are memory locations

sequence of bytes are called streams

sequence of variables are called streams

sequence does not have any definition

 

 

Question: 11

Stream operators are heavily overloaded means , they allow to handle int and character data type only.

 

true

false

 

 

Question: 12

What functionality the following program is performing?

 

int main()

{

            const int SIZE = 80;

            char buffer[SIZE];

            cout " Enter a sentence : ";

            cin.getline(buffer, SIZE);

            coutbuffer endl;

            system("pause");

           

}

 

read and write member functions of cin and cout objects are used respectively to read a sentence from the key board and then print it on the screen.

 

read and put member functions of cin and cout objects are used respectively to read a sentence from the key board and then print it on the screen.

 

get and write member functions of cout and cin objects are used respectively to read a sentence from the key board and then print it on the screen.

 

get and write member functions of cout and cin objects are used respectively to read a sentence from the key board and then print it on the screen.

 

 

Question: 13

Which of the following is a source for cout stream?

 

monitor / screen

keyboard

proccessor

none of these

 

 

Question: 14

If we use cin stream to read some value and store it in some integer variable and press some alphabet key instead of numeric keys. then what will happen?

 

 

Its binary representation will be ignored and the character will be stored

 

Its binary representation will be ignored and the value will be stored

 

Its ASCII code will be stored inside the computer

 

Some error will occur and cin stream will detect this error.

 

 

The endl and flush are _____

 

Functions

Operators

Manipulators

Objects

 

What is the difference between cout and cerr ?

 

cout is  unbuffered output and cerr is buffered  output

 

cout is  standard output and cerr is not a standard  output

 

cout is  not a standard output and cerr is standard  output

 

cout is  buffered output and cerr is unbuffered  output

 

The operator function for (stream insertion) >> and stream extraction must be

 

Member function of class

Non-member function of class

Both member and non-member function

None of the given options

Reference: (These cin and cout objects will remain intact for our overloaded insertion and extraction operators. Therefore, the overloaded operators cannot be member operators.)

 

Note: I took this reference

 

 

The pointer returned by the new operator points to --------------- of memory chunks allocated by the new operator

 

First memory address

 

Second memory address

 

Last memory address

None of the above

 

 

When we used eof (end of file) with the file reading than which of the following is a true statement?

This is way to check source of the stream

This is way to check destination of the stream

This is way to check state of the stream

This is way to check type of the stream

 

The stream insertion and extraction operators are not already overloaded for ____

 

Built-in data types

 

User-defined data types

 

Both built-in and user-defined types

 

None of the given options

 

When a variable is defined as static in a class then ___________

 

Separate copy of this variable is created for each object

Only one copy is created for all objects of this class

A copy of this variable is created for only static objects.

None of the given options

 

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

 

 

 

Which of the following concept is NOT associated with stream?

 

NULL

FINALTERM  EXAMINATION

CS201- Introduction to Programming

 

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

 

 

If it is required to copy an array to another array then,

 

       ► Both arrays must be of the same size and data type

 

       ► Both arrays may be of different size

 

       ► Both arrays may be of different data type

 

       ► Both arrays may be of different size and type



 

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

 

 

Dealing with structures and functions passing  by reference is the most economical method

 

 

       ► True

 

       ► False



 

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

 

 

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

 

       ► True

 

       ► False



 

Question No: 4      ( 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: 5      ( Marks: 1 ) - Please choose one

 

 

When new operator is overloaded at global level then corresponding built-in new operator will not be visible to whole of the program.

 

 

       ► True

 

       ► False



 

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

 

 

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?

 

       ► parentheses ( )

 

       ► braces { }

 

       ► brackets [ ]

 

       ► arrows < >



 

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

 

 

The return type of a function that do not return any value must be  ________

 

 

       ► float

 

       ► int

 

       ► void

 

       ► double



 

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

 

 

UNIX has been developed in ________ language.

 

       ► JAVA

 

       ► B

 

       ► C

 

       ► FORTRAN



 

Question No: 9      ( 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: 10      ( 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: 11      ( 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: 12      ( Marks: 1 ) - Please choose one

 

 

The endl and flush are _______

 

 

 

 

 

 

       ► Functions

 

       ► Operators

 

       ► Manipulators

 

       ► Objects



 

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

 

 

If a symbolic constant has been defined, it will be an error to define it again.

 

       ► True

 

       ► False



 

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

 

 

The operator used for casting, in C, is standard ________ operator.

 

       ► none of the given options.

 

       ► cast

 

       ► cost

 

       ► const



 

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

 

 

Constructors can not be overloaded like ordinary functions.

 

       ► True

 

       ► False



 

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

 

 

Which of the following function call is correct for the function prototype?

defaultParameters ( int a, int b = 7, char z = ‘*’ );

 

 

       ► defaultParameters (5);

 

 

       ► defaultParameters (5, ‘8’);

 

 

       ► defaultParameters (6, ‘#’);

 

 

       ► defaultParameters (0, 0, ‘*’, 0);

 



 

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

 

 

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: 18      ( Marks: 1 ) - Please choose one

 

 

We can not define a variable of user-defined data type in the class.

 

 

       ► True

 

       ► False



 

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

 

 

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: 20      ( Marks: 1 ) - Please choose one

 

 

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

 

       ► float

 

       ► int

 

       ► char

 

       ► none of the given options.



 

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

 

 

Class is a user defined___________.

 

       ► data type

 

       ► memory referee

 

       ► value

 

       ► none of the given options.



 

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

 

 

 A pointer variable can be,

 

       ► Decremented

 

       ► Incremented

 

       ► Multiplied

 

       ► Both Decremented and Decremented



 

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

 

 

NULL value has been defined in ______ and _________ header files.

 

 

       ► strings.h and iostream.h

 

 

       ► ctype.h and conio.c

 

 

       ► conio.c and conio.h

 

 

       ► stdlib.h and stddef.h

 

 



 

Question No: 24      ( 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: 25      ( Marks: 1 ) - Please choose one

 

 

"setprecision" manipulator will set

 

       ► The number of digits after the decimal point

 

       ► The number of digits before the decimal point

 

       ► The number of digits in a number

 

       ► None of the given options



 

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

 

 

Which of the following option will be true, if we overload "-=" operator?

 

 

 

 

 

       ► only - operator needs to be overloaded

 

       ► Minus (-) and = operators need to be overloaded

 

       ► the -= operator need to be overloaded explicitly

 

       ► the - and = operators need to be overloaded implicitly



 

Question No: 27      ( Marks: 2 )

 

 

Suppose there is a template function ‘func’ having argument of type U and return type T. What will be the C++ syntax to call this function, passing a variable ‘x’ of type double and returning an int type?

 

 

 

Question No: 28      ( Marks: 2 )

 

 

Which variable will be used in inner code block if we have the same names of variable at outer code block and inner code block?

 

 

 

Question No: 29      ( Marks: 2 )

 

 

What is the benefit of reference and where can we use it?

 

 

 

Question No: 30      ( Marks: 2 )

 

 

Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator for the object d of type Date.

 

 

 

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 )

 

 

If the requested memory is not available in the system then what does calloc/malloc and new operator return?

 

 

 

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 )

 

 

What is difference between Unary and binary operators and how they can be overloaded?

 

 

 

Question No: 35      ( Marks: 5 )

 

 

Suppose we have the following class.

 

class Matrix

{

private:

int Elements[3][3];

};

 

Write the operator function of stream extraction operator (>>) for this class.

 

 

 

Question No: 36      ( Marks: 5 )

 

 

What is meant by user interface and class interface in C++ ? And what role a class interface can play in user interface [Marks 5]

 

MY PAPER OF CS 201

 (DATE 18JULY2011)

TOTAL 52 QUESTIONS

12 LONG AND 40 MCQ’S

AND  MOSTLY  MCQ’S ARE NOT FROM PAST PAPERS, ITS FROM LAST CHAPTERS… L

Q: 41:  Write a program with different variables V1 and V2 and print out it (hexadecimal, decimal, octal) form use one manipulator.   5 marks ..

Q:42: What is structure and union structure? 3 marks.

Q:43: What is template and write general syntax   of templates. 3marks..

Q:44: How many types of structure? 2 marks

Q:45: Write the rules for using of Dynamic memory allocations…  5marks..

Page 479

Q:46: Describe the first parameter to stream insertionand stream extraction>> operator function?  2marks

Q:47: See the following code segment 

Template <class T>

Class myclass

{

Private :

Tx;

Public

Myclass(ta)

{

X=a;

};

 Write the main function which creates  two  objects  of class for int & double types?

Q:48: If the requested memory is not available in the system then what does calloc/malloc and new operator

return?  3marks …

 

Q:49,  Q:50, Q:51 and Q:52 are not in my mind, These Question are from Lecture number 40 to 45….

 

 

 

 

FINALTERM  EXAMINATION

Spring 2010

CS201- Introduction to Programming

Ref No:

Time: 90 min

Marks: 58

Student Info

Student ID:

 

 

Center:

 

 

Exam Date:

 

 

 

 

For Teacher's Use Only

Q No.

1

2

3

4

5

6

7

8

Total

Marks

      

      

      

      

      

      

      

      

      

Q No.

9

10

11

12

13

14

15

16

 

Marks

      

      

      

      

      

      

      

      

      

Q No.

17

18

19

20

21

22

23

24

 

Marks

      

      

      

      

      

      

      

      

      

Q No.

25

26

27

28

29

30

31

32

 

Marks

      

      

      

      

      

      

      

      

      

Q No.

33

34

35

36

 

 

 

 

 

Marks

      

      

      

      

      

      

      

      

      

 

 

 

 

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?

 http://vustudents.ning.com/

 

 

       ► The current function of the class

 

 

       ► The current pointer of the class

 

 

       ► The current object of the class

 

 

       A value of the data member

 



 

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

 

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

 

 

 

       ► Read a string from keyboard

 

 

       Read a character from keyboard

 

 

       ► Read a string from file

 

 

       ► Read a character from file

 



 

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

 When we do dynamic memory allocation in the constructor of a class, then it is necessary to provide a destructor. http://vustudents.ning.com/

 

 

 

       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 http://vustudents.ning.com/

 

       ► 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 <iostream.h>

 

       ► include <iostream.h>

 

       ► #include <iostream.h>



 

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? http://vustudents.ning.com/

 

 

       ► *ptr = arr ; 

 

 

       ► ptr = arr ;

 

 

       *ptr = arr[5] ;

 

 

       ► ptr = arr[5] ; 

 

 



 

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

 

 

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

 

 

       ► ptr[3]

 

       ► (ptr+3)

 

       ► *(ptr+3)

 

       ► Both 1and 3



 

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

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

 

 

       True

 

       ► False



 

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

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

http://vustudents.ning.com/

 

 

 

       ► 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. http://vustudents.ning.com/

 

 

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

http://vustudents.ning.com/

 

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 

 

 

Question No: 31      ( Marks: 3 )

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

1)         Matrix m1 (m2);

2)         Matrix m1, m2;

m1 = m2;

3)         Matrix m1 = m2;

 

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 <class T>
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 <iostream>

#include <iomanip>

 

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;

http://vustudents.ning.com/

  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 <iostream.h>

math

{

mth operator + (obj1,obj2)

mth operator + (obj1,obj2)

{

 mth operator + (obj1,obj2)

mth operator + (obj1,obj2)

 

}

}

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

FINALTERM  EXAMINATION

Spring 2010

CS201- Introduction to Programming

Ref No: xxxxxxx

Time: 90 min

Marks: 58

Student Info

Student ID:

bcxxxxxxxxx

 

Center:

OPKST

 

Exam Date:

09-08-2001

 

 

 

For Teacher's Use Only

Q No.

1

2

3

4

5

6

7

8

Total

Marks

      

      

      

      

      

      

      

      

      

Q No.

9

10

11

12

13

14

15

16

 

Marks

      

      

      

      

      

      

      

      

      

Q No.

17

18

19

20

21

22

23

24

 

Marks

      

      

      

      

      

      

      

      

      

Q No.

25

26

27

28

29

30

31

32

 

Marks

      

      

      

      

      

      

      

      

      

Q No.

33

34

35

36

 

 

 

 

 

Marks

      

      

      

      

      

      

      

      

      

 

 

 

 

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 replaced

 

 

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

 

 

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

 

 

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

 

 

 

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

 

 

FINALTERM  EXAMINATION

Spring 2010

CS201- Introduction to Programming

Ref No: 1555950

Time: 90 min

Marks: 58

Student Info

Student ID:

 

 

Center:

 

 

Exam Date:

 

 

 

 

For Teacher's Use Only

Q No.

1

2

3

4

5

6

7

8

Total

Marks

      

      

      

      

      

      

      

      

      

Q No.

9

10

11

12

13

14

15

16

 

Marks

      

      

      

      

      

      

      

      

      

Q No.

17

18

19

20

21

22

23

24

 

Marks

      

      

      

      

      

      

      

      

       

Q No.

25

26

27

28

29

30

31

32

 

Marks

      

      

      

      

      

      

      

      

      

Q No.

33

34

35

36

 

 

 

 

 

Marks

      

      

      

      

      

      

      

      

      

 

 

 

 

Question No: 1   http://vustudents.ning.com  ( Marks: 1 ) - Please choose one

 

 

If it is required to copy an array to another array then,

 

       ► Both arrays must be of the same size and data type

 

       ► Both arrays may be of different size

 

       ► Both arrays may be of different data type

 

       ► Both arrays may be of different size and type



 

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

 

 

Dealing with structures and functions passing  by reference is the most economical method

 

 

       ► True

 

       ► False



 

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

 

 

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

 

       ► True

 

       ► False



 

Question No: 4      ( Marks: 1 ) http://vustudents.ning.com- 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: 5      ( Marks: 1 ) - Please choose one

 

 

When new operator is overloaded at global level then corresponding built-in new operator will not be visible to whole of the program.

 

 

       ► True

 

       ► False



 

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

 

 

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?

 

       ► parentheses ( )

 

       ► braces { }

 

       ► brackets [ ]

 

       ► arrows < >



 

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

 

 

The return type of a function that do not return any value must be  ________

 

http://vustudents.ning.com

       ► float

 

       ► int

 

       ► void

 

       ► double



 

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

 

 

UNIX has been developed in ________ language.

 

       ► JAVA

 

       ► B

 

       ► C

 

       ► FORTRAN



 

Question No: 9      ( 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: 10      ( 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: 11      ( Marks: 1 ) - Please choose one

 

 

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

 

http://vustudents.ning.com

 

 

       ► Non-member function of class

 

       ► Member function of class

 

       ► Friend function of class

 

       ► None of the given options



 

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

 

 

The endl and flush are _______

 

 

 

 

 

 

       ► Functions

 

       ► Operators

 

       ► Manipulators

 

       ► Objects



 

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

 

 

If a symbolic constant has been defined, it will be an error to define it again.

 

       ► True

 

       ► False



 

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

 

 

The operator used for casting, in C, is standard ________ operator.

 

       ► none of the given options.

 

       ► cast

 

       ► cost

 

       ► const



 

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

 

 

Constructors can not be overloaded like ordinary functions.

 

       ► True

 

       ► False



 

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

 

 

Which of the following function call is correct for the function prototype?

defaultParameters ( int a, int b = 7, char z = ‘*’ );

 

 

       ► defaultParameters (5);

 

 

       ► defaultParameters (5, ‘8’);

 

 

       ► defaultParameters (6, ‘#’);

 

 

       ► defaultParameters (0, 0, ‘*’, 0);

 



 

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

 

 

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: 18      ( Marks: 1 ) - Please choose one

 

 

We can not define a variable of user-defined data type in the class.

 

 

       ► True

 

       ► False



 

Question No: 19     http://vustudents.ning.com ( Marks: 1 ) - Please choose one

 

 

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: 20      ( Marks: 1 ) - Please choose one

 

 

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

 

       ► float

 

       ► int

 

       ► char

 

       ► none of the given options.



 

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

 

 

Class is a user defined___________.

 

       ► data type

 

       ► memory referee

 

       ► value

 

       ► none of the given options.



http://vustudents.ning.com

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

 

 

 A pointer variable can be,

 

       ► Decremented

 

       ► Incremented

 

       ► Multiplied

 

       ► Both Decremented and Decremented



 

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

 

 

NULL value has been defined in ______ and _________ header files.

 

 

       ► strings.h and iostream.h

 

 

       ► ctype.h and conio.c

 

 

       ► conio.c and conio.h

 

 

       ► stdlib.h and stddef.h

 

 



 

Question No: 24      ( Marks: 1 ) http://vustudents.ning.com- 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: 25      ( Marks: 1 ) - Please choose one

 

 

"setprecision" manipulator will set

 

       ► The number of digits after the decimal point

 

       ► The number of digits before the decimal point

 

       ► The number of digits in a number

 

       ► None of the given options



 

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

 

 

Which of the following option will be true, if we overload "-=" operator?

 

 

 

 

 

       ► only - operator needs to be overloaded

 

       ► Minus (-) and = operators need to be overloaded

 

       ► the -= operator need to be overloaded explicitly

 

       ► the - and = operators need to be overloaded implicitly



 

Question No: 27      ( Marks: 2 )

 

 

Suppose there is a template function ‘func’ having argument of type U and return type T. What will be the C++ syntax to call this function, passing a variable ‘x’ of type double and returning an int type?

 

 

 

Question No: 28      ( Marks: 2 )

 

 

Which variable will be used in inner code block if we have the same names of variable at outer code block and inner code block?

 

 

 

Question No: 29      ( Marks: 2 )

 

 

What is the benefit of reference and where can we use it?

 

 

 

Question No: 30      ( Marks: 2 )

 

 

Write the C++ code for the declaration of overloaded stream insertion and stream extraction operator for the object d of type Date.

 

 

 

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 )

 

 

If the requested memory is not available in the system then what does calloc/malloc and new operator return?

 

 

 

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 )

 

 

What is difference between Unary and binary operators and how they can be overloaded?

 

 

 

Question No: 35      ( Marks: 5 )

 

 

Suppose we have the following class.

 

class Matrix

{

private:

int Elements[3][3];

};

 

Write the operator function of stream extraction operator (>>) for this class.

 

http://vustudents.ning.com

 

Question No: 36      ( Marks: 5 )

 

 

What is meant by user interface and class interface in C++ ? And what role a class interface can play in user interface [Marks 5]

 

RSS

© 2020   Created by +M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service

.