cs201 MID Term 2012 Papers
cs201 MID Term 2012 Papers
com
www.facebook.com/Vuplanet
Follow us on Facebook
CS201 MID Term 2012 & 2011 SOLVED MCQS
(MN. Date 26 , 10am)
Explain the logic of each statement of the given code segment.
Write a program which prompts the user to enter 10 elements of type int and stores them
into an array. Program should display only those elements whose indices are divisible by
2.
Hint: Use pointer to display the array elements whose indices are divisible by 2. (05)
Write the code for a structure called Inventory having the following elements:
A character array named partName
An integer named partNumber
An integer named stock.
(03)
Which one of the following is the better approach in terms of memory space occupation
and why ?
Write a statement for opening file trans.txt for input; using an ifstream object called
inTransaction. (02)
Write the code to access the element at third row and second column of a 2D array uses pointer
named arrayptr . (02)
MCQS
Syntax of a union is identical to __________ .
structure
Class
Function
Oop
A union is a user-defined data type that contains only _______from its list of members at a
time.
www.vuplanet.com
www.vuplanet.com
one object
two objects
three objects
four objects
Which of the given file handling modes are similar in their functionality ?
ios::out, ios::trunk
ios::trunc, ios::ate
ios::trunc, ios::nocreate
ios::trunc, ios::ate
Which one of the given option is not a mode for reading/writing the data from a file?
In
Out
Trunk
Get
A 2D array multi[5][10] can be accessed using the array name as **multi , this technique is
called __________.
Single referencing
Single dereferencing
Double referencing
Double dereferencing
The __________ statement forces the immediate next iteration of the loop.
Switch
Goto
Continue
Break
www.vuplanet.com
www.vuplanet.com
Operators
Loops
Functions
Variables
___________ executes all the lines before error and stops at the line which contains the error.
Intrepreter
Compiler
Linker
Debugger
Middle
Post design
First
Last
Which of the following is the correct function call, having array named student of 10
elements as a parameter?
addRecord(student[]);
addRecord(student);
addRecord(student[10]);
addRecord(*student);
What is the correct syntax to declare an array of size 10 of int data type?
int [10] name ;
name[10] int ;
int name[10] ;
int name[] ;
www.vuplanet.com
www.vuplanet.com
Which of the following is the correct syntax to print multiple values or variables in a single
command using cout?
cout << "H" << x << "\n";
cout << "Hello" + x + "\n";
cout << "H", x, "\n";
cout << ("H" & x & "\n");
Arithmatic Expression
Constant Expression
Boolean Expression
Primary Expression
www.vuplanet.com
www.vuplanet.com
If condition
is true
Then Process
if-else structure
else-if structure
switch structure
if structure
2ND PAPER
Write the code for defining a structure Triangle with variables base, altitude and
hypotenuse are the structure members. (05)
Write a code which reads a string not greater than 20 characters from keyboard, stores it
in an array and displays it on the screen. (05)
Given below is the code segment of a file handling program. What is purpose of the
condition given in the while loop ?
while (!inFile.eof())
{
inFile >> name >> sal >> dept;
cout << name << "\t" << sal << " \t" << dept << endl;
}
(03)
Identify the error in the given code segment and explain the reason for error.
main()
www.vuplanet.com
www.vuplanet.com
{
int num1[5] = {5,8,3,6,9};
int *ptr;
ptr = num1;
num1++;
return 0;
}
(03)
Which standard library must be included in a program to perform file read and write
operations? (02)
MCQS
Stream which sends data to the program is called _________.
Input stream
Output stream
Inline stream
Function stream
When accessing a structure member, the identifier to the left of the dot operator is the
name of ______________.
a structure member
a structure tag
a structure variable
the keyword struct
www.vuplanet.com
www.vuplanet.com
a boolean variable
an integer variable
a character string
______ translates high level language program into machine language code.
Compiler
Linker
Debugger
Editor
From the option given below, what will be the correct output of the code?
If the return type of a function is void then it means that it will _________.
return any type of data
return some specific type of data
return no data
return just character data
The functions that have already been defined as a part of the language are called
___________.
user-defined functions
programmer-defined functions
inner funtions
built-in functions
Given that doubleArray is an array of 7 integers. Which of the below is the correct
statement to access the 5th element of the array?
doubleArray[7]
www.vuplanet.com
www.vuplanet.com
doubleArray[4]
doubleArray{7}
doubleArray(4)
In ________, the first pointer stores the address of the some other pointer, which contains the
address of any variable.
single dereference
double dereference
single reference
double reference
Bad Programming
Necessary
Good Programming
Not a necessary
www.vuplanet.com
www.vuplanet.com
Which looping process checks the test condition at the end of the loop?
For
While
do-while
no looping process checks the test condition at the end
You can use a _________ statement to transfer control elsewhere out of the nested structure.
Continue
Goto
Pause
Break
Which of the following array is the most suitable for storing a matrix structure?
Single-dimensional array
Two-dimensional array
Three-dimensional array
Four-dimensional array
Write a C/C++ program which defines an array of 15 elements. This program changes all
uppercase letters of an array into lowercase letters and all lowercase letters to uppercase
using character handling functions. (05)
main()
{
char province[] = "Sindh";
char s[80];
strcpy(s, "Hyderabad");
strcat(s, province);
cout << s;
(03)
}
(03)
What happens if we open an existing file using the default output mode and write the data
into the file ? (02)
A two-dimensional array has 3 rows and 4 columns. Write down the syntax to initialize
first element of all three rows of two-dimensional array with value 2. (02)
A union is a user-defined data type that contains only _______from its list of members at
a time.
one object
two objects
three objects
four objects
In C/C++, ___________ are the doors through which data can enter and come out of a
program.
www.vuplanet.com
www.vuplanet.com
Streams
Fields
Variables
Header files
Which one of the given option is not a mode for reading/writing the data from a file?
In
Out
Trunk
Get
Bits
Bytes
Numbers
Words
In 2D array, the technique used to access the array elements is called ___________
Single referencing
Double referencing
Double dereferencing
Single dereferencing
From the options given below, identify the correct option which is used for calling the
function float square (int &);
Identify the correct option which is used for calling the function float area (int).
area(&num) ;
area(num) ;
area(int num) ;
area(*num) ;
Which kind of error occurs in the code below to access the variable num in the main
function?
www.vuplanet.com
www.vuplanet.com
int main(){
int x ;
x = num ;
}
Syntax error
Logical error
main(){
int a = 10 ;
int b =0;
int *x = &a;
b = (*x)+3 ;
cout << a << “, ” << b ;
}
10,0
10,3
10,13
0,13
When the logical operator AND (&&) combines two expressions exp1 and exp2 then the
result will be true only ____________
When both exp1 and exp2 are true
When both exp1 and exp2 are false
When exp1 is true and exp2 is false
www.vuplanet.com
www.vuplanet.com
For which array, the size of the array should be one more than the number of elements in
an array?
int
double
float
char
To assigned a value to a character type variable, ________ are used around the value.
parenthesis ( )
single qoutes ' '
double qoutes " "
curly braces { }
Rectangle
Circle
www.vuplanet.com
www.vuplanet.com
Diamond
Arrow
What will be the correct syntax for initialization of pointer ptr of type int with variable x?
int ptr = &x ;
int ptr = x ;
Write a program which prompts the user to enter 10 elements of type int and stores them
into an array. Program should display only those elements whose indices are divisible by
2.
Hint: Use pointer to display the array elements whose indices are divisible by 2. (05)
Write the code for a structure called Inventory having the following elements:
A character array named partName
An integer named partNumber
An integer named stock.
(03)
Which one of the following is the better approach in terms of memory space occupation
and why ?
Write a statement for opening file trans.txt for input; using an ifstream object called
inTransaction. (02)
Write the code to access the element at third row and second column of a 2D array uses pointer
named arrayptr . (02)
MCQS
Syntax of a union is identical to __________ .
structure
www.vuplanet.com
www.vuplanet.com
Class
Function
Oop
A union is a user-defined data type that contains only _______from its list of members at a
time.
one object
two objects
three objects
four objects
Which of the given file handling modes are similar in their functionality ?
ios::out, ios::trunk
ios::trunc, ios::ate
ios::trunc, ios::nocreate
ios::trunc, ios::ate
Which one of the given option is not a mode for reading/writing the data from a file?
In
Out
Trunk
Get
2nd paper
Write the code for defining a structure Triangle with variables base, altitude and
hypotenuse are the structure members. (05)
Write a code which reads a string not greater than 20 characters from keyboard, stores it
in an array and displays it on the screen. (05)
Given below is the code segment of a file handling program. What is purpose of the
condition given in the while loop ?
while (!inFile.eof())
{
inFile >> name >> sal >> dept;
cout << name << "\t" << sal << " \t" << dept << endl;
}
(03)
www.vuplanet.com
www.vuplanet.com
Which standard library must be included in a program to perform file read and write
operations? (02)
MCQS
Stream which sends data to the program is called _________.
Input stream
Output stream
Inline stream
Function stream
When accessing a structure member, the identifier to the left of the dot operator is the
name of ______________.
a structure member
a structure tag
a structure variable
the keyword struct
www.vuplanet.com
www.vuplanet.com
______ translates high level language program into machine language code.
Compiler
Linker
Debugger
Editor
From the option given below, what will be the correct output of the code?
If the return type of a function is void then it means that it will _________.
return any type of data
return some specific type of data
return no data
return just character data
The functions that have already been defined as a part of the language are called
___________.
user-defined functions
programmer-defined functions
inner funtions
built-in functions
Given that doubleArray is an array of 7 integers. Which of the below is the correct
statement to access the 5th element of the array?
doubleArray[7]
doubleArray[4]
doubleArray{7}
doubleArray(4)
www.vuplanet.com
www.vuplanet.com
Data
Reference
Value
Data type
In ________, the first pointer stores the address of the some other pointer, which contains the
address of any variable.
single dereference
double dereference
single reference
double reference
Bad Programming
Necessary
Good Programming
Not a necessary
Which looping process checks the test condition at the end of the loop?
For
While
do-while
no looping process checks the test condition at the end
You can use a _________ statement to transfer control elsewhere out of the nested structure.
Continue
Goto
Pause
Break
www.vuplanet.com
www.vuplanet.com
Which of the following array is the most suitable for storing a matrix structure?
Single-dimensional array
Two-dimensional array
Three-dimensional array
Four-dimensional array
QUESTION:
Write down the output of the code given below?
#include <iostream>
using namespace std;
union Num
{
int ValueI;
float ValueF;
double ValueD;
char ValueC;
};
void main()
{
// Optional union keyword
// ValueI = 100
Num TestVal = {100};
cout<<"\nInteger = "<<TestVal.ValueI<<endl;
TestVal.ValueF = 2.123;
cout<<"Float = "<<TestVal.ValueF<<endl;
cout<<"Uninitialzed double = "<<TestVal.ValueD<<endl;
cout<<"Some rubbish???"<<endl;
TestVal.ValueC = 'U';
cout<<"Character = "<<TestVal.ValueC<<endl;
}
(05)
Write a program which declares and initializes an array of 10 integers and then displays
the 4th and 8th element of the array by using a pointer.
www.vuplanet.com
www.vuplanet.com
(05)
Perform left shift operation on a binary number 0101 and write the result in binary and
decimal.
(03)
Write the code for the declaration of a function named getMax which takes a 2D array of
integers(3x3 dimension) as its parameter and returns a double pointer to an integer.
(03)
Identify any logical or syntax error in the statement below and explain the reason of the error.
Write the code to access the element at third row and second column of a 2D array uses pointer
named arrayptr . (02)
MCQS:
An object of _________ class can be created for saving the current position of any opened file
before reading from the file
Filepos
Streampos
Stream
Filestream
The value returned by the eof() function is of __________ type.
Integer
Float
Character
Boolean
If a file is not properly closed in a program then what is the status of the program ?
Runtime error will be generated in the program
The program will terminate normally
Compiler will generate syntax error
The Program will crash
www.vuplanet.com
www.vuplanet.com
Each array declaration must provide the information about all these things except
__________.
___________ transfers the executable code from hard disk to main memory.
Linker
Loader
Editor
Interpreter
___________ operator is used to pass the address of a variable to the called function.
*
**
&&
&
www.vuplanet.com
www.vuplanet.com
Preprocessor program performs its function before ______ phase takes place.
Editing
Linking
Compiling
Loading
Which of the following is the correct function call, having array named student of 10
elements as a parameter?
addRecord(student[]);
addRecord(student);
addRecord(student[10]);
addRecord(*student);
Logical
Arithmetic
Relational
Conditional
Which of the following array is the most suitable for storing a matrix structure?
Single-dimensional array
Two-dimensional array
Three-dimensional array
Four-dimensional array
www.vuplanet.com
www.vuplanet.com
www.vuplanet.com