Question: Problem 7: Classes Again Suppose you are writing a quilt design program. One type of quilt the program will be used to design is a
Problem 7: Classes Again Suppose you are writing a quilt design program. One type of quilt the program will be used to design is a quilt that consists of a large grid of squares. Each square will have a certain pattern, and that pattern will be oriented in a certain way. So, for example, a square might have a pinstripe pattern that is rotated 45 degrees from its usual orientation. Each pattern has a C++ string name such as pinstripe, plaid, or polka dot. The rotation is an integer angle between 0 and 359 degrees. (a) Write an interface file Quilt.hpp and an implementation file Quilt.cpp that contain the following: In the Quilt.hpp file, before the class declaration, declare two constant integers NUM ROWS and NUM COLS, and set NUM ROWS to 5 and NUM COLS to 4. Two member variables, each of which is a 2D array with NUM ROWS rows and NUM COLS columns. The first of these is a 2D array of strings that contains the patterns for the corresponding square in a quilt, and the second is a 2D array of ints containing the orientations for the corresponding squares. A default constructor that sets all square patterns to background and all square orientations to 0. An accessor member function string getPattern(int row, int column) const that returns the pattern of the square at the given row and column. Anaccessormemberfunctionint getOrientation(int row, int column) const that returns the orientation of the square at the given row and column. Amutatormemberfunctionvoid setPattern(int row, int column, string s) that sets the pattern for the square at the given row and column to the string s. A mutator member function void setOrientation(int row, int column, int deg) that sets the orientation for the square at the given row and column to the value deg. An overloaded output (<<) operator that is a friend function of the class, and that prints out all squares patterns and orientations in some reasonable format. (b) Write a main program that sets up a quilt object using the default quilt constuctor, and then goes through the quilt square by square, asking the user to input a pattern and orientation for each square. When the user has input all that information the program should print out the object information using the overloaded output operator. (c) Modify your main program so that after the user inputs the quilt object patterns and orientations, the program asks them for a search string p, and an integer newDeg. Then write a function that takes as arguments this quilt object (call it q), the string p, and the integer newDeg. The function should construct and return another Quilt object that is the same as q, only in the returned object any square whose pattern string equals p should have its orientation be newDeg instead of the orientation in q. Then the main program should print out, using the overloaded output operator, both q and the Quilt object returned from the function.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
