Skip to content

Python Question(for detail see in description) based on oops. #7

Description

@UpstartLeague

create a class called RationalNumber for performing arithmetic with fractions. Write a driver program to test your class.
Use integer variables to represent the data of the class—the numerator and the denominator.
Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values, in case no initializers are provided, and should store the fraction in reduced form (i.e., the fraction 2/4 would be stored in the object as 1 in the numerator and 2 in the denominator).
Provide methods for each of the following:
a) Adding two RationalNumbers. The result should be stored in reduced form.
b) Subtracting two RationalNumbers. The result should be stored in reduced form.
c) Multiplying two RationalNumbers. The result should be stored in reduced form.
d) Dividing two RationalNumbers. The result should be stored in reduced form.
e) Printing RationalNumbers in the form a/b, where a is the numerator and b is the denominator.
f) Printing RationalNumbers in floating-point format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coulCode_for_UpstartLeaguegood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions