Sample Paper of CS201
Sample Paper of CS201
FINALTERM EXAMINATION
Fall 2022
CS201 – Introduction to Programming
Time: 90 min
Marks: 60
…………. function is used to determine the current location while reading a file.
A. tellp()
B. tellg()
C. seekp()
D. seekg()
A. ^
B. &&
C. ||
D. >>
int main(){
int i = 20;
for(int i=1;i<10;i++);
cout<<i;
return 0;
}
A. 10
B. 20
C. 9
D. 1
int main() {
change();
return 0;
}
int change (int a=12){
int b=12;
a = a + b;
cout<<a++;
}
A. 12
B. 24
C. 25
D. 26
While handling files in C++, the default mode of “ifstream” library for opening file is.
A. ios::ate
B. ios::out
C. ios::in
D. ios::app
In C++, “getline()” function is a built-in function that allows accepting and reading.
A. Single line
B. Multiple lines
C. Single and Multiple lines
D. Only multiword input
Question No: 7 (Marks: 01) - Please choose the correct option
struct book {
char title[20];
};
int main(){
book * sptr;
}
From the above code the correct way to access the data member title of the structure
book through pointer is?
A. sptr.title
B. sptr:title
C. sptr->title
D. .sptr*title
#include <iostream>
#define LIMIT 3
int main()
{
for (int i = 2; i < LIMIT; i++) {
std::cout << i* LIMIT << "\t";
}
return 0;
}
A. 6
B. 2 3 6
C. 3
D. 9
A. Static
B. Stack
C. Heap
D. Hard Disk
A. Attribute
B. Method
C. Instance
D. Dimensions
A. +
B. -
C. /
D. ->
Question No: 17 (Marks: 01) - Please choose the correct option
A class includes both data members as well as functions to manipulate the data. These
functions are called ___________.
A. Member functions
B. Constant functions
C. Rational functions
D. Memory functions
A. Data member
B. Constructor
C. Member function
D. Object
In friend function, which operator is utilized to access members of a class using class
objects.
A. ::
B. +
C. *
D. .
Which of the following is the correct way of referring a data member “buf” of a class
name “String”? Consider “buf” data member declared as a character pointer.
A. buf;
B. this->buf;
C. *(this).buf;
D. *this.buf
A. sizeof
B. ?:
C. ::
D. %
When a unary operator is overloaded and is a member of a class, how many arguments
need to be passed explicitly when it is called?
A. Zero
B. One
C. Two
D. Three
#include<iostream>
using namespace std;
class A
{
int a;
public:
A(int x):a(x){}
int geta() {return a;}
};
int main ()
{
A M(10),N(20);
N = M;
cout<<N.geta();
return 0;
}
A. 20
B. 10
C. 30
D. 15
A. endl
B. flush
C. ends
D. ws
A. 3.144
B. 3.143
C. 3.1436
D. 3.145
Question No: 26 (Marks: 01) - Please choose the correct option
A. ios::dec
B. ios::showpoint
C. ios::showcause
D. ios::right
If we press the key 1 from the keyboard to store it in integer i, the digit 1 travels as a(an)
_________ but stored as number inside i.
A. integer
B. character
C. float
D. double
In C++, whenever have an “&” ampersand symbol appears on right hand side of an “=”
assignment operator, it is taken as ______ of an object.
A. Pointer
B. Reference
C. Address
D. Function
While writing nested classes in C++, no memory is allocated for it unless a/an _______
of it is created.
A. Function
B. Instance
C. Class
D. Operator
In C++, which one from the following errors can be encountered when dealing with
references.
A. Memory Leak
B. Dangling Reference
C. Static Reference
D. Global Reference
A. Macros.
B. Inline function
C. Function overloading
D. Object Creation
The correct syntax for writing a template ‘class student’ of type ‘T’ is _____.
A. template <class T> class student { …. };
B. template <Class T> Class student{ …. };
C. Template <class T> class student { …. };
D. template <class student > class T { …. };
In C/C++, the array index number for representing last element of an array of size 10 is
_____.
A. 5
B. 7
C. 9
D. 11
A. 2
B. 4
C. 5
D. 6
int arr[]={2,5,6,8,9,10,6,3,1};
int * ptr= &arr[1];
cout<<*(ptr+4);
A. 6
B. 10
C. 3
D. 1
int arr[]={2,5,6,8,9,10,6,3,1};
int * ptr= &arr[3];
cout<<*(ptr+4);
A. 10
B. 6
C. 3
D. 5
Question No: 40 (Marks: 01) - Please choose the correct option
Which one of the following is not a keyword and can be used as an identifier in C/C++?
A. friends
B. template
C. this
D. new
What is the masking operator? Write the code snippet and determine the output of
expression which masks a variable int x = 100; with int m = 50;
class Output{
private:
int a,b,c;
public:
Output(){
a = 8;
b = 4;
c = 0;
}
void Display(){
c=a/b;
cout <<a<<"\n"<<b<<"\n"<<c;
}
};
int main() {
Output ob;
ob.Display();
return 0;
}
Write the keywords used for auxiliary input output stream and printer output stream in
DOS.
#include <iostream>
using namespace std;
int main () {
double x = 123.4;
cout.precision(4);
cout<< scientific;
cout<< x << endl;
return 0;
int main(){
int *ptr, sum=0, i=0, n=3;
if (ptr==NULL) {
cout<<"Memory allocation is not successful";
return 1;
}
while (i<=n) {
*(ptr+i) = i;
i++;
}
n=5;
if (ptr == NULL){
cout<<"Memory allocation is not successful";
return 1;
}
for (int j = 0;j < = n; j++){
*(ptr + j ) = j;
sum +=*( ptr + j);
}
cout<<"sum="<<sum;
free(ptr);
return 0;
}
class first
{
friend void add(first *, int);
private:
int variable;
public:
void print()
{
cout << "Variable = " <<variable<<endl;
}
first();
};
first::first()
{
variable = 0;
}
void add(first *x, int y){
x->variable += y;
}
int main(){
first z;
z.print();
add(&z, 10);
z.print();
}
Write the C++ syntax to create and delete a dynamic array using new and delete operator.
Carefully read and analyze the following code and determine its output.
class One {
public:
One(){
cout << "Class One Constructor" << endl;
}
~One(){
cout << "Class One Destructor" << endl;
}
};
class Three {
private:
One one;
public:
Three() {
cout << "Class Three Constructor" << endl;
}
~Three(){
cout << "Class three Destructor" << endl;
}
};
class Two {
private:
Three three;
public:
Two(){
cout << "Class Two Constructor" << endl;
}
};
int main()
{
Two two;
return 0;
}