Site icon T4Tutorials.com

Friend Function C++ Program to convert octal to decimal number

Write the Octal to Decimal number program in C++ using friend function.

Octal to Decimal number program in C++

#include<iostream>
#include<math.h>
using namespace std;
class view
{
    public: 
		int T4Tutorials_Decimal=0,rem,T4Tutorials_Octal;
		public:
		view()    
			{ 
		     int T4Tutorials_Decimal=0,rem,T4Tutorials_Octal;
          	int i;
       	cout<<"Enter num:";
	      cin>>T4Tutorials_Octal;
	   for(i=0;T4Tutorials_Octal>0;i++)
	{
		rem=T4Tutorials_Octal%10;
		T4Tutorials_Decimal=T4Tutorials_Decimal+rem*pow(8,i);
		T4Tutorials_Octal=T4Tutorials_Octal/10;
	}
		cout<<"decimal num is"<<T4Tutorials_Decimal;
			
		    }
		friend int show(view c);
};
int show(view c)
   	{     
		cout<<endl<<"The number has converted to octal to Decimal.";
		    
	}
	
int main()
	  {
	      view c;
	      show(c);
           }

 

Exit mobile version