CS304 - Final Term Papers (WWW - Weblyceum.com) 04
CS304 - Final Term Papers (WWW - Weblyceum.com) 04
CS304 - Final Term Papers (WWW - Weblyceum.com) 04
► Static allocation
► Static typing
► Dynamic binding
► Dynamic allocation
► Public
► Private
► Protected
► All of the given
► overload
► overriding
► copy riding
► none of given
► True
► False
► True
► False
► True
► False
►1
►2
►3
► As many as necessary.
► set,map
► sequence,mapping
► setmet,multipule
► sit,mat
► late binding
► static binding
► virtual binding
► None of the given options
► Reusability
► Writability
► Maintainability
► All of given
►0
► 0.0
►1
► null
► length();
► size();
► ele();
► veclen();
vector<int> evec;
After adding the statment,
evec.push_back(21);
what will happen?
► The following statement will add an element to the start (the back) of evec
and will initialize it with the value 21.
► The following statement will add an element to the center of evec and will
reinitialize it with the value 21.
► The following statement will delete an element to the end (the back) of
► True
► False
► To define an object
► To define a data member
► To link the definition of an identifier to its declaration
► To make a class private
► Produce an error
► True
► False
► glorified.
► encapsulated.
► classified.
► overloaded.
► A operator + ( A &obj);
► int + operator();
► int operator (plus) ();
► A operator(A &obj3);
► Parameter, temporary
► Null, Parameter
► Parameter, default
► non of the given
► directly
► inderectly
► simultaniously
► non of the given
Yes, deque behaves like queue (line) such that we can add elements on both sides
of it.
the C++ Standard Template Library contains the function template max(x, y)
which creates functions that return either x or y, whichever is larger. max() could
be defined like this:
template <typename T>
T max(T x, T y)
{
return x < y ? y : x;
}
classPoweredDevice
{
};
classScanner: publicPoweredDevice
{
};
classPrinter: publicPoweredDevice
{
Scanners and printers are both powered devices, so they derived from
PoweredDevice. However, a copy machine incorporates the functionality of both
Scanners and Printers.
#include <iostream>
#include <stdlib.h>
using namespace std;
class Shape{
public:
void Draw(){cout<<"shape"<<endl;}
};
class Line : public Shape{
public:
void Draw(){cout<<"Line"<<endl;}
};
class Circle : public Shape{
public:
void Draw(){cout<<"Circle"<<endl;}
};
int main(int argc, char *argv[])
{
Shape * ptr1 = new Shape();
Shape * ptr2 = new Line();
Shape * ptr3 = new Circle();
ptr1->Draw();
ptr2->Draw();
ptr3->Draw();
system("PAUSE");
return 0;
Shape
Shape
Shape
Shape
Line
Circle
};
class B : public A
{
public:
void method() { cout<<"B's method\n"; }
};
Ans:
t.test(a);
t.test(b);
}
}
Hint:Use push_back() to add the words in vector class object, and the [] operator
and size() to display these sorted words.
The STL is the containers, iterators and algorithms component of the proposed
C++ Standard Library [ANSI95]. It represents a novel application of principles
which have their roots in styles of programming other than Object-orientation.
void listWords(istream& in, ostream& out)
{
string s;
sort(v.begin(), v.end());
vector<string>::iterator e
= unique(v.begin(), v.end()); // (2)
Exceptions in Destructors:
An object is presumably created to do something. Some of the changes made by
an object should persist after an object dies (is destructed) and some changes
should not. Take an object implementing a SQL query. If a database field is
updated via the SQL object then that change should persist after the SQL objects
dies. To do its work the SQL object probably created a database connection and
allocated a bunch of memory. When the SQL object dies we want to close the
database connection and deallocate the memory, otherwise if a lot of SQL objects
are created we will run out of database connections and/or memory.
The logic might look like:
Sql::~Sql()
{
delete connection;
delete buffer;
}
Let's say an exception is thrown while deleting the database connection. Will the
buffer be deleted? No. Exceptions are basically non-local gotos with stack
cleanup. The code for deleting the buffer will never be executed creating a
gaping resource leak.
Special care must be taken to catch exceptions which may occur during object
destruction. Special care must also be taken to fully destruct an object when it
throws an exception.
#include<iostream.h>
#include<conio.c>
class Exception {
private:
char message[30] ;
public:
int stock ;
int required_quantity;
public:
int get_required_quantity()
{
return required_quantity;
}
void order()
{
if (get_stock()< get_required_quantity())
throw Exception();
else
cout<<"The required quantity of item is available in the stock";
}
~Item(){}
};
void main()
{
try
{
obj.order();