Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

QB For 1702cs201

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

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.

1702CS201 PROGRAMMING IN C++


Academic Year 2017-2018 Programme B.E – (Common
: : to all)
Question Bank
Year / Semester I / II Course Coordinator: Dr.M.Chinnadurai
: Mr.S.Aravindan

Course Objectives Course Outcomes:

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.

PART – A ( 2 Mark Questions With Key)


S.No Questions Mark COs BTL
UNIT I – BASIC CONCEPTS
1 What are the Concepts of OOPs
 Objects
 Classes
 Data Abstraction
 Data Encapsulations 1 K2
 Inheritance 2
 Polymorphism
 Message Passing
 Dynamic Binding

2 Differentiate Procedure Oriented Programming(POP) and Object Oriented


Programming(OOP)
Emphasis on non-real time
2) Programs are divided into functions
3) Data are sharable
4) Structured Programming
5) Top-Down Approach
OOP 2 1 K2
1) Emphasis on real item
2) Programs are divided into Objects
3) Data are not sharable
4) Object Oriented Programming
5) Bottam-Up Arpproach

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.

Smallest individual unit in a program. C++ tokens are Keywords,


Identifiers, Constants,Strings, Operators
4 What are the Data Types in C++?
Built-in Data types
User Defined Data types 2 1 K1
Derived Data Types
5 Write the Block Structure of C++
Include Files
Class Declaration 2 1 K1
Member Function Defintions
Main Function Program

6 What are the Operators in C++


1. Scope Resolution Operator : :
2. Pointer-to-Pointer Member Declarator : :*
3. Pointer-to-Pointer Member Operator ->*
2 1 K1
4. Pointer-to-Pointer Member Operator .*
5. Delete-Memory Release Operator
6. Endl-Line feed operator
7. New-Memory allocation operator
7 8.
What is Setw-Memory width
expression? What areoperator
the expressions in C++?
1. Constant Expressions
2. Integral Expressions
3. Float Expressions
4. Pointer Expressions 2 1 K1
5. Relational Expressions
6. Logical Expressions
7. Bitwise Expressions
8 Define Class?
A class encloses both data and functions that operate on the data, into a 2 1 K1
single unit
9 Define Object Based Language.
Object Based Language=Encapsulation + Object Identity Object Oriented 2 1 K2
Language= Object Based Features + Inheritance + Polymorphism
10 What are the Access Specifiers in C++.?
1. Public
2. Private 2 1 K1
3. Protected
11 What is Static Variables?
Defined within the function, static variable initialized only once. Contents 2 1 K1
of the variables retained throughout the program.
12 What is an array? 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.

An array is a data structure which allows a collective name to be given to a


group of elements which all have the same type
13 What is ADT?
ADT is a collection of data and associated operations for manipulating that 2 1 K2
data
14 What are userdefned ADTs?
2 1 K2
Stack ,queue,tree
15 List the predefined ADTs in c++
C++ Classes ,Automatic Initialization and Termination,Friends,Assignment
2 1 K1
and Initialization, Overloading ,Parameterized Types ,Iterators,
Miscellaneous Issues
UNIT 2- CLASS AND OBJECTS
1 Write short notes on class with syntax
A class reduces complicity of holding data. A class just holds data and
functions.
Normal datatype variables are holding data. A class is a custom data type. It
has capable of hold data and functions
class class_name {
access_specifier_1: 2 K1
2
variable1;
function1;
access_specifier_2:
variable12
function2;
} object1, object2;
2 Write short notes on object with syntax
An object is an instance of a class. Simply, It is variable of custom datatype
2 2 K1
classes. It can access and use all classes variables and functions

3 How do we pass and return object as arguments?


we can pass objects and assign the values of supplied object to the current
object. For complex or large projects, we need to use objects as an 2 2 K1
argument or parameter.
4 Define friend functions with syntax.
A friend function of a class is defined outside that class' scope but it has the
right to access all private and protected members of the class. Even though
2 2 K2
the prototypes for friend functions appear in the class definition, friends are
not member functions.

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.

Constructors are special class functions which performs initialization of


every object. The Compiler calls the Constructor whenever an object is
created

6 List the three types of constructor


1. Default Constructor
2. Parametrized Constructor 2 2 K1
3. Copy constructor
7 Give an example for constructor overloading.
class Student
{
int rollno;
string name;
public:
Student(int x)
{
rollno=x;
name="None";
}
Student(int x, string str)
2 2 K2
{
rollno=x ;
name=str ;
}
};

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

