Page 224 - Computer science 868 Class 12
P. 224
22. Define a class Flight with the following description.
Instance variables/data members:
fl_no : to store the flight number of int type
dest : to store the destination of the flight of String type
dist : to store the distance of the flight of float type
fuel : to store the fuel required by the flight of float type
Member Methods
calfuel() : to calculate the value of the fuel as per the following criteria
Distance Fuel
<=1000 500
>1000 and <=2000 1100
>2000 2200
feedinfo() : to allow the user to enter values for Flight Number, Destination, Distance and fuel
calfuel() : to calculate the quantity of the fuel
showinfo() : to allow the user to view the content of all the data members
Write the main method to create an object of the class and call the above member methods.
23. 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
n : stores the decimal number
oct : stores the equivalent octal number
Member Functions
DeciOct() : constructor to initialise the data members to 0
void getnum(int nn) : assigns nn to n
void deci_oct() : calculates the octal equivalent of n and stores it in oct
void show() : displays the decimal number n and 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.
Previous Years' Questions
1. The conditional statement to check for the diagonal elements in a double dimensional array of ‘M’ number of rows and ‘M’
number of columns having the row index represented by ‘r’ and the column index represented by ‘c’ will be:
(a) (r==c && r+c == M) (b) (r==c || r+c == M-1)
(c) (r==c && r+c == M-1) (d) (r==c || r==M-1 || c==M-1) [ISC 2022]
Ans. (b)
2. What is the output of the code given below? [ISC 2022]
void main()
{ int a,b,c;
for(a=150,b=65,c=0;a%b !=0;c=a%b,a=b,b=c);
System.out.print(b+"");
}
(a) 0 (b) 65
(c) 5 (d) Error
Ans. (c)
3. With reference to the following program code, answer the questions that follow: [ISC 2022]
void trick (int a, int b)
{ int p=l;
for(int j= 1;j<=b;j++,p*=a);
222222 Touchpad Computer Science-XII

