QB For 1702cs201
QB For 1702cs201
QB For 1702cs201
1. To understand the concepts of Object On completion of the course, students will be able to
Oriented Programming.
2. To execute the Object oriented CO1: Explore the concept of classes and objects.
concepts to solve problems using C++ CO2: Develop programs using arrays and strings.
3. To develop programs using files and CO3: Implement the various types of inheritance.
templates. CO4: Exemplify the concepts of functions and streams.
CO5: Develop programs using files, templates and exception
handling.
3 Define Tokens 2 1 K2
E.G.S. PILLAY ENGINEERING COLLEGE
Rev.0
(An Autonomous Institution, Affiliated to Anna University, Chennai)
COE/2017/QB
Nagore Post, Nagapattinam – 611 002, Tamilnadu.
5 Define constructor
Friend return type function name() 2 2 K1
E.G.S. PILLAY ENGINEERING COLLEGE
Rev.0
(An Autonomous Institution, Affiliated to Anna University, Chennai)
COE/2017/QB
Nagore Post, Nagapattinam – 611 002, Tamilnadu.
int main()
{
Student A(10);
Student B(11,"Ram");
}
8 Define destructor.
Destructor is a member function which destructs or deletes an object. 2 2 K2
6 What is inheritance?
Inheritance in Object Oriented Programming can be described as a process
of creating new classes from existing classes. New classes inherit some of
the properties and behavior of the existing classes. An existing class that is 2 3 K1
"parent" of a new class is called a base class. ... Inheritance is a technique of
code reuse.
7 What are the benefits of inheritance in C++?
The most frequent use of inheritance is for deriving classes using existing
classes, which provides reusability. The derived classes extend the 2 3 K2
properties of base classes to generate more dominant objects. The same
base classes can be used by a number of derived classes in class hierarchy.
8 List the types of inheritance.
In C++, we have 5 different types of Inheritance. Namely,
1. Single Inheritance
2. Multiple Inheritance 2 3 K2
3. Hierarchical Inheritance
4. Multilevel Inheritance
5. Hybrid Inheritance (also known as Virtual Inheritance)
#include<iostream>
#include<conio.h>
//Standard namespace declaration
using namespace std;
class overloading {
int value;
public:
void display() {
cout << value << endl;
}
};
//Main Functions
int main() {
overloading obj1, obj2, result;
int a, b;
getch();
return 0;
}
E.G.S. PILLAY ENGINEERING COLLEGE
Rev.0
(An Autonomous Institution, Affiliated to Anna University, Chennai)
COE/2017/QB
Nagore Post, Nagapattinam – 611 002, Tamilnadu.
#include<iostream>
using namespace std;
int main() {
A<char> a; // This will call A<char, char>
return 0;
}
Run on IDE
Output:
Constructor Called
9 What is the difference between function overloading and templates?
Both function overloading and templates are examples of polymorphism
feature of OOP. Function overloading is used when multiple functions do 2 4 K2
similar operations, templates are used when multiple functions do identical
operations.
Templates are used to create Abstract Data Types (ADTs) and classify
algorithms and data structures.
There are few important functions to be used with file streams like:
tellp() - It tells the current position of the put pointer.
Syntax: filepointer.tellp()
tellg() - It tells the current position of the get pointer.
Syntax: filepointer.tellg()
seekp() - It moves the put pointer to mentioned location.
Syntax: filepointer.seekp(no of bytes,reference mode)
seekg() - It moves get pointer(input) to a specified location.
Syntax: filepointer.seekg((no of bytes,reference point)
put() - It writes a single character to file.
get() - It reads a single character from file.
#include <iostream>
using namespace std;
float division(int x, int y) {
if( y == 0 ) {
throw "Attempted to divide by zero!";
}
return (x/y);
}
int main () {
int i = 25;
int j = 0;
float k = 0;
try {
k = division(i, j);
cout << k << endl;
}catch (const char* e) {
cerr << e << endl;
}
return 0;
}
12 What causes a runtime exception?
public class RuntimeException extends Exception. RuntimeException is the
superclass of those exceptions that can be thrown during the normal. 2 5 K2
RuntimeException and its subclasses are uncheckedexceptions.
15 What is an exception
Unchecked specification
are the exceptions in C++?
that are not checked at compiled time. In
Exception specifications
C++, all exceptions are a C++ language
are unchecked, so it is notfeature
forcedthat is deprecated
by the compiler toin
C++11. They or
either handle were designed
specify to provideItsummary
the exception. information
is up to the abouttowhat
programmers be 2 5 K2
exceptions canspecify
civilized, and be thrown out of
or catch thea exceptions
function
Example 3
Justification 3
5 Write a c++ program to to get and print employee detils using array of
objects
Flow operations 4 2 K2
Program 8
6 Explain about pointer to object with example.
Definition and syntax 4
2 K2
Example 4
Justifications 4
UNIT III - POLYMORPHISM AND INHERITANCE
1 Explain about polymorphism with example
Definition and syntax 4
3 K2
Types with comparison chart 4
Examples 4
2 Write a c++ program to create game character using inheritance
Identification of control and conditional expressions 4
3 K2
Syntax flow 4
Logic 4
3 Explain about unary and binary operator overloading in c++
Definitions 6 3 K2
Flow operations and examples 6
4 Explain about friend function with examples
Definition and syntax 5
3 K2
Control flow 2
Track diagrams with examples 5
5 Illustrate abstract data type in c++
User defined types 6 3 K2
List of supportive types with examples 6
6 Explain about standared template library in c++
Functional template 6 3 K2
Class template 6
UNIT IV – VIRTUAL FUNCTIONS AND TEMPLATES
1 Explain about virtual function with example
Virtual functions 3
Pure virtual functions 3 4 K2
Examples 3
Justification 3
2 Illustrate virtual destructor and highlight the usage of destructor and virtual
destructor in one example
4 K2
Comparison of destructor and virtual destructor 6
Example highlighting destructors with output justifications 6
E.G.S. PILLAY ENGINEERING COLLEGE
Rev.0
(An Autonomous Institution, Affiliated to Anna University, Chennai)
COE/2017/QB
Nagore Post, Nagapattinam – 611 002, Tamilnadu.
times. For example, xyz, ccaarr, mmmiiiaaa satisfy the criteria, but xyzw,
aabbbcccc don't.
Given N names suggested by Roman, print "OK" if Brian likes the name
and "Not OK" if he doesn't.
Input:
First line contains a single positive integer N - the number of names.
N lines follow - each line contains a name.
Output:
For each name, Print "OK" if the name satisfies the criteria, else print "Not
OK", on a new line.
Constraints:
1 ≤ N ≤ 100
1 ≤ Length of names ≤ 500
Names contain only lowercase English alphabets
2 Given A and B, count the numbers N such that A ≤ N ≤ B and N is a
palindrome.
Examples:
Palindromes: 121, 11 , 11411
Not Palindromes: 122, 10
20 4 K3
Input:
First line contains T, the number of testcases. Each testcase consists of two
integers A and B in one line.
Output:
For each testcase, print the required answer in one line
UNIT V – FILES AND EXCEPTION HANDLING
1 W.T.H.S.E.C
Confused? Well it stands for Welcome To HackerEarth September Easy
Challenge :). It's quite amazing when long words like this get reduced to
such a short string. They sound pretty cool and often make the chat
interesting. They are almost used everywhere these days.
Our friend Harsh has been recently reducing every sentence he receives to
acronym. Since Harsh is a young lad he has his own personal likes and
dislikes. There are some words which he just does not want to see in a
sentence. So whenever he encounters such a word he simply ignores it.
Harsh is thinking of converting a book to an acronym book where each
sentence of the book is reduced to its short form. Since Harsh is quite busy
in promoting his new book he wants you to help him in doing so. 20 5 K3
So he gives you a set of words which he dislikes and a sentence for which
he wants to abbreviate. Help him in getting the required abbreviation.
Input:
The first line contains an integer K which denotes the number of disliked
words, This is followed by k lines where each line contains a disliked word,
the next line will contain an integer donating the number of words in the
given sentence, The last line contains the sentence of which Harsh wants to
abbreviate.
The sentence will consist of number of words separated by a space
All words will consist of lowercase English alphabets(a-z)
E.G.S. PILLAY ENGINEERING COLLEGE
Rev.0
(An Autonomous Institution, Affiliated to Anna University, Chennai)
COE/2017/QB
Nagore Post, Nagapattinam – 611 002, Tamilnadu.
Output:
In a single line print the required acronym. The Acronym should be printed
in Upper Case English alphabets separated by "." (dots).
2 If we list all the natural numbers below 10 that are multiples of 3 or 5 , we
get 3, 5, 6, and 9. The sum of these multiples is 23 .
Find the sum of all the multiples of 3 or 5 below N .
Input Format
First line contains T that denotes the number of test cases. This is followed 20 5 K3
by T lines, each containing an integer, N .
Output Format
For each test case, print an integer that denotes the sum of all the multiples
of 3 or 5 below . N