Exercise P5.18. Design a class House that defines a house on a street. A house has a house number and an (x, y) location, where x and y are numbers between –10 and 10. The key member function is plot, which plots the house. Next, design a class Street that contains a number of equally spaced houses. An object of type Street stores the first house, the last house (which can be anywhere on the screen), and the number of houses on the street. The Street::plot function needs to make the intermediate house objects on the fly, because you don’t yet know how to store an arbitrary number of objects. Use these classes in a graphics program in which the user clicks with the mouse on the locations of the first and last house, then enters the house numbers of the first and last house, and the number of houses on the street. Then the entire street is plotted.

To solve this problem, we need to design two classes: House and Street.

The House class represents a house on a street. It has two member variables: the house number and the (x, y) location. The house number is an integer value, and the location is represented by two floating-point numbers. The location is restricted to values between -10 and 10.

The key member function of the House class is plot, which plots the house on the screen. The plot function will be used in the Street class to plot the entire street.

The Street class represents a street that contains a number of equally spaced houses. It has three member variables: the first house, the last house, and the number of houses on the street. The first house and the last house are objects of the House class, and the number of houses is an integer value.

The Street class has a member function plot, which is responsible for plotting the entire street. In this function, we need to dynamically create intermediate house objects as we don’t know how many houses there will be on the street beforehand. We will use a loop to create and plot each house object.

To implement the graphics program, we need to allow the user to interactively specify the locations of the first and last house, as well as the house numbers of the first and last house, and the number of houses on the street. We can achieve this by using mouse clicks to obtain the location coordinates and asking the user for the house numbers and the number of houses through input prompts.

After obtaining the required information from the user, we can create objects of the House and Street classes and call the plot functions to display the street on the screen.

Overall, the solution involves designing and implementing the House and Street classes, creating a graphics program with user interaction, and plotting the street using the plot functions of the House and Street classes.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer