National Institute of Technology Goa: B.Tech-IV Semester - End Semester Examinations
National Institute of Technology Goa: B.Tech-IV Semester - End Semester Examinations
National Institute of Technology Goa: B.Tech-IV Semester - End Semester Examinations
Instructions:
1. Write legibly. Unnecessary details attracts penalty
2. You must complement your explanation with the short fragments of C++ code where appropriate
3. Your programs should compile on any standard C++ compiler and be executed.
4. You should assume that appropriate headers and namespace std are included in each program.
5. The question paper is of Six pages.
1.
a) Consider a class myclass with two data members each of type int. Write a C++ program, so that
the following statements get executed. You can assume that following are present in main ().
Ob4=++Ob1+ Ob2-Ob3++;
cout<<Ob1<<Ob2<<Ob3<<Ob4;
Where, Ob1, Ob2, Ob3 and Ob4 are objects of class myclass. You are supposed to make the
required functions as member functions wherever possible. (10)
b) State whether each of the following is true or false. If false, explain why. (5)
i. All virtual functions in an abstract base class must be declared as pure virtual
functions.
ii. Referring to a derived-class object with a base-class handle is dangerous.
iii. A class is made abstract by declaring that class virtua1.
iv. If a base class declares a pure virtual function, a derived class must implement that
function become a concrete class.
v. Polymorphic programming can eliminate the need for switch logic.
2.
A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5 and 6 spots. After
the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum
is 7 or 11 on the first roll, the player wins. If the sum is 2, 3 or 12 on the first roll (called
"craps"), the player loses (i.e., the "house" wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first roll
then that sum becomes the player's "point." To win, you must continue rolling the dice until you
"make your point." The player loses by rolling a 7 before making the point. (5)
1
3.
a) What are abstract classes? Can you instantiate an abstract class? Justify. Give a scenario wherein
you will be using abstract classes. Differentiate function overloading and overriding (4)
b) How to achieve run-time polymorphism in C++? With an example program explain run-time
polymorphism. How static binding is realized in C++? (6)
c) Consider the following program. Correct the program using all possible approaches, if the
program is incorrect. If the program is incorrect, reason why it is incorrect.(8)
4.
a) Why exception handling is important? How C++ supports exception handling? With an example
program explain the concept of exception handling supported by C++. When terminate () and
unexpected () functions are invoked and what are their default actions? (6)
b) How derived class exceptions are handled in C++? Explain with a program example. How to
check whether an exception thrown is caught or uncaught? (4)
2
5.
a) What are the features of Java programming language? How Java achieves platform
independence? Write a Java program to multiply two integers. The numbers should be passed as
command line arguments. You have to put your program in a package called MyPackage. Also,
mention how to run this program? (6)
b) In Java classes are often organized as packages. The members of a class of a package can have
default, public, protected and private access specification. Elaborate on the visibility of various
members under various access specifications to the class, classes within a package, and classes
outside a package. While elaborating on visibility control, you have to take inheritance also into
consideration. For convenience, you can use table to elaborate visibility control.(6)
c) What is multithreaded programming? How multithread programming can be done in Java. With
a suitable Java program explain the same. The Java thread will be in several states during its
lifetime. Elaborate on the life cycle of Java thread. (5)
6. Note: Assume that all the relevant header files are included corresponding C/C++ Program, along
with using namespace std (for C++) wherever missing; QUESTIONS SHOULD BE ANSWERED IN
SEQUENCE. Justification is needed for the answers.
a) What is the output of the following program? b) Give the output of the following program. (2)
(2)
struct marks int main()
{ {
int p:3; char *str="c-pointer";
int c:3; printf("%*.*s",10,7,str);
}; return 0;
int main() }
{
struct marks s={2,-6};
printf("%d %d",s.p,s.c); c) What is the output of the following C program? (2)
return 0;
} #include <stdio.h>
int main(){
int class=150;
int public=25;
e) What is the output of the following Program?(2)
int private=30;
int main()
class = class >> private - public;
{
printf("%d",class);
printf("%s", "c" "question" "bank");
return 0;
return 0;
}
}
3
f) What is the output of the following program? d) What is the output of the program? (2)
(2)
int main() int main()
{ {
int a=-12; try
a=a>>3; {
cout<<a; throw 'a';
return 0; }
} catch (int param)
{
cout << "int exception";
}
catch (...)
{
cout << "default exception";
}
cout << "After Exception";
return 0;
}
g) What is the output of the program? (2) j) What is the output of the program? (2)
int main()
#include<iostream>
#include<string.h> {
using namespace std; int a=1;
int b=(1,2);
int main()
{ cout<<a<<" "<<b;
cout<<sizeof("string")<<"\n"<<strlen("string"); return 0;
return 0; }
}
iii) *((*kd).name + 2 )
n) What is the output of the following? (2) o) What is the output of the following? (2)
class Test
int main() {
{ static int count;
try
{ int id;
try public:
{ Test()
throw 20; {
}
count++;
catch (int n)
{ id = count;
cout << "Inside Caught "; cout << "Constructing object number " << id << endl;
throw; if(id = = 4)
} throw 4;
}
catch (int x) }
{ ~Test() {
cout << "Outside Caught"; cout << "Destructing object number " << id << endl;
} }
return 0; };
}
int Test::count = 0;
int main()
{
try
{
Test array[6];
} catch(int i) {
cout << "Caught " << i << endl;
}
}
5
p) What is the output of the following? (2) q) Assume A and B are non-zero positive integers.
What does the following code segment
void square (int *x)
{ compute?(2)
*x = (*x)++ * (*x); while ( A != B )
} {
void square (int *x, int *y)
{ If ( A> B )
*x = (*x) * --(*y); A -= B ;
} else
int main ( ) B -= A ;
{ }
int number = 30; cout<<A;
square(&number, &number);
cout << number;
return 0;
}
r) What is the output of the program? (2) t) What is the output of the following? (2)
class Test {
int main() int x;
{ public:
int i=0;
if(i==0) void* operator new(size_t size);
{ void operator delete(void*);
i=((5,(i=3)),i=1); Test(int i) {
cout<<i; x = i;
}
cout << "Constructor called \n";
else
cout<<"Equal"; }
} ~Test() { cout << "Destructor called \n"; }
};
s) What is the out of the program? (2) void* Test::operator new(size_t size)
class Test {
{ void *storage = malloc(size);
private: cout << "new called \n";
int x; return storage;
int y; }
public:
Test(int x = 0, int y = 0) {
this->x = x; this->y = y; void Test::operator delete(void *p )
} {
static void function1() { cout<<"delete called \n";
cout << "Inside function1()"; } free(p);
static void function2()
{ }
cout << "Inside function2()"; this->function1();} int main()
}; {
Test *m = new Test(5);
int main()
{ delete m;
Test obj; return 0;
obj.function2(); }
return 0;
}
**********************************All the Best************************************
6