Wednesday , 13 September 2017
Latest Posts
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
{
String name[];
int rnk[];

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

{
System.out.println("*** Inputting The Names And Ranks ***");
for(int i=0;i<50;i++)
{
System.out.print("Enter name of student "+(i+1)+" : ");
System.out.print("Enter his rank : ");
}
}

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]<min)
{
min = rnk[i];
index = i;
}
}
}

void display()
{
super.display(); //calling the superclass function display()
highest(); //calling the function highest() for finding index of topmost rank
System.out.println("nTop most rank = "+rnk[index]);
System.out.println("Student with topmost rank = "+name[index]);
}
} //end of subclass Rank

/* In your exams you don't need to write the below given code
We are writing it so as to familiarize the students on how to run programs
based on the concept of inheritance.*/

public class Question11_ISC2011 //Class which will contain the main() method and execute the program
{
public static void main(String args[])throws IOException
{
Rank ob=new Rank(); //creating object of subclass
ob.readvalues(); //calling radvalues() function of superclass to input the names and ranks
System.out.println("*** Output ***");
ob.display(); //calling display() function of subclass
}
}```

#### 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

## [Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks