Self-Test Exercise 17 asked you to overload the operator >> and the operator << for a class Pairs. Complete and test this exercise. Implement the default constructor and the constructors with one and two int parameters. The one-parameter constructor should initialize the first member of the pair; the second member of the pair is to be 0. Overload binary operator+ to add pairs according to the rule
(a, b) + (c, d) = (a + c, b + d)
Overload operator– analogously.
Overload operator* on Pairs and int according to the rule
(a, b) * c = (a * c, b * c)
Write a program to test all the member functions and overloaded operators in your class definition.
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Concepts Of Programming Languages
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Computer Science: An Overview (12th Edition)
- JAVA-Homework Write a Java program to create Human as a class with Hpersonname and Hpersonage as members of class HUman, and can make employee and Lecturer as the subclasses of Human (a class can have any number of subclasses). In the employee class, we can define grade member and in the Lecturer class also income member will be defined. 1. The program must be able to store information about employee and Lecturer. we want to store the Hpersonname and Hpersonage with grade of employee and the Hpersonname and Hpersonage with income of lecturer.arrow_forwardLocalResource(String date, String sector)- Actions of the constructor include accepting a date in the format “dd/mm/yyyy”, initializing the base class, storing the sector and storing an id as a consecutively increasing integer. Note that the constructor must ensure that the date of birth information is recorded. b. getId():Integer - returns the ID of the current instance of LocalResource c. getSector():String – returns the sector associated with the current instance of localResource d. getTRN():String – returns the trn number of the current instance of LocalResource. The process used to determine the TRN is to add the id to the number 100000000 and then returning the string equivalent. e. Update the NineToFiver class to ensure it properly extends the LocalResource class f. In method getContact() of NineToFiver, remove the comments so that the method returns "Local Employee #"+and the id of the contact. Write a concrete class LocalConsultant that extends LocalResource, and implements…arrow_forwardPython Program: Auction Housearrow_forward
- 1- Write a class that allows you to define complex numbers in C++ and call it complex. The class contains two private members named real and img. It also has a constructor to initialize its members to values other than zero. Then, write a four methods that implement the basic mathematical operations (+,-.*) for two complex numbers. 2- The purpose of the method resize() in the IntegerArray class below is to dynamically change the size of the IntegerArray instance. This methid is implemented as follows: 1. create a new array with the desired size 2. copy the data form the old to new one 3. delete the old data 4. Make the old data pointer points to the newly created data 5. update the size field your task is to write the resize() method based on the above five steps. #include int main() { using namespace std; IntegerArray a(2); a.data[0] = 4; class IntegerArray { public: a.data[1] = 2; int *data; a.resize(5); int size; cout size = size; solve number 2 } -IntegerArray()) { delete[] data;…arrow_forwardC++ program Implement a class with the required data fields, constructor, and setter/getter for each of the private data members, and a print() member function. In your program, the class must be fully tested. Implement a class Book. A book has a title, author, year of publication, and ISBN number. Implement a member function toBibtex() that returns a BibTeX string that describes the book. Also please if you are able give me documentation of your work because i need it too.arrow_forwardobjective of the project: Implement a class address. An address has a house number street optional apartment number city state postal code. All member variables should be private and the member functions should be public. Implement two constructors: one with an apartment number one without an appartment number. Implement a print function that prints the address with the street on one line and the city, state, and postal code on the next line. Implement a member function comesBefore that tests whether one address comes before another when the addresses are compared by postal code. Returns false if both zipcodes are equal. Use the provided main.cpp to start with. The code creates three instances of the Address class (three objects) to test your class. Each object will utilize a different constructor. You will need to add the class definition and implementation. The comesBefore function assumes one address comes before another based on zip code alone. The test will also return…arrow_forward
- •Person Class: Person class has attributes: String name, address and int age. Write setperson() function to set values and getPerson() to Print attributes. Also write appropriate constructors. •Employee Class: Write another class Employee having attributes department and salary of type string and double. Write methods setEmployee(), getEmployee() and appropriate constructors for Employee class. •Student Class: •Write a class Student having attributes registration number and GPA of type string and float. Also write setStudent(), getStudent() methods and required constructors. Use the concept of inheritance to achieve the above functionality. Write a main() function to display the information of employee and student. • Note: Call the constructors/methods of parent class in child class where requiredarrow_forward•Person Class: Person class has attributes: String name, address and int age. Write setperson() function to set values and getPerson() to Print attributes. Also write appropriate constructors.•Employee Class: Write another class Employee having attributes department and salary of type string and double. Write methods setEmployee(), getEmployee() and appropriate constructors for Employee class.•Student Class:•Write a class Student having attributes registration number and GPA of type string and float. Also write setStudent(), getStudent() methods and required constructors. Use the concept of inheritance to achieve the above functionality. Write a main() function to display the information of employee and student.• Note: Call the constructors/methods of parent class in child class where required in java codearrow_forwardSUBJECT: 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
- Create a Pair class in C++ with the members x, y and also overload the + operator to add the values of x separately and the values of y separately for two objects of the Pair class. Also, write a parameterized constructor for the class. Public Members: int x, int y Function: Overload the + operator. Constructor: Parameterized.arrow_forwardTalking: Heba Abde QUESTION 1: Implement class myTime, this class should: 1) Encapsulate information about the hours (integer), minutes (integer), seconds (integer), AM PM (String) 2) Forbid invalid times, where the following criteria should be considered: - hours are in the range [1 – 12], default is 12. - minutes are in the range [0 – 59], default is 0. - seconds are in the range [0-59], default is 0. - AM PM can only be either “AM" or "PM", default is "AM" If any forbidden value entered, you should set the value to default value. 3) Two different constructors (default and parameterized) 4) A print function that will print the time as (hours : minutes : seconds PM/AM) Example: 02:45:30 PM 6) implement function ticktack, which adds one to the seconds, notice that if seconds is 59 and you add one, it should become 0 and the minutes should be incremented by one, also, if after incrementing minutes by one it becomes 60, it should be set to 0 and hours must be incremented by 1, if after…arrow_forwardCPSC 131: Introduction to Computer Programming IIProgram 3: Inheritance and Interface1 Description of the ProgramIn this assignment, you will make two classes, Student and Instructor, that inherit from asuperclass Person. The implementation of class Person is given. You will also need to writea test program to test the methods you write for these two classes. The implementationdetails are described as follows.Stage 1: In the first file Student.java, you should include the following additional instancevariables and methods (other than all instance variables and methods inherited from classPerson):• Private instance variables studentID, and major;• A constructor takes four inputs (name, age, studentID and major);• Two additional getter methods to return each of instance variables (accessor);• Two setter methods to change each of instance variables (mutator);• A method toString that converts a student’s information into string form. Thestring should have the format as shown in Figure 1.…arrow_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