9 9. When is destructor called?


A destructor function is called automatically when the object goes out of
scope:
(1) the function ends 2 2 K1
(2) the program ends
(3) a block containing local variables ends
(4) a delete operator is called

10 State array of object. 2 2 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.

An object of class represents a single record in memory, if we want more


than one record of class type, we have to create an array of class or object.
As we know, an array is a collection of similar type, therefore an array can
be a collection of class type
11 What is a copy constructor?
A copy constructor is a member function which initializes an object using 2 2 K1
another object of the same class.
12 When is copy constructor called?
In C++, a Copy Constructor may be called in following cases:

1. When an object of the class is returned by value. 2 2 K1

2. When an object of the class is passed (to a function) by value as an


argument.
13 When is user defined copy constructor needed?
3. When an object is constructed based on another object of the same class.
If we don’t define our own copy constructor, the C++ compiler creates a
default
4. Whencopy constructor
compiler for each
generates class which
a temporary does a member wise copy
object.
between objects. The compiler created copy constructor works fine in 2 2 K1
general. We need to define our own copy constructor only if an object has
pointers or any run time allocation of resource like file handle, a network
connection..etc
14 Are pointers important in C++?
One reason to use pointers is so that a variable or an object can be modified
in a called function. In C++ it is a better practice to use references than 2 2 K2
pointers. ... You can also use pointers to navigate arrays: An array is a block
of contiguous memory that has been allocated with a specific type
15 What is default constructor?
A default constructor is a constructor that either has no parameters, or if it 2 2 K2
has parameters, all the parameters have default values
UNIT III – POLYMORPHISM AND INHERITANCE
1 What is polymorphism?
The word polymorphism means having many forms.
Typically, polymorphism occurs when there is a hierarchy of classes and
they are related by inheritance.C++ polymorphism means that a call to a 2 3 K1
member function will cause a different function to be executed depending
on the type of object that invokes the function.

2 What are requirements of function overriding?


Inheritance should be there. Function overriding cannot be done within a
class. For this we require a derived class and a base class.Function that is 2 3 K1
redefined must have exactly the same declaration in both base and derived
class, that means same name, same return type and same parameter list.
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.

3 What are ways to overload a function?


By changing number of Arguments. 2 3 K1
By having different types of argument
4 Why function overloading is important in C++?
Overloading is a form of polymorphism. It allows the programmer to write
functions to do conceptually the same thing on different types of data 2 3 K1
without changing the name.
5 Give an example for data conversion in c++.
#include <iostream>
#include <string>
using namespace std;
void main(void) {
int num1; 2 3 K2
float num2 = 5.615;
num1=static_cast<int>(num2);
cout<<num1;
}

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)

9 What are characterstics of abstract class? 2 3 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.

 Abstract class cannot be instantiated, but pointers and refrences of


Abstract class type can be created.
 Abstract class can have normal functions and variables along with a
pure virtual function.
 Abstract classes are mainly used for Upcasting, so that its derived
classes can use its interface.
 Classes inheriting an Abstract Class must implement all pure virtual
functions, or else they will become Abstract too.

10 What is iterator in c++?


Iterator: a pointer-like object that can be incremented with ++, dereferenced
with *, and compared against another iterator with !=. Iterators are 2 3 K2
generated by STL container member functions, such as begin() and end().
11 What is containers in c++?
The Containers are objects that store data. The standard sequence containers
include vector , deque , and list . The standard associative containers are set 2 3 K2
, multiset , map , multimap , hash_set , hash_map , hash_multiset and
hash_multimap .
12 What are components of standard template library?
STL has four components
 Algorithms
 Containers 2 3 K2
 Functions
 Iterators
13 List the unary operators available in c++
The increment (++) and decrement (--) operators.
The unary minus (-) operator. 2 3 K2
The logical not (!) operator
14 what are binary operator?
The binary operators take two arguments and following are the examples of
Binary operators. You use binary operators very frequently like addition (+) 2 3 K2
operator, subtraction (-) operator and division (/) operator

15 How binary operator overloading works in addition of two numbers? 2 3 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.

#include<iostream>
#include<conio.h>
//Standard namespace declaration
using namespace std;

