C++

Assume the existence of a Window class with integer data members width and height. Overload the << operator for the Window class-- i.e., write a nonmember ostream-returning function that accepts a reference to an ostream object and a constant reference to a Window object and sends the following to the ostream: 'a (width x height) window' (without the quotes and with width and height replaced by the actual width and height of the window. Thus for example, if the window had width=80 and height=20, << would send 'a (80 x 20) window' to the ostream object.) Don't forget to have the function return the proper value as well. Assume the operator has been declared a friend in the Window class.

Answers

Answer 1

Answer:

Following are the code to the given question:

#include <iostream>//header file

using namespace std;

class Window //defining a class Window

{

private:

int width, height;//defining integer variable

public:

friend ostream& operator << (ostream& stm, Window& width)//defining a friend function that takes two parameters

{

return stm<<"a ("<<width.width<<" x "<<width.height<<") window"; //use return keyword that return its values

}  

Window(int width, int height): width(width), height(height)//defining parameterized constructor that inherit width and height in its parameters  

{}

};

int main() //Main method

{

Window w(80,90);//calling class constructor

cout<<w;//print object value

return 0;

}

Output:

a (80 x 90) window

Explanation:

In the above code, a class "Window" is defined that uses a friend function "ostream& operator" is declared that uses the "ostrea&" as a data type to hold two-variable "stm and w" in its parameter, and declared the parameterized constructor to hold value by inheriting width and height in its parameters.

Inside the main method, a class object is created that calls the constructor and uses the print method to print object value.


Related Questions

What does input allow a computer to do

Answers

In computer science, the general meaning of input is to provide or give something to the computer, in other words, when a computer or device is receiving a command or signal from outer sources, the event is referred to as input to the device.

Explain what Fahd did wrong in the scenario below. Fahd is running ten programs at once on his laptop when it suddenly freezes up. To fix this problem, Fahd buys a new battery for his laptop.

Answers

Answer:

Well first off. if the laptop froze that doesn't mean the battery is dead to the point where a simple rest of the laptop wouldn't work out.

What is an example of a composite key in a database table?

InvoiceID
CustomerID
ProductID
OrderID + ProductID

Answers

Answer:

b

Explanation:

OrderID + ProductID is an example of a composite key in a database table. The correct option is 4.

What is composite key?

A composite key is a key in a database table that consists of two or more columns that uniquely identify each row.

In a database table, a composite key is the combination of OrderID and ProductID in a table that tracks sales transactions.

Because a single order can contain multiple products and multiple orders can contain the same product, neither column can uniquely identify a row by itself.

However, by combining the two columns, each row can be uniquely identified, ensuring that the data is accurate and complete.

Similarly, a combination of CustomerID and ProductID might be used in a sales system to track the products purchased by each customer.

Thus, the correct option is 4.

For more details regarding composite key, visit:

https://brainly.com/question/10167757

#SPJ3

Other Questions
3/10 = N/10Find the missing value to write an equivalent fraction.Multiply the numerator and denominator by .The missing numerator is . Subtract 4 from 9 then subtract 5 from the result written expression for the sequence of operations described below Milk is a very weak acid. What might its pH value be ? Find the slope of the line with x intercept 9 and y intercept of -2 t/15=3 what operation is that? An example of a host-based intrusion detection tool is the tripwire program. This is a file integrity checking tool that scans files and directories on the system on a regular basis and notifies the administrator of any changes. It uses a protected database of cryptographic checksums for each file checked and compares this value with that recomputed on each file as it is scanned. It must be configured with a list of files and directories to check and what changes, if any, are permissible to each. It can allow, for example, log files to have new entries appended, but not for existing entries to be changed. What are the advantages and disadvantages of using such a tool? Consider the problem of determining which files should only change rarely, which files may change more often and how, and which change frequently and hence cannot be checked. Hence consider the amount of work in both the configuration of the program and on the system administrator monitoring the responses generated. The brain can affect the way the body functions but the body can not affect the way the brain functions. A.TrueB.False Essence of Skunk Fragrances, Ltd., sells 5,750 units of its perfume collection each year at a price per unit of $445. All sales are on credit with terms of 1/10, net 40. The discount is taken by 35 percent of the customers.Required:What is the amount of the company's accounts receivable? What Does You cant have your cake and eat it too. Mean? plz help me i need this done soon Andrew wants to write about what life was like for regular people living during the Civil War. If he searches "American Civil War," his results will be too broad.Which search term should he use to narrow the results?life of American Civil War peopleAmerican Civil War normal peopleAmerican Civil War causes and effects on peoplehow people lived during the American Civil War Mixing chemicals in a cold pack creates a reaction that:absorbs heatdestroys heatreleases coldnone of the above What can lead to being curious and also lead to fascinating scientific investigations? a. Questions b. Answers c. Qualitative Measurements d. Quantitative Measurements Kianna started her homework at 4:30 pm. She finished at 5:05 pm. How many SECONDS did it take her to finish her homework? *1 point solve for x.hint: use your knowledge of parallel lines. what do you know about these angles? are they congruent or supplementary? Sylvia owns a large media firm. she organizes a lunch meeting to announce a minor change in the management hierarchy to her all employees. which type of communication has Sylvia used? A. Interpersonal communicationB. departmental communicationC. interdepartmental communication D. Company wide communication Can someone help me with this. Will Mark brainliest. plz answer ASAP tysm ! GUYS PLEASE HELP I WILL GIVE U BRAINLIEST. NO LINKS PLEASE OR YOULL BE REPORTED. 21 = -3c + 7 -5c -2i need help with this multi step equation question