Write C++ A program with a base class conversion declares two variables, val1 and val2, that contain the initial and converted values. It also defines the getinit() and getconv() functions, which return the initial value and the converted value. These conversion elements are fixed and applicable to all derived classes that inherit the conversion. However, the function that actually performs the conversion, compute(), is a purely virtual function that must be defined by classes derived from the conversion. The specific nature of compute() will be determined by what type of conversion is taking place.

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.


OUTPUT OF THE PROGRAM
#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();

}

For more such posts click the link:-http://svencrai.com/G8W

Post a Comment

Previous Post Next Post