Question 10

A super class Record contains names and marks of the students in two different single dimensional arrays. Define a sub class Highest to display the names of the students obtaining the highest mark.

The details of the members of both the classes are given below:

Class name     Record

Data member/instance variable:

n[ ]       array to store names

m[ ]      array to store marks

size      to store the number of students

Member functions/methods:

Record(int cap            )           parameterized constructor to initialize the data member size = cap

void readarray()          to enter elements in both the arrays

void display( )             displays the array elements

Class name:    Highest

Data member/instance variable:

ind       to store the index

Member functions/methods:

Highest(…)     parameterized constructor to initialize the data members of both the classes

void find( )      finds the index of the student obtaining the highest mark and assign it to ‘ind

void display( ) displays the array elements along with the names and marks of the students who have obtained the highest mark

Assume that the super class Record has been defined. Using the concept of inheritance, specify the class Highest giving the details of the constructor(…),void find( ) and void display( )The super class, main function and algorithm need NOT be written

 

import java.util.*; 
class Highest extends Record 
{
	int ind; 
	Highest(int cap) 
	{
		super(cap); 
		ind=-1; 
	} 
	void find() 
	{
		readarray(); 
		int hm=m[0]; 
		for (int i=0;i<size;i++) 
		{
			 if (m[i]>hm) {
				 hm=m[i]; 
				ind=i; 
			} 
	         } 
	} 
	void display() 
	{ 
		super.display(); 
		for(int i=0;i<size;i++) 
		{
			 if(m[i]==m[ind]) 
			System.out.println("Highest obtained by "+n[i] + " marks "+m[i]); 
		}		 
	} 
}
This entry was posted in ISC2019. Bookmark the permalink.

Leave a Reply

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