Here is a definition of a class called Pairs. Objects of type Pairs can be used in any situation where ordered pairs are needed. Your task is to write implementations of the overloaded operator >> and the overloaded operator << so that objects of class Pairs are to be input and output in the form (5,6)(5,−4)(−5,4) or (−5,−6). You need not implement any constructor or other member, and you need not do any input format checking.
#include <iostream> using namespace std; class Pairs { public: Pairs( ); Pairs(int first, int second); //other members and friends friend istream& operator >>(istream& ins, Pairs& second); friend ostream& operator <<(ostream& outs, const Pairs& second); private: int f; int s; }; |
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Introduction To Programming Using Visual Basic (11th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with Python (4th Edition)
Mechanics of Materials (10th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- CPSC 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_forwardWrite c# equivalent statements for the following: There is a book library. Define classes respectively for a library. The library must contain a name and a list of books (use array). The books only contain author name as information. In the class, which describes the library, create methods to add a book to the library, to search for a book by a predefined author, and to delete a book from the library. Write a test class, which creates an object of type library, adds several books to it. Implement a test functionality, which finds all books authored by Stephen King and deletes them. Finally, display information for each of the remaining books.arrow_forwardOperator overloading can’t be applied to following operatorsA. Class member access operators (., .*)B. Sizeof C. Conditional operators (?:)D. Pointers (*)arrow_forward
- Suppose that a class is defined to represent a deck of cards or a player's hand in a card game. This class is implemented as below: A class, also, is defined to develop a card game in which a list of all players' names and their hand is stored. Part of the implementation of this class looks like the following code: A) Specify what should be the return type of getPlayersHand()? B) Assume that the cardGame is a composition of Deck. With this assumption, i) implemnt getPlayerHand(). ii) implement the overloaded constructor of Deck. No java methods can be used for part ii. C) Assume that cardGame is an aggregation of Deck. With this assumption, implement getPalyerHand(). D) An equals() method has been implemented for Deck class. Fill in the gaps to create a fully working equals() method.arrow_forwarduse java (ArrayList, inheritance, polymorphism, File I/O and basic Java) Student class: First, you need to design, code in Java, test and document a base class, Student. The Student class will have the following information, and all of these should be defined as Private: A first name (given name) A last name (family name/surname) Student number (ID) – an integer number (of type long) The Student class will have at least the following constructors and methods: (i) two constructors - one without any parameters (the default constructor), and one with parameters to give initial values to all the instance variables of Student. (ii) only necessary set and get methods for a valid class design. (iii) a reportGrade method, which you have nothing to report here, you can just print to the screen a message “There is no grade here.”. This method will be overridden in the respective child classes. (iv) an equals method which compares two student objects and returns true if they…arrow_forwardNovice: How can i access a main class objects from outside the function? / Better Alternative? If i have 4 Student objects how can i print the information for the specific object given one parameter about the class, like the students Idnumber. What i came up with was making a checkId void function that takes the user input and runs an if else chain checking if the Id belongs to student 1-4 then printing the details of that classes object with the void function print. ideally i would want the if-else chain in the checkId function to call the print( student1-4) class object but im not sure how to properly do that. i dont think this is the best way to go about it, if you have any recommendations or alternatives please help me out.arrow_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_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_forwardIntegrate the constructor and compute method of the doubler class. The constructor should be set to startingVal and n member variables. The compute method should double the startingVal in n times and return the result asarrow_forward
- Please add a destructor to the code. Solve this in C++arrow_forwardWrite a base class (Person) that has the following data members: String name, long NID, int age. Your class (Person) should have setters and getters for all data members. Derive a class (Student) from class (Person). Class student should have the following private data members: Int id, double GPA, string major. Class (Student) should have setters and getters for its private data members. In your main function, create an object of class (Student) and set all of its data members.arrow_forwardOOPS ANS.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning