Problem StatementWrite a program to demonstrate Multilevel InheritanceInput FormatInput the details of the student containing the Name, Roll No, Branch, College, marksOutput FormatPrint the details of the studentsSample InputNik12fCSEVJIT9.2Sample OutputNik12fCSEVJIT9.2
Question
Problem StatementWrite a program to demonstrate Multilevel InheritanceInput FormatInput the details of the student containing the Name, Roll No, Branch, College, marksOutput FormatPrint the details of the studentsSample InputNik12fCSEVJIT9.2Sample OutputNik12fCSEVJIT9.2
Solution
Sure, here is a simple Python program that demonstrates multilevel inheritance. In this program, we have three classes: Student, Branch, and Details. The Student class is the base class, Branch is the derived class and Details is the multilevel derived class.
class Student:
def __init__(self, name, roll_no):
self.name = name
self.roll_no = roll_no
class Branch(Student):
def __init__(self, name, roll_no, branch):
Student.__init__(self, name, roll_no)
self.branch = branch
class Details(Branch):
def __init__(self, name, roll_no, branch, college, marks):
Branch.__init__(self, name, roll_no, branch)
self.college = college
self.marks = marks
def display(self):
print(self.name, self.roll_no, self.branch, self.college, self.marks)
# Sample Input
d = Details('Nik', '12f', 'CSE', 'VJIT', 9.2)
d.display()
In this program, Details class inherits Branch class and Branch class inherits Student class. This is a simple example of multilevel inheritance. The display method in Details class is used to print the details of the student.
Similar Questions
In a school, each student is identified by a unique combination of a class section and a roll number. Write a program that takes input for the class section (either uppercase or lowercase character) and the roll number (an integer). The program should then output a message indicating the student's roll number in the specified class section.Input format :The first line of input is a character c, representing the class section (A-Z or a-z).The second line of input is an integer d, representing the roll number.Output format :The output displays a message indicating the roll number and class section in the format: "Roll number d in Section c".Refer to the sample output for formatting specifications.Code constraints :In this scenario, the test cases will fall under the following constraints:1 ≤ d ≤ 50The class section must be a letter in either uppercase or lowercase.Sample test cases :Input 1 :A30Output 1 :Roll number 30 in Section AInput 2 :D50Output 2 :Roll number 50 in Section DInput 3 :z25Output 3 :Roll number 25 in Section z
Single File Programming QuestionProblem StatementA school administrator needs to display the information of a student. The student has an ID (an integer) of 15, an age (an integer) of 23 and achieved a grade (a character) 'B'. Write a C program to print these details using appropriate data types and formatting.Input format :No console input.Output format :The output displays the values in the below format:Student id: 15Student age: 23Student grade: BRefer to the sample output for the formatting specification
Write a programme in C++ which read and print employee information with department and pf information using hierarchical inheritance
Multilevel inheritance allows _________________ in the program.
You have to create a struct, named Student, representing the student's details, as mentioned above, and store the data of a student.Input FormatInput will consist of four lines.The first line will contain an integer, representing age.The second line will contain a string, consisting of lower-case Latin characters ('a'-'z'), representing the first_name of a student.The third line will contain another string, consisting of lower-case Latin characters ('a'-'z'), representing the last_name of a student.The fourth line will contain an integer, representing the standard of student.Note: The number of characters in first_name and last_name will not exceed 50.Output FormatOutput will be of a single line, consisting of age, first_name, last_name and standard, each separated by one white space.P.S.: I/O will be handled by HackerRank.Sample Input15johncarmack10Sample Output15 john carmack 10
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.