Write C++ Program with base class convert declares two variables, val1 and val2, which
hold the initial and converted values, respectively. It also defines the functions getinit() and
getconv(), which return the initial value and the converted value. These elements of convert
are fixed and applicable to all derived classes that will inherit convert. However, the function
that will actually perform the conversion, compute(), is a pure virtual function that must be
defined by the classes derived from convert. The specific nature of compute() will be
determined by what type of conversion is taking place.
#include
using namespace std;
class convert
{
protected:
float val1, val2;
public:
float getinit()
{
cout<<"Enter the Initial Value :";
cin>>val1;
return val1;
}
float getconv()
{
return val2;
}
virtual void compute()
{
}
};
class cm : public convert
{
public :
void compute()
{
float m;
m = val1 * 100;
val2 = m;
}
void display()
{
cout<<"\n*********Conversion************\n ";
cout<
}
};
int main()
{
cm obj;
obj.getinit();
obj.compute();
obj.getconv();
obj.display();
}
hold the initial and converted values, respectively. It also defines the functions getinit() and
getconv(), which return the initial value and the converted value. These elements of convert
are fixed and applicable to all derived classes that will inherit convert. However, the function
that will actually perform the conversion, compute(), is a pure virtual function that must be
defined by the classes derived from convert. The specific nature of compute() will be
determined by what type of conversion is taking place.
OUTPUT OF THE PROGRAM |
using namespace std;
class convert
{
protected:
float val1, val2;
public:
float getinit()
{
cout<<"Enter the Initial Value :";
cin>>val1;
return val1;
}
float getconv()
{
return val2;
}
virtual void compute()
{
}
};
class cm : public convert
{
public :
void compute()
{
float m;
m = val1 * 100;
val2 = m;
}
void display()
{
cout<<"\n*********Conversion************\n ";
cout<
}
};
int main()
{
cm obj;
obj.getinit();
obj.compute();
obj.getconv();
obj.display();
}
For more such posts click the link:-http://svencrai.com/G8W
Tags
CODING