Saturday, October 6, 2012
Saturday, September 15, 2012
CS 201 Quize
CS201 – Introduction to Programming
First Quiz
suppose we have int y[10]; To access the 4th element of the array we write_______
y[4];
y[3];
y[2];
none of given
From the following; which one is the range of Random number generator function rand()?
0 – 32768
1 – 32768
0 – 32767
1 – 32767
From following; which one is the correct syntax of an array initialize: Array size is 10 and it is of double data type to value 0?
arr[10] = {0.0};
double arr[10]= 0.0;
double arr[10] = {0.0};
double arr[] = 0.0;
The string in the array is terminated by a _____
zero
nil
null
one
y[4];
y[3];
y[2];
none of given
From the following; which one is the range of Random number generator function rand()?
0 – 32768
1 – 32768
0 – 32767
1 – 32767
From following; which one is the correct syntax of an array initialize: Array size is 10 and it is of double data type to value 0?
arr[10] = {0.0};
double arr[10]= 0.0;
double arr[10] = {0.0};
double arr[] = 0.0;
The string in the array is terminated by a _____
zero
nil
null
one
In C/C++; by default arguments are passed by _____ to a function.
Reference
Value
Type
Data
1
char name [] = “Hello World” ; In the above statement, a memory of _______ characters will be allocated
13
11
12
10
_______ Keyword is used to return some value from a function.
break
return
continue
goto
Which of the function call is call by value for the following function prototype? float add(int);
add(&x);
add(x);
add(int x);
add(*x);
The increment of a pointer depends on its_________.
variable
10
_______ Keyword is used to return some value from a function.
break
return
continue
goto
Which of the function call is call by value for the following function prototype? float add(int);
add(&x);
add(x);
add(int x);
add(*x);
The increment of a pointer depends on its_________.
variable
value
data type
None of the given
The ASCHI code of null character is_________
000
010
111
110
data type
None of the given
The ASCHI code of null character is_________
000
010
111
110
Pointers are a special type of __________in which a memory address is stored
Select correct option:
variables
Location
Characters
None of the given
Select correct option:
variables
Location
Characters
None of the given
just for copy paste
Transpose of a matrix means that when we interchange rows and columns_____________
Select correct option:
the first row becomes the Last column
the first row becomes the first column
the Last row becomes the first column
the first column becomes the first row
Select correct option:
the first row becomes the Last column
the first row becomes the first column
the Last row becomes the first column
the first column becomes the first row
Pointers store the ____________________
Select correct option:
value of a variable
memory address
characters
None of the given
Select correct option:
value of a variable
memory address
characters
None of the given
Which of the following function call is “call by reference” for the following function prototype? int add (int *);
Select correct option:
add(&x);
add(int x);
add(x);
add(*x);
Select correct option:
add(&x);
add(int x);
add(x);
add(*x);
The name of the array is a constant pointer which contains the memory address of the ____________of the array.
Select correct option:
first element
Last element
second element
None of the given
Select correct option:
first element
Last element
second element
None of the given
array name always contains the memory address of the ___________of the array
Select correct option:
entire elements
last element
first element
None of the given
Select correct option:
entire elements
last element
first element
None of the given
At the___________, we try to break up the problem into functional units
Select correct option:
analysis phase
design phase
Implementation phase
None of the given
Select correct option:
analysis phase
design phase
Implementation phase
None of the given
5.2 Q1: Which of the following does counter-controlled repetition require?
A condition that tests for the final value.
Counter-controlled repetition requires all of the above.
An increment or decrement by which the control variable is modified each time through the loop.
An initial value.
5.2 Q2: The statement
while ( --counter >= 1 )
counter % 2 ? cout << "A" : cout << "B";
cannot be rewritten as:
while ( --counter >= 1 )
if ( counter % 2 )
cout << "A";
else
cout << "B";.
while ( counter >= 1 )
if ( counter % 2 )
cout << "A";
else
cout << "B";.
--counter;
while ( --counter >= 1 )
counter % 2 == 0 ? cout << "B" : cout << "A";.
while ( counter > 1 )
{
--counter;
if ( counter % 2 )
cout << "A";
else
cout << "B";
}.
5.2 Q3: Which of the following is a bad programming practice?
Using floating-point values for counters in counter-controlled repetition.
Indenting the statements in the body of each control structure.
Nesting multiple repetition structures one within another.
Placing vertical spacing above and below control structures.
Section 5.3 for Repetition Statement
5.3 Q1: If a variable is declared in the initialization expression of a for structure, then:
It can not be used in any structures that are nested in that for structure.
It retains its final value after the loop is finished.
The scope of the variable is restricted to that particular for loop.
It is automatically reinitialized to zero once the loop is finished.
5.3 Q2: Which of the following is not true?
The initialization and increment expressions can be comma-separated lists.
You must declare the control variable outside of the for loop.
The three expressions in the for structure are optional.
A for loop can always be used to replace a while loop, and vice versa.
5.3 Q3: Consider the execution of the following for loop
for (int x = 1; x < 5; increment )
cout << x + 1 << endl;
If the last value printed is 5, which of the following might have been used for increment?
Any of the above.
x += 1.
a. x++.
++x.
Section 5.4 Examples Using the for Statement
5.4 Q1: Which of the following for headers is not valid?
for ( int i = 0; i < 10; i++ ).
int i = 0;
for ( ; i < 10; i++ ).
for ( int i = 0; int j = 5; ; i++ ).
for ( int i = 0: i < 10; ).
A Caution about Using Type double for Monetary Amounts
5.4 Q2: float and double variables should be used:
To perform monetary calculations.
To store true/false values.
As imprecise representations of decimal numbers.
As counters.
Using Stream Manipulators to Format Numeric Output
5.4 Q3: Which of the following is a parameterized stream manipulator used to format output?
setw.
right.
left.
fixed.
Section 5.5 do…while Repetition Statement
5.5 Q1: If a do…while structure is used:
Counter-controlled repetition is not possible.
The body of the loop will execute at least once.
An infinite loop will not take place.
An off-by-one error will not occur.
5.5 Q2: What will the following program segment do?
int counter = 1;
do {
cout << counter << " ";
} while ( ++counter <= 10 );
Cause a syntax error.
Print the numbers 1 through 11.
Print the numbers 1 through 9.
Print the numbers 1 through 10.
Section 5.6 switch Multiple-Selection Statement
5.6 Q1: A switch statement should be used:
As a multiple-selection structure.
As a single-selection structure.
To replace all if and if…else statements.
As a double-selection structure.
5.6 Q2: In a switch structure:
A default case is required.
A break is required after each case.
A break is required after the default case.
Multiple actions do not need to be enclosed in braces.
5.6 Q3: Which of the following is correct when labeling cases in a switch structure?
Case1.
Case 1.
case1.
case 1.
5.6 Q4: switch can be used to test:
all types of constants.
int constants.
string constants.
float constants.
5.6 Q5: Which of the following data types can be used to represent integers?
long.
short.
char.
All of the above.
Section 5.7 break and continue Statements
5.7 Q1: Which of the following is False?
break statements exit from the loop in which they are embedded.
continue statements skip the remaining statements in current iteration of the body of the loop in which they are embedded.
continue and break statements may be embedded within all C++ structures.
break and continue statements alter the flow of control.
5.7 Q2: Which of the following is False?
Many programmers feel that break and continue violate structured programming.
The effects of break and continue statements can be achieved by structured programming techniques.
You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.
break and continue statements can perform faster than their corresponding structured techniques.
Section 5.8 Logical Operators
5.8 Q1: In C++, the condition ( 4 > y > 1 ):
Evaluates correctly and could be replaced by ( 4 > y && y > 1 ).
Does not evaluate correctly and should not be replaced by ( 4 > y && y > 1 ).
Does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ).
Evaluates correctly and could not be replaced by ( 4 > y && y > 1 ).
5.8 Q2: The OR (||) operator:
Stops evaluation upon finding one condition to be true.
Associates from right to left.
Has higher precedence than the AND (&&) operator.
Is a ternary operator.
5.8 Q3: An operator that associates from right to left is:
().
!=.
?:.
,.
5.8 Q4: The expression if ( num != 65 ) cannot be replaced by:
if ( !( num == 65 ) ).
if ( num > 65 || num < 65 ).
d. if ( !( num – 65 ) ).
if ( num – 65 ).
5.8 Q5: An example of a unary operator is:
The < relational operator.
The = assignment operator.
The % arithmetic operator.
The ! logical operator.
Section 5.9 Confusing Equality (==) and Assignment (=) Operators
5.9 Q1: Variables are also known as:
rvalues, and cannot be used as lvalues.
lvalues, but can be used as rvalues.
Constant variables.
lvalues, and cannot be used as rvalues.
5.9 Q2: Consider the following code, assuming that x is an int with an initial value of 12
if( x = 6 )
cout << x;
What is the output?
12.
6.
A syntax error is produced.
Nothing.
5.9 Q3: Of the following, which is not a logic error?
Failing to initialize counter and total variables before the body of a loop.
Not placing curly braces around the body of an if that contains two statements.
Using commas instead of the two required semicolons in a for header.
Using == to assign a value to a variable.
Section 5.10 Structured Programming Summary
5.10 Q1: The ____________, __________ and ____________ are the only three forms of control necessary.
break, continue, if…else.
sequence, selection, repetition.
switch, if, else.
for, while, do…while.
5.10 Q2: Which of the following is not one of the C++ control structures?
if.
switch.
do…while.
main.
5.10 Q3: Which of the following is not one the rules for forming structured programs?
Any action state can be replaced by any control statement.
Any transition arrow can be reversed.
Begin with the “simplest activity diagram.”
Any action state can be replaced by two action states in sequence
Section 5.11 (Optional) Software Engineering Case Study: Identifying Objects’ States and Activities in the ATM System
5.11 Q1: Which of the following is not a part of a UML state diagram?
A solid circle indicating the initial state.
Arrows with accompanying event description text representing transitions.
Rounded rectangles representing states.
Fractions beside each state indicating the likelihood of entering that state.
5.11 Q2: An activity diagram for modeling the actions involved in executing a balance inquiry transaction using the BalanceInquiry object should not include:
Retrieving the user’s balance information from the database of accounts.
All of the above actions should be modeled in this activity diagram.
Receiving the user’s main menu input indicating a desire to inquire the amount of his or her balance.
Displaying the user’s balance information on the screen.
Question No: 1 ( Marks: 1 ) - Please choose one
Compiler is a
► System software
► Application Software
► Driver
► Editor
Question No: 2 ( Marks: 1 ) - Please choose one
Operating System is
► An application software
► System Software
► Computer Language
► Interpreter
Question No: 3 ( Marks: 1 ) - Please choose one
Which one is the correct syntax for defining an identifier PI with preprocessor directive?
► #define PI 3.1415926;
► #define PI 3.1415926
► #define PI = 3.1415926 ;
► #define PI = 3.1415926
Question No: 4 ( Marks: 1 ) - Please choose one
Character strings are arrays of characters that can store
► Only one character
► Limited number of characters
► Number of characters specified.
► None of the given option
Question No: 5 ( Marks: 1 ) - Please choose one
Which of the following is NOT a preprocessor directive?
► #error
► #define
► #line
► #ndefine
Question No: 6 ( 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: 7 ( Marks: 1 ) - Please choose one
Let suppose int a, b, c, d, e;, a = b = c = d = e = 42;
This can be interpreted by the complier as:// assignment is right-associative.
► a = (b = (c = (d = (e = 42))));
► (a = b = (c = (d = (e = 42))));
► a = b = (c = (d = (e = 42)));
► (a = b) = (c = d) = (e = 42);
Question No: 8 ( Marks: 1 ) - Please choose one
Friend function of a class is ______________ .
► Member function
► Non-member function
► Private function
► Public function
Question No: 9 ( Marks: 1 ) - Please choose one
Function implementation of friend function must be defined outside the class.
► True
► False
Question No: 10 ( Marks: 1 ) - Please choose one
When we define an array of objects then,
► Constructor will be called once for whole array
► Constructor will be called for each object of the array
► Constructor will never call
► Depends on the size of array
Question No: 11 ( Marks: 1 ) - Please choose one
The stream objects cin and cout are included in which header file?
► iostream.h
► fstream.h
► istream.h
► ostream.h
Question No: 12 ( Marks: 1 ) - Please choose one
What is the sequence of event(s) when allocating memory using new operator?
► Only block of memory is allocated for objects
► Only constructor is called for objects
► Memory is allocated first before calling constructor
► Constructor is called first before allocating memory
Question No: 13 ( Marks: 1 ) - Please choose one
► Logical error
► Syntax error
► Runtime error
► None of the given options
Question No: 14 ( Marks: 1 ) - Please choose one
An array stores the numbers into consecutive memory locations.
► True
► False
Question No: 15 ( Marks: 1 ) - Please choose one
The template functions do NOT promote the code reuse
► True
► False
Question No: 16 ( Marks: 1 ) - Please choose one
What will be the correct syntax for initialization of pointer ptr of type int with variable x?
► int ptr = &x ;
► int ptr = x ;
► int *ptr = &x ;
► int ptr* = &x ;
Question No: 17 ( Marks: 1 ) - Please choose one
Which of the following function calling mechanism is true for the function prototype given below?
float func(float &);
► Call by value
► Call by reference using pointer
► Call by reference using reference variable
► None of the given options
Question No: 18 ( Marks: 1 ) - Please choose one
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: 19 ( Marks: 1 ) - Please choose one
Which of the following object(s) will call the member operator function within the statement given below?
obj1=obj2+obj3;
► Object obj1
► Object obj2
► Object obj3
► Any of the object
Question No: 20 ( Marks: 1 ) - Please choose one
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: 21 ( Marks: 1 ) - Please choose one
The static data members of a class will be ________
► shared by objects
► created for each object
► initialized within class
► initialized within main function
Question No: 22 ( Marks: 1 ) - Please choose one
Which of the following function cannot be overloaded?
► Member functions
► Utility functions
► Constructor
► Destructor
Question No: 23 ( Marks: 1 ) - Please choose one
The region of memory, available for allocation at run time in C language is called ________ memory whereas in C++ language is called as ________________.
► Heap, Stack
► Stack, Free Store
► Heap, Free Store
► None of above
Question No: 24 ( Marks: 1 ) - Please choose one
A variable which is defined inside a function is called
► Automatic variable
► Global variable
► Functional variable
► None of the given option
Question No: 25 ( Marks: 1 ) - Please choose one
The default copy constructor provides member wise assignment.
► True
► False
Question No: 26 ( Marks: 1 ) - Please choose one
The code is written to __________ the program.
► implement
► design
► analysis
► none of the given options.
Question No: 27 ( 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: 28 ( Marks: 1 ) - Please choose one
To avoid dangling reference, always return the reference of a local variable from a function.
► True
► False
Question No: 29 ( Marks: 1 ) - Please choose one
Analysis is the -------------- step in designing a program.
► Last
► Middle
► Post Design
► First
Question No: 30 ( 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: 1 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
Array is a data structure which store
► Memory addresses
► Variables
► Data Type
► Data
Question No: 4 ( Marks: 1 ) - Please choose one
We can also create an array of user define data type.
► True
► False
Question No: 5 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
What is the sequence of event(s) when allocating memory using new operator?
► Only block of memory is allocated for objects
► Only constructor is called for objects
► Memory is allocated first before calling constructor
► Constructor is called first before allocating memory
Question No: 7 ( Marks: 1 ) - Please choose one
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 ( 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
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 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
What does STL stand for?
► Source template library
► Standard template library
► Stream template library
► Standard temporary library
Question No: 12 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
new and delete are _____ whereas malloc and free are _____.
► Functions, operators
► Classes, operators
► Operators, functions
► Operators, classes
Question No: 15 ( Marks: 1 ) - Please choose one
Friend functions are _____ of a class.
► Member functions
► Public member functions
► Private member functions
► Non-member functions
Question No: 16 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
Which one of the following is the declaration of overloaded pre-increment operator implemented as member function?
► Class-name operator +() ;
► Class-name operator +(int) ;
► Class-name operator ++() ;
► Class-name operator ++(int) ;
Question No: 19 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
We can also do conditional compilation with preprocessor directives.
► True
► False
Question No: 21 ( Marks: 1 ) - Please choose one
The programs, in which we allocate static memory, run essentially on ________
► Heap
► System Cache
► None of the given options
► Stack
Question No: 22 ( 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: 23 ( 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: 24 ( 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: 25 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
Assignment operator is used to initialize a newly declared object from existing object.
► True
► False
Question No: 27 ( 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: 28 ( Marks: 1 ) - Please choose one
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 ( Marks: 1 ) - Please choose one
new operator allocates memory from free store and return _____________.
► A pointer
► A reference
► An integer
► A float
Question No: 30 ( Marks: 1 ) - Please choose one
"new" and "delete" keywords are _____________ in C++ language.
► Built-in- Function
► Operators
► Memory Allocation Function
► None of the given options
Subscribe to:
Posts (Atom)