A pure-virtual method is similar to a virtual method. A virtual method is a method that is expected to be overridden in a derived class while a pure-virtual method must be overridden in a derived class. The base class may provide a default implementation for a pure-virtual method, but it is not a requirement, whereas it must provide an implementation for a virtual method. In addition,
any base class that has a pure-virtual method becomes abstract; you cannot instantiate abstract classes -- you are expectedto derive from them.
#include
class Abstract
{
public:
// Pure-virtual method; note the '=0' to denote pure-virtual.
virtual void Show()=0;
};
class Derived : public Abstract
{
public:
virtual void Show()
{
// Implementation is required here!
std:: cout << "Derived" << std::end;
}
};
void main()
{
// Abstract a; // Compiler error!
Derived d;
d.Show(); // Call pure-virtual method.
return( 0 );
}
The following program demonstrates pure virtual functions.
#include<iostream>
#include<list>
class shape
{
public:
// pure-virtual
virtual void draw() = 0 { std::cout<<"Drawing..."; }
};
class circle: public shape
{
public:
void draw(){ shape::draw(); std::cout<<"circle"<<std::endl; }
};
class square: public shape
{
public:
void draw(){ shape::draw(); std::cout<<"square"<<std::endl; }
};
void process_shapes(std::list<shape*>& shapes)
{
for(std::list<shape*>::iterator i=shapes.begin(); i!= shapes.end(); ++i )
{
shape& sh=*(*i);
sh.draw();
}
}
int main()
{
circle c;
square s;
std::list<shape*> shapes;
shapes.push_back( &c );
shapes.push_back( &s );
process_shapes( shapes );
}
write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program
This is not a question.
There is no gotoxy statement in C.
write a vb program to find the magic square
Write a merits and demerits of using function in program
extensible means to enhance the program with new capabilities. In c++, extensibility can be achieved by using virtual function. now first we discuss what is virtual function in c++. " C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. The whole function body can be replaced with a new set of implementation in the derived class." Through this u can be able to promote extensibility in your program by using Virtual function. Very simple concept.
write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program
#include<
not possible dude
This is not a question.
give an example of calculation of mathematics
There will be a function in it like this: double RectangleArea (double a, double b) { return a*b; }
Use text-editor notepad++
swap (int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; }
I don't think its possible. Every C++ program must at least have the main function.
There is no gotoxy statement in C.
write a sample program using asp.net explaining all the syntax and semantics of the program