C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 18.11E
Program Plan Intro
Program plan:
- Define class Polynomial. Inside this class,
- Include a private data members size of type int and coefs array of type double.
- Include a default constructor to initialize size to 1 and coefs to 0.
- Include a parametrized constructor to initialize size and coefsarray to user defined values.
- Overload arithmetic operators for this class using through friend function.
- Overload input output operators for this class.
- Overload relational operator for this class.
- Define a main function. Inside main function,
- Define four objects p1, p2, p3 and p4 of Polynomial class.
- Define an array a and a4 of type double holding coefficients.
- Use coefficients in array ato initialize polynomial p1 and p2 and array a4 to initialize polynomial p4.
- Then apply all the overloaded operators on these four objects.
Program Description: The following program will create a Polynomial class to represent the polynomials and include functions for operations on these polynomial like base data types.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Develop class Polynomial . The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent—e.g., the term 2x4has the coefficient 2 and the exponent 4. Develop a complete class containing proper constructor and destructor functions as well as set and get functions. The class should also provide the following overloaded operator capabilities: "Overload the subtraction operator ( - ) to subtract two Polynomial s."
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.…
(java)
The Painting Subclass
Write class as follows:
The class is named Painting, and it inherits from the Art class.
It has a private String member variable named medium
It has a default constructor that assigns the values "No name" to name, "No artist" to artist, -1 to year, and "No medium" to the medium variable. This default constructor calls the four-argument constructor.
It has a four-argument constructor to assign values to the name, artist, year, and medium variables.
It has a getter and settersfor the medium 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.
Chapter 18 Solutions
C How to Program (8th Edition)
Ch. 18 - (Memory Allocation and Deallocation Operators)...Ch. 18 - (Overloading the Parentheses Operator) One nice...Ch. 18 - (Complex Class) Consider class Complex shown in...Ch. 18 - (HugeInt Class) A machine with 32-bit integers can...Ch. 18 - (RationalNumber Class) Create a class...Ch. 18 - Prob. 18.11E
Knowledge Booster
Similar questions
- (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_forwardInstructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and…arrow_forward(Triangle class) Design a new Triangle class that extends the abstract Geometricobject class. Draw the UML diagram for the classes Triangle and Geometricobject then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filed. The program should create a Tri- angle object with the se sides, and set the color and filled properties using the input. The program should display the area, perimeter, color, and true or false to indicate whether it is filled or not.arrow_forward
- (Triangle class) Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject and then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a colour, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the colour and filled properties using the input. The program should display the area, perimeter, colour, and true or false to indicate whether it is filled or not.arrow_forwardQuestion 5 (6 marks) Given the following interface class interface Bigoperation { public Biglnteger operation (Biglnteger x, Biglnteger y); Write Lambda expressions to implement BigOperation to simulate three arithmetic operations *, / and % on Biglnteger. You can call them op1, op2 and op3 respectively. Note that the three operations in Biglnteger are called multiply, divide and remainder respectively. Using these three operations, we wish to multiply all the digits in a Biglnteger. For example, if the Biginteger is 234, the product is 2* 3*4 = 24. The method has the following method heading: static BigInteger product (Biglnteger n, BigOperation op1, BigOperation op2, BigOperation op3) Compare the implementation of this method using two approaches: Iterative and Recursive. Put the Lambda expressions in a main method. Construct a few Biglnteger objects, invoke the methods to test our design. The following shows some of the sample outputs:arrow_forward(JAVA) Create a class hierarchy to represent the different types of employees in an office who have the following job titles: manager, assistant, salesperson. Write an abstract base class called Employee that declares an abstract method: signature double calculateSalary() This class must also define the following attributes: name (String type), enrollment (String type) and base_salary (double type). Use encapsulation and provide a constructor that receives the corresponding values to be stored in the respective attributes. This abstract class must be extended by the other classes representing the types of employees, so the classes Manager, Assistant and Salesperson must be written. In each class you must override the method calculateSalario so that the salary calculation is done like this: The manager receives twice the base_salary, the assistant receives the base_salary and the salesperson receives the base_salary plus a commission defined in the constructor of his class. Create a…arrow_forward
- [JAVA] Question 4: Write the source code of the classes ReportCurrentRevenue and ReportPastIncome. The ReportCurrentRevenue class is responsible from calculating the current amount of money to be gained if all the guests would leave from the hotel. The ReportPastIncome class is responsible from calculating the money gained so far from the previous visits of guests. Class Hotel will create one instance of this class and execute it in multithreaded fashion in its report method. You will code Hotel.report in the next question. Question 5: Write the source code of only the following methods of the class Hotel. The explanations of the methods you need to code are given below. Don’t forget to address the multithreading issues when coding. report: The details of this method are given in Question 4. restore: This method loads the Hashtable members and LinkedList visits from the path given by the fileName parameter. However, if there are ongoing multithreaded operations, it must first wait…arrow_forwardJava (derived classes) - Pet Informationarrow_forwardPlease solve quickly OOParrow_forward
- SUBJECT: OOPPROGRAMMING LANGUAGE: C++ ALSO ADD SCREENSHOTS OF OUTPUT. Write a class Distance to measure distance in meters and kilometers. The class should have appropriate constructors for initializing members to 0 as well as user provided values. The class should have display function to display the data members on screen. Write another class Time to measure time in hours and minutes. The class should have appropriate constructors for initializing members to 0 as well as user provided values. The class should have display function to display the data members on screen. Write another class which has appropriate functions for taking objects of the Distance class and Time class to store time and distance in a file. Make the data members and functions in your program const where applicablearrow_forward(2) Your member functions will be: Make sure that the mutators for height and width only take positive numbers! Test your class with the driver program given below. //--- Test driver for class Rectangle #include using namespace std; setHeight (int h): mutator for height variable setWidth (int w): mutator for width variable setDimensions (int h, int w): sets both height and width getArea (): returns the area of the rectangle getPerimeter () returns the perimeter of the rectangle print (): prints a rectangle with your dimensions composed of asterisks (3) Create a default constructor that sets the default values of Rectangle class to 1. int main() { Rectangle rec rec2; recl.setHeight (10); recl.setWidth (20); Page rec2.setDimensions (5, 10); cout of 2 ZOOM +arrow_forward(JAVA) What is the benefit of an abstract class? Group of answer choices A) There is a guarantee that all classes that inherit from the abstract class have the methods and fields of the abstract class. B) They cannot be instantiated, so you only need to write the code for the fields and methods that are common to all classes that extend it. You also need to initialize those fields in a constructor. C) All choices are correct. D) All classes that extend the abstract class will automatically inherit all the methods from the abstract classes without need to implement them again.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning