Question

Your will write a class named Gasket that can be used to build Gasket objects (that...

Your will write a class named Gasket that can be used to build Gasket objects (that represent Sierpinski gaskets) that you can display graphically.  Your Gasket class is defined in the provided file Gasket.h.   DO NOT CHANGE the file Gasket.h.  The attributes and methods defined for class Gasket are described below.    

·sideLength            an int that holds the length of each side of the Gasket.  The length of the side is measured as a number of pixels

·xLocation              an int that holds the x coordinate (in pixels) of the upper left hand corner of the Gasket (left end of the base of the largest triangle in the Gasket)

·yLocation              an int that holds the y coordinate (in pixels) of the upper left hand corner of the Gasket (right end of the base of the largest triangle in the Gasket)

·iterations              The number of iterations.  One iteration consists of dividing each triangle in the list of triangles in the gasket into parts using TriangleDivide.

·gasketColour        an object of type Colour (the Colour class is provided for you) that holds the colour that the plotted Triangles in the Gasket will have

·lenSubTriList         an int that holds the number of triangles in the array of Triangles that are contained in the gasket.

·listOfSubTriangles         a pointer to a Triangle (to be used for dynamically allocation the array of Triangles of length lenSubTriLIst)   

In addition your class should have the following constructors and public member functions. The prototypes for all the following functions are given in the class definition provided for you in file Gasket.h. You must use the file Gasket.h as part of your class. DO NOT CHANGE the file Gasket.h.

§ Default constructor (sets private member sideLength to 100, members xLocation and  yLocation and iterations to 0, members lenSubTriList to 1 and allocates the dynamic memory for an array containing 1 triangle.   The default constructor sets gasketColour to black (0, 0, 0.255)

§ Constructor that initializes iterations, sideLength, xLocation,  yLocation and gasketColour to the provided values of the corresponding actual arguments in the constructor call. This constructer calculates the length of the list of Triangles needed and allocates an array large enough to hold all triangles at the iteration given by the value of the iterations member.  The constructor builds the gasket by calling private member function GasketDIvide once for each iteration.

§ Copy constructor

§ Destructor

§ Accessor functions to access private members xLocation, yLocation, iterations, sideLength and gasketColour

§ Mutator functions to access private members xLocation, yLocation, iterations, sideLength and gasketColour  (mostly provided)

§ An overloaded print function which prints the values of each private member in the Gasket Class.  (use same format as you did for the Rectangle class).  This function also prints each Triangle in the Gasket.

§ Member function GasketDisplay.  You can create this function without directly calling the bitmap library.  You need to print each triangle in the Gasket using the TriangleDisplay function

§ Boolean private member function GasketDivide (provided).  GasketDivide creates a Sierpinski Gasket.  The results expected are shown below for some values of the number of iterations.  Member function GasketDivide takes the list of triangles for iteration n-1 and divides each of them into 3 triangles using TriangleDIvide.  This makes a new list of Triangles for iteration n

The array of triangles passed to the GasketDivide function must be at least 3 times longer than the list of triangles to be divided. When GasketDivide  has completed the array of Triangles will hold a list of triangles containing 3 times as many triangles.

// Each Gasket has the a length (x extent)
// a width (y extent), a location used for graphic
// display (xlocation, ylocation), and a color
// for grapic display.All distances and
// locations are integers (number of pixels)
// The upper right hand corner is (0,0)
// y coordinate increased downward
// Author: Janice Regan March 2006

//#pragma warning(disable: 4996)

#ifndef GasketFlag
#define GasketFlag

#include <iostream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <iomanip>
#include "Colour.h"
#include "Triangle.h"
using namespace std;


class Gasket
{
public:
//default constructor: no arguments, no return type
//define if class has any other constructors, or if class
//includes deep memory (pointers) or static counters
Gasket();
//other intializing constructors
Gasket( int iterationsValue, int xLocationValue, int yLocationValue,
int sideLengthValue, Colour gasketColourValue);
   Gasket(const Gasket& toBeCopied);
~Gasket();

//accessor functions
   int GetIterations() const;
   int GetXLocation() const;
int GetYLocation() const;
   int GetSideLength() const;
Colour GetGasketColour() const;


//mutator functions,
void SetIterations(const int iterationsValue);
void SetXLocation(const int xLocationValue);
void SetYLocation(const int yLocationValue);
   void SetSideLength(const int sideLengthValue);
void SetGasketColour(const Colour gasketColorValue);

//member function to plot a Gasket to a bitmap
//myImageValue is a bitmap
void GasketDisplay(BMP& myImageValue, int thisIter, string theOutputFile);
void GasketPrint();

private:
   // helper functions
   void GasketDivide(Triangle* listOfSubTriangles, int numTriangleToDivide);
// Members expressing properties of a Gasket
   int xLocation;
   int yLocation;
   int iterations;
   int sideLength;
   Colour gasketColour;
   Triangle* listOfSubTriangles;
   int lenSubTriList;
};


#endif

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include "Gasket.h"
#include "Colour.h"

double GASKET_SIDE_TO_HEIGHT = 0.86666666;


void Gasket::GasketDivide(Triangle* listOfSubTriangles, int trianglesIn)
{
   if(trianglesIn <= 0 || trianglesIn >= static_cast<int>(pow(3,iterations) ) )
   {
       cerr << " illegal number of triangle in Gasket Divide";
       exit(1);
   }
   else
   {
       for (int k = trianglesIn-1; k >= 0; k--)
       {
           listOfSubTriangles[k].TriangleDivide(&listOfSubTriangles[k*3] );
       }
   }
}


// Requested Get of accessors (Get functions)
// to Get the values of each of the
// variable members of the class Gasket

// Requested Set functions to Set each of the variable members
// of class Gasket from outside of class Gasket.
// There is interaction between the members length width and area
// so Setting the variable member itself is not always adequate
// other calculations may be needded to maintain the consistancy
// of the instance of the class (the object)

void Gasket::SetIterations( const int iterationsValue)
{
    iterations = iterationsValue;
   lenSubTriList = static_cast<int> ( pow( 3.0, iterations ) );
   delete [] listOfSubTriangles;
   listOfSubTriangles = NULL;
   listOfSubTriangles = new Triangle[lenSubTriList];
   listOfSubTriangles[0]= Triangle(xLocation, yLocation, sideLength, gasketColour);
   for (int k=1; k <= iterations; k++)
   {
       GasketDivide(listOfSubTriangles, lenSubTriList / 3 );
   }
}

void Gasket::SetYLocation(const int yLocationValue)
{
   int height = 0;
    yLocation = yLocationValue;
   //If yLocation is off the page move to 0,0
   if( yLocation >= pageLength || yLocation < 0 )
   {
       xLocation = 0;
       yLocation = 0;
   }
   height = static_cast<int>(sideLength * GASKET_SIDE_TO_HEIGHT);
   if( yLocation + height > pageLength )
   {
       sideLength = static_cast<int>( (pageLength - yLocation) / GASKET_SIDE_TO_HEIGHT );
   }
   listOfSubTriangles[0]= Triangle(xLocation, yLocation, sideLength, gasketColour);
   for (int k=1; k <= iterations; k++)
   {
       GasketDivide(listOfSubTriangles, lenSubTriList / 3 );
   }
}

void Gasket::SetSideLength(const int sideLengthValue)
{
   int height = 0;
    sideLength = sideLengthValue;
   //Check if the change in sideLiength makes the
   //Triangle extend beyond any edge of the page
   if(sideLength < 1) sideLength = 1;
   if( xLocation + sideLength > pageWidth )
   {
       sideLength = pageWidth - xLocation;
   }
   height = static_cast<int> (sideLength * GASKET_SIDE_TO_HEIGHT);
   if( yLocation + height > pageLength )
   {
       sideLength = static_cast<int>( (pageLength - yLocation) / GASKET_SIDE_TO_HEIGHT );
   }
   listOfSubTriangles[0]= Triangle(xLocation, yLocation, sideLength, gasketColour);
   for (int k=1; k <= iterations; k++)
   {
       GasketDivide(listOfSubTriangles, lenSubTriList / 3 );
   }
}

Add a comment
Know the answer?
Add Answer to:
Your will write a class named Gasket that can be used to build Gasket objects (that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds...

    USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...

  • IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as...

    IntList Recursion Assignment Specifications: You will add some additional recursive functions to your IntList class as well as make sure the Big 3 are defined. IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined...

  • This program has an array of floating point numbers as a private data member of a...

    This program has an array of floating point numbers as a private data member of a class. The data file contains floating point temperatures which are read by a member function of the class and stored in the array. Exercise 1: Why does the member function printList have a const after its name but getList does not? Exercise 2: Fill in the code so that the program reads in the data values from the temperature file and prints them to...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

  • (Classes and Objects) Design a class named Box. The class should have the following private members:...

    (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...

  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the...

    Long Answer 2: (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables...

  • Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person {...

    Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...

  • Given the following class definition in the file Classroom.h, which XXX and YYY complete the corresponding.cpp...

    Given the following class definition in the file Classroom.h, which XXX and YYY complete the corresponding.cpp file? #ifndef CLASSROOM_H #define CLASSROOM_H class Classroom public: void SetNumber(int n); void Printo const; private: int num; }; Tendif #include <iostream using namespace std; XXX void Class Room:: Set Number(int n) { nun: cout << "Number of Class Rooms: << num << endl; include "Classroom.hr vold Classroom: Print( const sinclude "Classroom.cpp" vold Classroom. Print() const #include "Classroom.h" void Class Room::Print) const #include "Classroom.cpp" void...

  • The class dateType is designed to implement the date in a program, but the member function...

    The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT