0% found this document useful (0 votes)
89 views25 pages

Inheritance 57

dcsd

Uploaded by

23cb057
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views25 pages

Inheritance 57

dcsd

Uploaded by

23cb057
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

TANYA K 710723244057

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 :

The output displays the book details.

Refer to the sample output for the formatting specifications.

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]"

Refer to the sample output for the formatting specifications.

Code constraints :

The test cases will fall under the following constraints:

1 <= age, gradeLevel <= 100

The length of the name is at most 100 characters.

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.

The Student class should have the following:

A Student class constructor, which has the parameters:

A string - first name.

A string - last name.

An integer - id.

An integer array of test scores.

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 third line of input consists of an integer representing the id.

The fourth line of input consists of the number of test scores.

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.

Refer to the sample output for formatting specifications.

Code constraints :

0 <= test scores <= 100

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.

Refer to the sample output for the formatting specifications.

Code constraints :

In the given scenario, the test cases fall under the following constraints:

1 ≤ length of the rectangle ≤ 40

1 ≤ width of the rectangle ≤ 40

1 ≤ side of the square ≤ 40

Aim
TANYA K 710723244057

Algorithm
TANYA K 710723244057

Program
TANYA K 710723244057

Output
TANYA K 710723244057
TANYA K 710723244057

Result

You might also like