Wednesday , 22 May 2019
Home » Class 12 » [Question 11 (Inheritance)] ISC 2011 (Theory) Paper Solved

[Question 11 (Inheritance)] ISC 2011 (Theory) Paper Solved

Question:

A super class Record has been defined to store the names and ranks of 50 students. Define a sub class Rank to find the highest rank along with the name. The details of both classes are given below:

Class name : Record

Data Members / instance variables:
name[ ] : to store the names of students
rnk[ ] : to store the ranks of students

Member functions:
Record() : constructor to initialize data members
void readvalues() : to store names and ranks
void display() : displays the names and the corresponding ranks

Class name : Rank

Data Members / instance variables:
index : integer to store the index of the topmost rank

Member functions
Rank() : constructor to invoke the base class constructor and to initialize index to 0.
void highest() : finds the index location of the topmost rank and stores it in index without sorting the array 6
void display() : displays the name and ranks along with the name having the topmost rank.

Specify the class Record giving details of the constructor(), void readvalues(), void display(). Using the concept of inheritance, specify the class Rank giving details of constructor(), void highest() and void display().

The main function and algorithm need not be written.

[Note: We will be writing the main() function also in this program so as to familiarize the students on how to run programs based on the concept of inheritance.]

Programming Code:

/**
* The superclass Record stores the stores the name and ranks of 50 students and
* the subclass Rank finds the highest rank along with the name
* @author : www.javaforschool.com
* @Program Type : BlueJ Program – Java
* @Question Year : ISC Theory 2011 Question 11
*/

import java.io.*;
class Record //superclass
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String name[];
int rnk[];

Record()
{
name = new String[50];
rnk = new int[50];
}

void readvalues()throws IOException
{
System.out.println(“*** Inputting The Names And Ranks ***”);
for(int i=0;i<50;i++) { System.out.print("Enter name of student "+(i+1)+" : "); name[i]=br.readLine(); System.out.print("Enter his rank : "); rnk[i]=Integer.parseInt(br.readLine()); } } void display() { System.out.println("NamettRank"); System.out.println("-------tt-------"); //this is just for styling the output. You can skip it ! for(int i=0;i<50;i++) { System.out.println(name[i]+"tt"+rnk[i]); } } } //end of superclass Record class Rank extends Record //subclass { int index; Rank() { super(); //invoking the constructor of superclass index = 0; } void highest() { int min = rnk[0]; for(int i=0;i<50;i++) { if(rnk[i]

Output:

[Note: We have shown output of the same program with only 5 students and not 50. But the above program works likewise for 50 students]

*** Inputting The Names And Ranks ***
Enter name of student 1 : Aamir
Enter his rank : 5
Enter name of student 2 : Zakir
Enter his rank : 2
Enter name of student 3 : Saalim
Enter his rank : 7
Enter name of student 4 : Samir
Enter his rank : 3
Enter name of student 5 : Saif
Enter his rank : 6
*** Output ***
Name             Rank
—–                 —–
Aamir             5
Zakir              2
Saalim           7
Samir             3
Saif                6

Top most rank = 2
Student with topmost rank = Zakir

Check Also

Infix Postfix Prefix Conversion – Correct Method (ISC Computer Science)

In this video we discuss about the correct way of converting an Infix Expression to Postfix and Prefix.

Leave a Reply

Your email address will not be published. Required fields are marked *