Friend Function C++ Program to convert octal to decimal number
Write the Octal to Decimal number program in C++ using friend function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #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); } |