class overloading {
int value;
public:

void setValue(int temp) {


value = temp;
}

overloading operator+(overloading ob) {


overloading t;
t.value = value + ob.value;
return (t);
}

void display() {
cout << value << endl;
}
};

//Main Functions

int main() {
overloading obj1, obj2, result;
int a, b;

cout << "Enter the value of Complex Numbers a,b:";


cin >> a>>b;
obj1.setValue(a);
obj2.setValue(b);

result = obj1 + obj2;

cout << "Input Values:\n";


obj1.display();
obj2.display();

cout << "Result:";


result.display();

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.

UNIT IV – VIRTUAL FUNCTIONS AND TEMPLATES


1 Define virtual function.
Virtual Function is a function in base class, which is overrided in the
derived class, and which tells the compiler to perform Late Binding on this 4 K1
2
function.Virtual Keyword is used to make a member function of the base
class Virtual.
2 What is late binding?
In Late Binding function call is resolved at runtime. Hence, now compiler
determines the type of object at runtime, and then binds the function call. 2 4 K1
Late Binding is also called Dynamic Binding or RuntimeBinding
3 What are the rules of virtual function?
• They Must be declared in public section of class.

• Virtual functions cannot be static and also cannot be a friend


function of another class.

• Virtual functions should be accessed using pointer or reference of


base class type to achieve run time polymorphism.

• The prototype of virtual functions should be same in base as well as 2 4 K2


derived class.

• They are always defined in base class and overridden in derived


class. It is not mandatory for derived class to override (or re-define the
virtual function), in that case base class version of function is used.

• A class may have virtual destructor but it cannot have a virtual


constructor.
4 What is a pure virtual function?
A pure virtual function or pure virtual method is a virtual function that is
required to be implemented by a derived class if the derived class is not 2 4 K2
abstract. Classes containing pure virtual methods are termed "abstract" and
they cannot be instantiated directly.
5 What is a virtual destructor?
If the destructor in the base class is not made virtual, then an object that
might have been declared of type base class and instance of child class 2 4 K1
would simply call the base class destructor without calling the derived class
destructor.
6 Define TypeID.
- Hence, by making the destructor in the base class virtual, we ensure that
The typeid keyword is used to determine the class of an object at run time.
the derived class destructor gets called before the base class destructor. 2 4 K1
It returns a reference to std::type_info object, which exists until the end of
the program
7 Define dynamic casting 2 4 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.

The dynamic_cast operator in C++ is used for downcasting a reference or


pointer to a more specific type in the class hierarchy
8 Can we specify default value for template arguments?
Yes, like normal parameters, we can specify default arguments to templates.
The following example demonstrates the same.

#include<iostream>
using namespace std;

template<class T, class U = char>


class A {
public:
T x;
U y; 2 4 K1
A() { cout<<"Constructor Called"<<endl; }
};

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.

10 What happens when there is static member in a template class/function?


Each instance of a template contains its own static variable. See Templates 2 4 K2
and Static variables for more details.
11 What is template specialization?
Template specialization allows us to have different code for a particular 2 4 K2
data type. See Template Specialization for more details.
12 Define generic programming
Generic programming is a type of programming where the programmer
2 4 K2
specifies a general code first. That code is instantiated based on the type of
parameters that are passed later in the program or at execution.
13 list the use of templates 2 4 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.

Templates are widely used to implement the Standard Template Library


(STL).

Templates are used to create Abstract Data Types (ADTs) and classify
algorithms and data structures.

Class templates are generally used to implement containers.


14 Define function template.
A function template is a function which contains generic code to operate on
different types of data. This enables a programmer to write functions
without having to specify the exact type of parameters. Syntax for defining
a template function is as follows:
2 4 K2
template<class Type, ...>
return–type function–name(Type arg1, ...)
{
//Body of function template
}
15 Give an syntax for class template
2 4 K2
template <class type> class class-name {}
UNIT V – FILES AND EXCEPTION HANDLING
1 Define
{ file streams.
File represents storage medium for storing data or information. Streams 5 K1
2
refer to sequence of bytes
2 list the stream console in c++
ofstream:template<class Type, Stream
It represents output ...> and this is used for writing in files.
return–type function–name(Type
ifstream: It represents arg1,
input Stream and...)
this is used for reading from files. 2 5 K1
{fstream: It represents both output Stream and input Stream. So it can read
from files and write to files.
//Body of function template
3 list the file handling operations in c++
}
Operations in File Handling:-
• Creating a file – open()
• Reading data - read() 2 5 K1
• Writing new data - write()
• Closing a file- close()

4 What are special operations in file? 2 5 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.

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.

5 What are the streams in C++?


The stream is the central concept of the iostream classes. You can think of a
streamobject as a smart file that acts as a source and destination for bytes. A 2 5 K1
stream'scharacteristics are determined by its class and by customized
insertion and extraction operators.
6 What is a Stringstream in C++?
Stringstreams can be used to both read strings and write data into strings. It
mainly functions with a string buffer, but without an real I/O channel. The 2 5 K1
basic member functions of stringstream class are. str() , which returns the
contents of its buffer in string type

7 What is the use of Iostream in C++?


C++ input/output streams are primarily defined by iostream , a header file
that is part of the C++ standard library (the name stands for Input/Output 2 5 K1
Stream). In C++ and its predecessor, the C programming language, there is
no special syntax for streaming data input or output.
8 write short notes on exception handling.
Exception Handling in C++ is a process to handle runtime errors. We
perform exception handling so the normal flow of the application can be 2 5 K2
maintained even after runtime errors.
9 list the exception classes in c++
std::exception
It is an exception and parent class of all standard C++ exceptions. 2 5 K1
std::logic_failure
It is an exception that can be detected by reading a code.

10 list the keywords used in exception handling


Try
catch, and 2 5 K2
throw
11 Give an example for exception handling 2 5 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.

#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.

13 Is Filenotfoundexception checked or unchecked?


Since FileNotFoundException is a subclass of IOException, we can just
specify IOException in the throws list and make the above program
compiler-error-free.Unchecked are the exceptions that are not checked at 2 5 K2
compiled time. ... The compiler allows it to compile, because
ArithmeticException is an uncheckedexception.

14 list the two types of exceptions


Checked: are the exceptions that are checked at compile time. If some code
within a method throws a checked exception, then the method must either 2 5 K1
handle the exception or it must specify the exception using throws keyword.

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

PART – B (12 Mark Questions with Key)


S.No Questions Mar CO BTL
k s
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.

UNIT I –BASIC CONCEPTS


1 Explain the object oriented paradigms with examples
9 concepts 4
Diagram 4 1 K2
Example 4

2 Explain about arrays with example


Definition and syntax 4
1 K2
One dimensional array 4
Two dimensional array 4
3 Explain about operators and expressions in c++
List of operators definitions 3 1 K2
Examples 3
List of expressions definitions 3
Examples 3
4 4.Write a c program to remove all characters except alphabets
Identification of control and conditional expressions 4
1 K2
Syntax flow 4
Logic 4
5 Write a c program to find GCD and LCM of given nos.
4
Identification of control and conditional expressions
1 K2
Syntax flow 4
Logic 4
6 Write a c++ program to compute the power with and without Pow()
functions 4
Identification of control and conditional expressions
1 K2
Syntax flow 4
Logic 4
UNIT II – CLASS AND OBJECTS
1 Explain about object as arguments and returning object
Object definition and syntax 4
2 K2
Overview of object as arguments 4
Examples 4
2 Demonstrate and explain friend function with example
2 K2
Definition and syntax 2
Example with explanations 10
3 Explain about constructor and destructor with example
Definition and syntax 3
Flow of operations 3 2 K2
Examples with output 3
Justifications 3
4 Choose one mathematical formula and workout with three types of constructors
Comparison chart 3 2 K2
Formula declaration 3
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.

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.

3 Explain about rum time type information.


Overview 6 4 K2
Generic approach 6
4 Describe templates and write a program to find largest of two numbers using
templates
4 K2
Definition ,syntax and flow operations 6
Program with output 6
5 i. Perform following two programs using templates
ii. swapping of two numbers
iii. simple calculator
4 K2
Identification of control and conditional expressions 4
Syntax flow 4
Logic 4
6 Explain about generic programming in c++
4 K2
Overview 6
Examples 6
UNIT V - FILES AND EXCEPTION HANDLING
1 Write a c++ program for student management using file handling.
File handling list used in program 3
Procedure with diagram 3 5 K2
Program 3
Program flow track 3
2 Explain about file handling with examples
Tabular column of file handling 6 5 K3
Examples 6
3 Illustrate exception handling with example
Try,catch,throw 6 5 K2
Checked and unchecked exceptions with examples 6
4 Demonstrate the file handling techniques in library management and indentify the
list of exceptions handled.
Procedure 3
5 K2
Track diagram 3
Program 3
Conceptual mapping 3
5 Explain the following
 Ofstream
 Ifstream
 Fstream 5 K2
Definition and syntax 4
Flow operations 4
Examples 4
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.

6 Explain the following


 ios::trunk
 ios::app
 ios::ate 5 K2
Tabular column within definitions 4
Examples 8

PART – C (20 Mark Questions with Key)


S.No Questions Mark COs BTL
UNIT I – BASIC CONCEPTS
1 You have been given 3 integers - l, r and k. Find how many numbers
between l and r (both inclusive) are divisible by k. You do not need to print
these numbers, you just have to find their count.
Input Format 20
1 K3
The first and only line of input contains 3 space separated integers ll, rr and
kk.
Output Format
Print the required answer on a single line.
2 Mr. X's birthday is in next month. This time he is planning to invite N of
his friends. He wants to distribute some chocolates to all of his friends after
party. He went to a shop to buy a packet of chocolates. 20

At chocolate shop, each packet is having different number of chocolates.


He wants to buy such a packet which contains number of chocolates, which
can be distributed equally among all of his friends.
Help Mr. X to buy such a packet.
1 K3
Input:
First line contains T, number of test cases.
Each test case contains two integers, N and M. where is N is number of
friends and M is number number of chocolates in a packet.
Output:
In each test case output "Yes" if he can buy that packet and "No" if he can't
buy that packet.

UNIT II – CLASS AND OBJECTS


1 Indian army is going to do a surprise attack on one of its enemies country.
The President of India, the Supreme Commander of the Indian Army will
be sending an alert message to all its commanding centers. As enemy would
be monitoring the message, Indian army is going to encrypt(cipher) the
20 2 K3
message using basic encryption technique. A decoding key 'K' (number)
would be sent secretly.
You are assigned to develop a cipher program to encrypt the message. Your
cipher must rotate every character in the message by a fixed number
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.

making it unreadable by enemies.


Given a single line of string 'S' containing alpha, numeric and symbols,
followed by a number '0<=N<=1000'. Encrypt and print the resulting string.
Note: The cipher only encrypts Alpha and Numeric. (A-Z, a-z, and 0-9) .
All Symbols, such as - , ; %, remain unencrypted.
2 Given two strings of equal length, you have to tell whether they both strings
are identical.
Two strings S1 and S2 are said to be identical, if any of the permutation of
string S1 is equal to the string S2. See Sample explanation for more details.
Input :
• First line, contains an intger 'T' denoting no. of test cases. 20 2 K3
• Each test consists of a single line, containing two space separated
strings S1 and S2 of equal length.
Output:
• For each test case, if any of the permutation of string S1 is equal to
the string S2 print YES else print NO.
UNIT III – POLYMORPHISM AND INHERITANCE
1 You have been given a String SS consisting of uppercase and lowercase
English alphabets. You need to change the case of each alphabet in this
String. That is, all the uppercase letters should be converted to lowercase
and all the lowercase letters should be converted to uppercase. You need to
then print the resultant String to output. 20 3 K3
Input Format
The first and only line of input contains the String SS
Output Format
Print the resultant String on a single line.
2 As a beginner to the programming, Mishki came to Hackerearth platform,
to become a better programmer. She solved some problems and felt very
confident. Later being a fan of Hackerearth, she gave a problem to her
friends to solve. They will be given a string containing only lower case
characters (a-z), and they need to find that by using the characters of the
given string, how many times they can print "hackerearth"(without quotes).
As they are new to programming world, please help them.
20 3 K3
Input:
The first line will consists of one integer NN denoting the length of string.
Next line will contain the string StrStr containing only lower case
characters.
Output:
Print one integer, denoting the number of times her friends can print
"hackerearth" (without quotes).
UNIT IV – VIRTUAL FUNCTIONS AND TEMPLATES
1 Brian built his own car and was confused about what name he should keep
for it. He asked Roman for help. Roman being his good friend, suggested a
lot of names.
Brian only liked names that: 20 4 K3
- Consisted of exactly three distinct characters, say C1, C2 and C3
- Satisfied the criteria that the string was of the form - C1n C2n C3n : This
means, first C1 occurs n times, then C2occurs n times and then C3 occurs n
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

You might also like