Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
10.2k views
in Computer by (49.9k points)
closed by

A class DeciOct has been defined to convert a decimal number into its equivalent octal number. Some of the members of the class are given below: 

Class name: DeciOct 

Data members/instance variables: 

n: stores the decimal number 

oct: stores the octal equivalent number 

Member functions:

DeciOct(): constructor to initialize the data members 

n = 0, oct = 0. 

void getnum(int nn): assign nn to n 

void deci_oct(): calculates the octal equivalent of ‘n’ and stores it in oct using the recursive technique 

void show(): displays the decimal number ‘n’, calls the function deci_oct() and displays its octal equivalent. 

Specify the class DeciOct, giving details of the constructor( ), void getnum(int), void deci_oct( ) and void show(). Also define a main() function to create an object and call the functions accordingly to enable the task

1 Answer

+1 vote
by (49.0k points)
selected by
 
Best answer

Class DeciOct 

Public int n ; 

Public int oct; DeciOct() 

n = 0; Oct = 0; 

void getnum.(int nn) 

n = nn; 

void deci_oct( ) 

int t = n; 

int r = 0;

int s; 

while (t! = 0) 

s = t % 8; 

r = 10 * r + s; 

Oct = 0; 

while (r! = 0) 

int p = r% 10 

Oct = 10 * Oct + p; 

r = r/10; 

}

void show( ) 

System.out.println ('' The decimal number is " + n); 

System.out.println ("The octal of "+ n + " is" + oct); 

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...