Site icon T4Tutorials.com

C++ Inheritance to convert an Octal number to a Decimal number without using an array

Octal to Decimal number program in C++

Write a program in C++ to convert an Octal number to a Decimal number without using an array by using the single inheritance.

#include<iostream>
#include<math.h>
using namespace std;
class a
{
	protected:
	int decimal_number=0 , remainder, octal_number;
	int count;
};
	class child: public a
	{
		public:
		int input()
		{
	cout<<"Enter an octal number:";
	cin>> octal_number;
		}
		int print()
		{
		decimal_number=0;
		for(count=0;octal_number>0;count++)
		{
		remainder = octal_number%10;
		decimal_number = decimal_number+ remainder*pow(8,count);
		octal_number=octal_number/10;
		}
		cout<<"decimal equivalent of"<<decimal_number;
		}
};
int main()
{
	child obj;
	obj.input();
	obj.print();
}

WAP in C++ to convert an Octal number to a Decimal number without using an array by using the multiple inheritances.

#include<iostream>
#include<math.h>
using namespace std;
class a
{
	protected:
	int decimal_number=0 , remainder, octal_number;
};
class b
{
	protected:
		int count;
	};
		class child:public a,public b
		{
			public:
			int input()
			{
	cout<<"Enter an octal number:";
	cin>> octal_number;
		}
		int print()
		{
		decimal_number=0;
		for(count=0;octal_number>0;count++)
		{
		remainder = octal_number%10;
		decimal_number = decimal_number+ remainder*pow(8,count);
		octal_number=octal_number/10;
		}
		cout<<"decimal equivalent of"<<decimal_number;
		}
};
int main()
{
	child obj;
	obj.input();
	obj.print();
}

 

Write a C++ program to convert an Octal to a Decimal number by using the multi-level inheritance.

#include<iostream>
#include<math.h>
using namespace std;
class a
{
	protected:
	int decimal_number=0 , remainder, octal_number;
};
	class b: public a
	{
		public:
		int count;
	};
	class c:public b
	{
		public:
		int input()
		{
	cout<<"Enter an octal number:";
	cin>> octal_number;
		}
		int print()
		{
		decimal_number=0;
		for(count=0;octal_number>0;count++)
		{
		remainder = octal_number%10;
		decimal_number = decimal_number+ remainder*pow(8,count);
		octal_number=octal_number/10;
		}
		cout<<"decimal equivalent of"<<decimal_number;
		}
};
int main()
{
	c obj;
	obj.input();
	obj.print();
}

 

Exit mobile version