0% found this document useful (0 votes)
87 views7 pages

Sample Paper - CS201P

This document contains a sample final term examination for an introductory programming practical course. It consists of 30 multiple choice and coding questions worth a total of 40 marks. The questions cover topics like C++ fundamentals, arrays, pointers, classes, templates, and matrices. Sample code is provided for some questions to determine output.

Uploaded by

habibayub31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views7 pages

Sample Paper - CS201P

This document contains a sample final term examination for an introductory programming practical course. It consists of 30 multiple choice and coding questions worth a total of 40 marks. The questions cover topics like C++ fundamentals, arrays, pointers, classes, templates, and matrices. Sample code is provided for some questions to determine output.

Uploaded by

habibayub31
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Sample Paper

FINALTERM EXAMINATION
Fall 2022
CS201P – Introduction to Programming Practical

Time: 90 min
Marks: 40

Question No: 1 (Marks: 01) - Please choose the correct option

In C++, which one of the following is used for clarity and to force the order of evaluation
in an expression?
A. []
B. {}
C. ()
D. <>

Question No: 2 (Marks: 01) - Please choose the correct option


Which element is at arr[1] in the following array?
int arr[4]={0,1,2,3};
A. 0
B. 1
C. 2
D. 3

Question No: 3 (Marks: 01) - Please choose the correct option


The_______________ member of a class can be accessed from inside the class?
A. Private
B. Public
C. Protected
D. Constant

Question No: 4 (Marks: 01) - Please choose the correct option


Choose the correct method to close a file.
A. myFile.close(r);
B. myFile.close(w);
C. myFile.close(a);
D. myFile.close();

Question No: 5 (Marks: 01) - Please choose the correct option


Which of the following is a parametrized manipulator in C++?
A. hex
B. ends
C. setbase
D. cin

Question No: 6 (Marks: 01) - Please choose the correct option


Which of the following is not a logical operator?
A. ||
B. !
C. +=
D. &&
Question No: 7 (Marks: 01) - Please choose the correct option
Which one of the following way is to extend the C++ language?
A. Classes
B. If/else
C. Loops
D. Arrays
Question No: 8 (Marks: 01) - Please choose the correct option
Which operator is used to de-allocate the memory.
A. Delete
B. New
C. Create
D. Insert

Question No: 9 (Marks: 01) - Please choose the correct option


To declare a friend function, we can put it ________.
A. only at the start of the class
B. only at the end of the class
C. outside the class
D. anywhere in the class

Question No: 10 (Marks: 01) - Please choose the correct option


Consider the expression int v = *(*(p+i)+j); where p is a pointer to 2D array and i and j
are integer. Select the best option that describes v.
A. v must be a pointer
B. v points to the ith row and jth column of a table corresponding to p
C. v points to the (i+j)th element of p
D. Expression is incorrect

Question No: 11 (Marks: 01) - Please choose the correct option


A pointer to pointer differs from reference in that...…
A. a pointer to pointer can be null
B. a reference can be null
C. a pointer to pointer and reference can be null
D. a reference cannot be null
Question No: 12 (Marks: 01) - Please choose the correct option
\t, \s, \b are examples of ........…
A. special characters
B. control characters
C. double characters
D. branch characters

Question No: 13 (Marks: 01) - Please choose the correct option


Select the true statements about strcat() and strncat().
A. both are used for appending the strings
B. both accepts same number of parameters
C. strncat allows selected length of characters to be appended
D. strcat allows the selected length of characters to be appended

Question No: 14 (Marks: 01) - Please choose the correct option


Consider the string “Food was tasty”, How many invocations of strtok() would be
required to print tasty.
A) 3
B) 4
C) 1
D) 2

Question No: 15 (Marks: 01) - Please choose the correct option


The main difference between template function and normal function is
A. data types are specific in normal function while in template not specific
B. data types are not specific in normal function while in template are specific
C. template function accepts only single parameter unlike normal function
D. template function accepts two parameters unlike normal function

Question No: 16 (Marks: 01) - Please choose the correct option


Function templates can operate with
A. Int data type
B. float data type
C. generic data type
D. char data type

Question No: 17 (Marks: 01) - Please choose the correct option


Which of the following keyword/keywords can be used in template?
A. #define
B. template
C. typename
D. both template and typename

Question No: 18 (Marks: 01) - Please choose the correct option


