Concept explainers
(Rational Class) Create a class called Rational for performing arithmetic with fractions. Write a
would be stored in the object as 1 in the numerator and 2 in the denominator. Provide public member functions that perform each of the following tasks:
- Adding two Rational numbers. The result should be stored in reduced form.
- Subtracting two Rational numbers. The result should be stored in reduced form.
- Multiplying two Rational numbers. The result should be stored in reduced form.
- Dividing two Rational numbers. The result should be stored in reduced form.
- Printing Rational numbers in the form a/b, where a is the numerator and b is the denominator.
- Printing Rational numbers in floating–point format.
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Computer Systems: A Programmer's Perspective (3rd Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with C++: Early Objects (9th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
- (Account class)Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member of type int to represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it’s greater than or equal to 0. If not, set the balance to 0 and display an error message indicating that the initial balance was invalid. Provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money from the Account and ensure that the debit amount does not exceed the Account’s balance. If it does, the balance should be left unchanged, and the function should print a message indicating "Debit amount exceeded account balance." Member function get_Balance should return the current balance. Create a program that creates two Account objects and tests the member functions of class…arrow_forward(Java) The Sculpture Subclass Write class as follows: The class is named Sculpture, and it inherits from the Painting class. It has a private boolean member variable named humanForm It has a default constructor that assigns the values "No name" to name, "No artist" to artist, -1 to the year, "No medium" to the medium, and false to the humanForm variable. This default constructor calls the five argument constructor. It has a five-argument constructor to assign values to the name, artist, year, medium, and humanForm variables. It has a getter and setter for the humanForm variable. It has a toString() method. This class contains no other methods Make sure to include your name, the name of this class, our course number, and the Activity number in a Javadoc comment at the top. Make sure to write a Javadoc comment for each of these methods.arrow_forward(Java) The Abstract Art Class Write an abstract class as follows: The class is named Art It inherits from the Comparable interface It has a private String member variable named name It has a private String member variable named artist It has a private int member variable called year It has a default constructor that assigns the values "No name" to name, "No artist" to artist and -1 to the year. This default constructor calls the three argument constructor. It has a three-argument constructor to assign values to the name, artist and year variables. It has a copy constructor that makes a copy of another non-null Art object It has getters and setters for the name, artist and year variables It has a toString() method that creates a string of artist, with name and year tabbed once on subsequent lines (see sample output) It has an equals method that compares this Art to another Object It has a compareTo method that compares in this order: 1) artist, 2) name, 3) year This class contains no…arrow_forward
- (Person Class) Design a class named Person that contains: o name, gender, and personCase as a private attribute o Non-default constructor that specifies name and gender o toString method that returns person data o personCase () method with no implementation (Student Class) Design a class named Student which is a child of Person that contains: o studentID as a private attribute o Nondefault constructor that specifies the name, gender, and studentID o toString method that returns student data o Implement personCase () that assigns "Not Studying" to personCase if studentID equals 0, “Studying" in case studentID greater than 0, and "Not a student" in case studentID less than 0. (Employee Class) Design a class named Employee which is a child of Person that contains: o employeelD as a private attribute o Non-default constructor that specifies the name, gender, and employeelD o toString method that returns employee data o Implement personCase () that assign “Technical" to personCase if…arrow_forward(The Fan class) Design a class named Fan to represent a fan. The class contains:■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to denotethe fan speed.■ A private int data field named speed that specifies the speed of the fan (the default isSLOW).■ A private boolean data field named on that specifies whether the fan is on (the default is false) ■ A private double data field named radius thatspecifiesthe radius of the fan (the default is5).■ A string data field named color thatspecifiesthe color of the fan (the default is blue).■ The accessor and mutator methodsfor all four data fields.■ A no-arg constructorthat creates a default fan.■ A method named toString() that returns a string description for the fan. If the fan is on, the method returns the fan speed, color, and radius in one combined string. If the fan is not on, the method returns the fan color and radius along with the string “fan is off” in onecombined string.Draw the UML diagram for the class and…arrow_forward(In python please) Q#4 Write a class named Patient that has attrib already have the code written I just need to know how to total the bill portion.utes for the following data: First name and last name Date of birth Address, city, state, and ZIP code Phone number The Patient class’s _ _init_ _ method should accept an argument for each attribute.Next, write a class named Appointment that represents an appointment that is assigned to a patient.The Procedure class should have attributes for the following data: Date of the appointment Reason of the appointment Name of the practitioner who visited a patient Bill for the appointment The Appointment class’s _ _init_ _ method should accept an argument for each attribute. Next, write a program that creates an instance of the Patient class, initialized with sample data. Then, create three instances of the Appointment class, initialized with the following data: Appointment #1: Date: 04/15/2021 , Reason: Physical Exam, Practitioner: Dr.…arrow_forward
- Problem (Online Address Book): Using classes, design an online address book to keep track of the names, addresses, phone numbers, and dates of birth of family members, close friends, and certain business associates. Define a class addressType that can store a street address, city, state, and ZIP code. Use the appropriate functions to print and store the address. Also, use constructors to automatically initialize the member variables. Define a class extPersonType using the class personType with following members and methods: firstname, lastname, and accessors and mutators, print to display, and constructors. Define a class dateType for month, day and year as members with its accessors, mutators, and constructors) Design a class addressType. Add a member variable to this class to classify the person as a family member, friend, or business associate. Also, add a member variable to store the phone number. Add (or override) the functions to print and store the appropriate information.…arrow_forwardState whether it's tru or false .arrow_forward(After reading the instructions given in the pictures attached, read the following) Class membersdoctorType Class must contain at least these functionsdoctorType(string first, string last, string spl); //First Name, Last Name, Specialty void print() const; //Formatted Display First Name, Last Name, Specialtyvoid setSpeciality(string); //Set the doctor’s Specialtystring getSpeciality(); //Return the doctor’s SpecialtypatientType Class must contain at least these functionsvoid setInfo(string id, string fName, string lName,int bDay, int bMth, int bYear,string docFrName, string docLaName, string docSpl,int admDay, int admMth, int admYear,int disChDay, int disChMth, int disChYear);void setID(string);string getID();void setBirthDate(int dy, int mo, int yr);int getBirthDay();int getBirthMonth();int getBirthYear();void setDoctorName(string fName, string lName);void setDoctorSpl(string);string getDoctorFName();string getDoctorLName();string getDoctorSpl();void…arrow_forward
- Nonearrow_forward- Create a class Rational for performing arithmetic with fractions.Write a driver program to test the class. Provide a constructor thatenables an object of this class to be initialized when it isinstantiated. The constructor should contain default values in caseno initializes are provided and should store the fraction in reducedform. Provide a private function to reduce numbers.Provide Public member functions for each of the followingarithmatic’s functions (addition – subtraction – multiplication –division), printing in the form a/b, printing in floating point formatand final overload the == and != operators to allow comparisons oftwo fraction numbers.Include any additional operations that you think would be useful fora rational number class.Design, implement, and test your class.arrow_forward(Invoice Class) Create a class called Invoice that a hardware store might use to representan invoice for an item sold at the store. An Invoice should include four data members—a part number (type string), a part description (type string), a quantity of the item being purchased (typeint) and a price per item (type int). Your class should have a constructor that initializes the fourdata members. A constructor that receives multiple arguments is defined with the form:ClassName( TypeName1 parameterName1, TypeName2 parameterName2, ... )Provide a set and a get function for each data member. In addition, provide a member functionnamed getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by theprice per item), then returns the amount as an int value. If the quantity is not positive, it should beset to 0. If the price per item is not positive, it should be set to 0. Write a test program that demonstrates class Invoice’s capabilitiesarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education