Inheritance 57
Inheritance 57
Problem Statement
Create a class called Book that has the title and author of the book as attributes in a parametrized constructor.
Create another class called MyBook that inherits from the Book class and has the price of the book as an
attribute in a parametrized constructor.
Implements the program that uses the display() method that prints the title, author, and price as the output.
Input format :
The first line of the input consists of the title of the book as a string.
The second line of the input consists of the author of the book as a string.
The third line of the input consists of the price of the book as an integer.
Output format :
Code constraints :
Price>0
Aim
TANYA K 710723244057
Algorithm
TANYA K 710723244057
Program
TANYA K 710723244057
Output
TANYA K 710723244057
TANYA K 710723244057
Result
TANYA K 710723244057
Problem Statement
Richard is developing a simple school enrollment system to manage information about school members. He
has defined two classes, SchoolMember and Student, to represent members of the school.
The SchoolMember class contains basic information such as name and age, while the Student class, which
inherits from SchoolMember, adds additional details like grade level.
Input format :
The first line of input is a string, which represents the name of the student.
The second line of input is an integer, which represents the age of the student.
The last line of the input integer, which represents the grade level of the student.
Output format :
The output displays the details of the student in the following format:
"Student: [Student Name], Age: [Student Age], Grade Level: [Student Grade Level]"
Code constraints :
Aim
TANYA K 710723244057
Algorithm
TANYA K 710723244057
Program
TANYA K 710723244057
Output
TANYA K 710723244057
TANYA K 710723244057
Result
TANYA K 710723244057
Problem Statement
Write a program such that it should have three classes, Person and Student, and the Main class where
Person is the base class and Student is the derived class and use single inheritance.
An integer - id.
A char calculate() method that calculates a Student object's average and returns the grade character
representative of their calculated average:
Input format :
The first line of input consists of a string representing the first name.
The second line of input consists of a string representing the last name.
The fifth line of input consists of an integer array of test scores, separated by a single space.
TANYA K 710723244057
Output format :
The output displays the Name, ID, and Grade of the student in separate lines.
Code constraints :
Aim
TANYA K 710723244057
Algorithm
TANYA K 710723244057
Program
TANYA K 710723244057
Output
TANYA K 710723244057
TANYA K 710723244057
Result
TANYA K 710723244057
Problem Statement
Implement a shape calculator program that uses inheritance to calculate the area and perimeter of rectangles
and squares. The program should leverage the inheritance relationship between the base class Shape and its
derived classes, Rectangle and Square, to calculate these values.
Input format :
The first line of input consists of an integer, which represents the length of the rectangle.
The second line of input consists of an integer, which represents the width of the rectangle.
The third line of input consists of an integer, which represents the side of the square.
Output format :
The first line of output displays "Rectangle Area: X", where X is the area of the rectangle.
The second line of output displays "Rectangle Perimeter: Y", where Y is the perimeter of the rectangle.
The third line of output displays "Square Area: Z", where Z is the area of the square.
The last line of output displays "Square Perimeter: W", where W is the perimeter of the square.
Code constraints :
In the given scenario, the test cases fall under the following constraints:
Aim
TANYA K 710723244057
Algorithm
TANYA K 710723244057
Program
TANYA K 710723244057
Output
TANYA K 710723244057
TANYA K 710723244057
Result