Nested class in C++ can be accessed outside the enclosing class using
A. Scope resolution operator ( :: ) (correct)
B. Arrow sign (->)
C. Using dot operator ( .)
D. Using <> sign

Question No: 19 (Marks: 01) - Please choose the correct option


To call template function in main(), following is the correct syntax
A. MyFunction<int>(3,7)
B. MyFunction(3,7)
C. MyFunction(int 3, int 7)
D. MyFunction(3,7) int

Question No: 20 (Marks: 01) - Please choose the correct option


Suppose A is matrix with 4 rows and 5 columns, then order of matrix A is _________.
A. 4 * 5
B. 5 * 4
C. 4 + 5
D. 5 + 4
Question No: 21 (Marks: 01) - Please choose the correct option
The sum or addition of two matrices can be found if both matrices have _________.
A. same no of rows
B. same no of columns
C. same no of rows and columns
D. same no of columns of first matrix and no of rows of second matrix

Question No: 22 (Marks: 01) - Please choose the correct option

The input function which will get the input from the keyboard, takes an argument of type
_________.

A. ostream
B. istream
C. ifstream
D. instream

Question No: 23 (Marks: 01) - Please choose the correct option


All of the given are normal operations that are performed on matrices except _________.
A. Matrix is added to another matrix
B. Matrix is subtracted from another matrix
C. Matrix is multiplied with another matrix
D. Matrix is divided with another matrix

Question No: 24 (Marks: 01) - Please choose the correct option


Suppose you want to perform scalar addition “x + A” on matrix A. Which of the
following is the correct declaration to overload the addition “+” operator in C++?
A. Matrix operator + (Scalar) const;
B. Matrix operator + (Scalar, Matrix &) const;
C. friend Matrix operator + (Scalar) const;
D. friend Matrix operator + (Scalar, Matrix &) const;

Question No: 25 (Marks: 05)


Carefully read and analyze the following code and determine its output.

int main(){
int x = 2;
double eq1 = (11+x)/ (x*x*x) + 2*x*(5-x);
cout << eq1;
double eq2 = (x*x) + x*(2+2*x)/ (11+x);
cout << eq2;
}

Solution:
2.5 marks for each.
13
4

Question No: 26 (Marks: 05)


What will be output of the following program?
#include<iostream>
using namespace std;
void print(int arr[5])
{
for(int i=4;i>=0;i--)
{
if(arr[i]%2!=0)
{
cout<<2*arr[i]<<" ";
}
else
{
cout<<arr[i]<<" ";
}
}
}
int main()
{
int arr[5]={5,4,3,2,1};
print(arr);
cout<<endl;
return 0;
}
Question No: 27 (Marks: 05)
Write a program in C++ to calculate area and circumference of a rectangle using macros.
Take the values of length and breadth from user.
Hint: Area of rectangle is the product of its length and breadth whereas circumference of
rectangle is sum of all the side lengths.

Question No: 28 (Marks: 05)


Write down the output of the following code.

#include <iostream>
using namespace std;
class Student
{
public:
~Student()
{
cout<<"Hello";
}
Student(int x)
{
for(int i=0;i<x;i++)
cout<<"Welcome to VU"<<endl;
}
};
int main()
{
Student s1(4);
}

Question No: 29 (Marks: 05)


Fill the columns with correct answers:
Mode Meaning
Open a file or stream for extraction (input)
Open a file or stream for insertion (output)
Append rather than truncate an existing file. Each
insertion(output) will be written to the end of the file
Discards the file’s contents if it exists. (similar to
default behavior)
Treat the file as binary rather than text. A binary file
has data stored in internal formats, rather than readable
text format

Question No: 30 (Marks: 05)


What will be the output of following program written in C++? [5 Marks]
#include<iostream>
#include<iomanip>
using namespace std;
class Fun
{
float f;
public:
Fun():f(1.0){};
Fun(float x):f(x){};
float getf(){return f;};
void setf(float a){f = a;};
void display();
friend Fun operator * (const Fun & , const Fun &) ;
};
Fun operator * (const Fun & Fn1 , const Fun & Fn2)
{
Fun temp;
temp.f = Fn1.f * Fn2.f;
return temp;
}
void Fun::display()
{
cout<< setprecision(3) << this->f;
}
int main()
{
Fun fobj[] = {Fun(2.563) , Fun(2.0) , Fun()};
Fun fd = fobj [0] * fobj [1] * fobj [2];
fd.display();
return 0;
}

You might also like