Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ OPTION A (Basic): A Seven Segment Display in Three Acts Understand the Probl

ID: 3843244 • Letter: C

Question

C++

OPTION A (Basic): A Seven Segment Display in Three Acts

Understand the Problem

In our lectures, we learned that boolean functions can be fully described by an array of bools, where the input of the function is the int index to the array, and the output is the bool value stored in that index position. We are going to wrap such an array of bools into a class called BooleanFunc(which, of course, stands for boolean function). This will represent a boolean function of any non-negative size and take precautionary measures that you would expect of a wrapper class that surrounds an unstructured type such as an array. Our goal will be to define the logic of a seven-segment display which is little more than seven boolean functions wrapped in a device that can be viewed visually.

We could do the entire project with two classes, BooleanFunc and SevenSegmentDisplay, but we will find that it is simpler to break the functionality of SevenSegmentDisplay into four classes, two of which we'll do this week (MultiSegmentLogic and SevenSegmentLogic) and two of which we'll do next week (SevenSegmentImage and SevenSegmentDisplay).

BooleanFunc will hold the truth table in a dynamic 1-D array of type bool. As we know from the modules, this tells us what the output is for any integer input, and those integer inputs are the encoded binary bits going into the table. The class allows the instantiation of any non-negative size boolean function, and once instantiated, cannot be resized (no mutator for the table size), but it can be redefined (meaning the operator=()and copy constructor could result in a totally new make-up of the object which has a different table size). Of course, it protects itself against client abuse and manages dynamic memory without leaking anything.

We will define a general base class called MultiSegmentLogic, which can be extended to cover a multi-segment display having any number of segments, but our intent is to extend it to cover a seven-segment display. We will be thinking in terms of the seven-segment displaythroughout the design of the class, but we'll design MultiSegmentLogic so that it could support a hypothetical 49-segment display, 1000-segment display or any other size the client wishes.

We will derive SevenSegmentLogic from MultiSegmentLogic, baking the specifics of a seven-segment display into this derived class.

MultiSegmentLogic, and SevenSegmentLogic are so named because they do the boolean logic of the displays, but do not actually produce any visual representation. This is not only more manageable (you would be hard pressed to do both the logic and the display in a single week), but is in keeping with the separation of interface and implementation.

Of course, we'll test our classes as we go, and you will demonstrate that your classes and methods work with a main() that tests the individual components.

Act 1: Class BooleanFunc

Summary

BooleanFunc will contain a truthTable (a dynamic array) which defines the boolean function being represented. We can load this truthTable using a mutator, setTruthTable() , and change the function it represents by calling setTruthTable() to give the table new values. We will not be able to change the size of the table (i..e. #inputs to the function) after an object is instantiated using a setTableSize-style method, but we can totally redefine the object using the assignment operator, which will have the effect of giving it a new size.. We'll need a method to evaluate the state (output) of the function based on input integers, and this will take the form or an eval( int ) method. Finally, we'll store the most recently evaluated output in an internal bool state member, so we can call eval() once, but get the resulting state later without having to re-call eval(): a method getState() will do the job nicely.

Static (Public) Members

int MAX_TABLE_FOR_CLASS = 65536; // that's 16 binary input lines

int DEFAULT_TABLE_SIZE = 16

Instance (Private) Members

int tableSize - reflects the number of inputs. tableSize of 4 would imply two binary inputs; a size of 16 would imply four binary inputs. Since we will be using one int to act as our multi-bit input, a tableSize of 4 means the valid input ints are 0-3. Size of 16 means valid input ints are 0-15.

bool *truthTable - This is our array (to be dynamically allocated and de-allocated) whose size is tableSize.

bool evalReturnIfError - This is the state (or return value) if an illegal (out-of-range) input is presented to the object -- or if no input has yet been presented to it.

bool state - this remembers the result of the most recent call to eval( int ).

Instance (Public) Methods

Constructors and a Destructor - The constructor's signature should be BooleanFunc( int tableSize = DEFAULT_TABLE_SIZE, bool evalReturnIfError = false ). More on constructors, below.

Mutators - We set the truth table not by passing an array which is an exact copy of the function table. Rather, we choose one of two mutators:

bool setTruthTableUsingTrue( int inputsThatProduceTrue[], int arraySize ) - In other words, if the function evaluates to true only for inputs 3 and 9, we would send it an array {3, 9} of size 2. This way, even if the table is very large, we can easily set it by passing a very small array in the cases where very few inputs produce true outputs. Any indices not passed in the array parameter are assumed to represent false outputs for their respective table positions.

bool setTruthTableUsingFalse( int inputsThatProduceFalse[], int arraySize ) - If the most common output is true, however, then we might prefer to use this method which has the same signature as its partner but provides an array whose values represent the false-triggering inputs. For example, if the truth table had size 64, and we wanted to represent a function "greater than 3", we would use setTruthTableUsingFalse(), and send it the array {0, 1, 2, 3}. Any indices not passed in the array parameter are assumed to represent true outputs for their respective table positions.

The return value of these two methods is true as long as the passed-in array size is <= the truth table array, and false, otherwise.. However, if a bad int is passed inside the array parameter (e.g., {5, 0, 2, 19} in the case of a 16-element truth table), we'll just ignore the bad int (19) and process the other good ints that are passed (5, 0 and 2).

bool eval( int input ) and bool getState() - a mutator for the state member based on the an input integer, which also returns that evaluated state, and an accessor for the state. If an invalid input is presented to eval(), evalReturnIfError is assigned to state and returned.

Deep memory methods - A copy constructor, destructor and assignment operator.

Supply helper methods as appropriate.

Sample Client

Here is some client code to use while debugging. You should be able to determine the correct run that results. You should provide some code that is more complete than this in your testing.

Act 2: Class MultiSegmentLogic

Summary

MultiSegmentLogic encapsulates any number of segments as a dynamic array of BooleanFunc objects and allows them to work together to produce some multi-segment display. Upon instantiation, a MultiSegmentLogic object obtains its size (the number of segments) from the user. This can be changed (a major resetting of the object) through the mutator setNumSegs(). After construction, or a resetting of the object via setNumSegs(), the truth table for each segment needs to be loaded, which is done using mutator setSegment(). setSegment() sends a BooleanFunc to a particular segment. For a seven segment display this would have to be called seven times, once for each segment. We'll do that in the derived class (Act 3), not in the client.

Static (Public) Members

(None are needed.)

Instance (Protected) Members

int numSegs - the number of BooleanFuncs (i.e., segments) that this potential display logic encapsulates. We think of this as being 7, but it can be any positive int.

BooleanFunc *segs - This is our array (to be dynamically allocated and de-allocated) whose size is numSegs.

Instance (Public) Methods

Constructors and a Destructor - The constructor's signature should be MultiSegmentLogic( int numSegs = 0 ). It has to allocate an array of numSegs BooleanFuncs. More on constructors, below.

Mutators - One that sets the number of segments and one that loads the truth table for a particular segment:

bool setNumSegs( int numSegs ) - this is a fairly serious mutator, which must completely redefine the kind of display, wiping out old segments and reallocating the new number of segments, leaving each in a default state. This is called, for example, when changing from a 7 segment to 12 segment display. Any non-negative value is allowed.

bool setSegment( int segNum, BooleanFunc &funcForThisSeg ) - it sets segs[segNum] to the passed-in BooleanFunc. It filters bad segNum and takes appropriate action.

void eval( int input ) - calls eval() for each of the segs in the object.

Deep memory methods - A copy constructor, destructor and assignment operator.

Supply helper methods as appropriate.

Sample Client

You can create and test your own sample client, but don't hand it in. I want to see the sample client of the derived class, SevenSegmentLogic, which will implicitly test MultiSegmentLogic.

Act 3: Derived Class SevenSegmentLogic

Summary

This class is derived from MultiSegmentLogic. It has no new members but adds the specifics of seven segment display logic, namely the number of segments (= 7) and the actual truth tables for a seven-segment display.

Static (Public) Members

(None are needed.)

Instance (Protected) Members

(None are needed.)

Instance (Public) Methods

Default Constructor - Simply sets the number of segments to 7 (literal ok) and the loads the BooleanFuncs for each of the seven segmentsusing a helper (see below).

bool getValOfSeg( int seg ) - Returns whatever is in the state variable of that segment. Of course checks for valid parameter.

Helper methods

You will need some private helpers to load the segments, called somewhere in the constructor.   Ultimately, somewhere you'll need to call setSegment( k, bFunc) for k = 0 through 6, where bFunc is the boolean function for the kth segment. For example, if a, b, c, d, e, f and g, are the universal names for the segments, let's say that you associate segs[0] a, segs[1] b, segs[2] c and so on.    The boolean function for segment a (your segs[0]) is easily found along with all the others, on-line. Here is the truth table for segment a:

You would, therefore, instantiate a BooleanFunc that realizes this truth table (using the BooleanFunc mutator setTruthTableUsing...()) then pass that BooleanFunc object to the setSegment() method of the base class. All of this is done in the helper function.

Here is some client code use while debugging. You should be able to determine the correct run that results. You should provide some code that is more complete than this in your testing. This example tests the copy constructor as well as the other methods.

===================

=====OUTPUT========

===================

For Act 1 and Act 3 example clients code, you should have something like this:

/* ------------------------- run test BooleanFunc ---------------------------
before eval()

A(x) = 0
B(x) = 0
C(x) = 1

looping with eval()
Input: 0
A(x) = 1
B(x) = 0
C(x) = 0

Input: 1
A(x) = 0
B(x) = 0
C(x) = 0

Input: 2
A(x) = 1
B(x) = 0
C(x) = 0

Input: 3
A(x) = 0
B(x) = 0
C(x) = 0

Input: 4
A(x) = 1
B(x) = 0
C(x) = 1

Input: 5
A(x) = 0
B(x) = 0
C(x) = 1

Input: 6
A(x) = 1
B(x) = 0
C(x) = 1

Input: 7
A(x) = 0
B(x) = 0
C(x) = 1

Input: 8
A(x) = 1
B(x) = 0
C(x) = 1

Input: 9
A(x) = 0
B(x) = 0
C(x) = 1


| 1 | 1 | 1 | 1 | 1 | 1 | 0 |

| 0 | 1 | 1 | 0 | 0 | 0 | 0 |

| 1 | 1 | 0 | 1 | 1 | 0 | 1 |

| 1 | 1 | 1 | 1 | 0 | 0 | 1 |

| 0 | 1 | 1 | 0 | 0 | 1 | 1 |

| 1 | 0 | 1 | 1 | 0 | 1 | 1 |

| 1 | 0 | 1 | 1 | 1 | 1 | 1 |

| 1 | 1 | 1 | 0 | 0 | 0 | 0 |

| 1 | 1 | 1 | 1 | 1 | 1 | 1 |

| 1 | 1 | 1 | 1 | 0 | 1 | 1 |

| 1 | 1 | 1 | 0 | 1 | 1 | 1 |

| 0 | 0 | 1 | 1 | 1 | 1 | 1 |

| 1 | 0 | 0 | 1 | 1 | 1 | 0 |

| 0 | 1 | 1 | 1 | 1 | 0 | 1 |

| 1 | 0 | 0 | 1 | 1 | 1 | 1 |

| 1 | 0 | 0 | 0 | 1 | 1 | 1 |
Press any key to continue . . .
---------------------------------------------------------------------- */

"a" bit (7-segment display) input output 0 T 1 F 2 T 3 T 4 F 5 T 6 T 7 T 8 T 9 T 10 T 11 F 12 T 13 F 14 T 15 T

Explanation / Answer

#include <iostream>

#include <cctype>

#include <string>

using namespace std;

class BooleanFunc

{

private:

   int tableSize;

   bool *truthTable;

   bool evalReturnIfError;

   bool state;

public:

   static int MAX_TABLE_FOR_CLASS;

   static int DEFAULT_TABLE_SIZE;

   BooleanFunc (int tableSize = DEFAULT_TABLE_SIZE,

      bool evalReturnIfError = false);

   ~BooleanFunc();

   const BooleanFunc &operator= (const BooleanFunc &rhs);

   BooleanFunc (const BooleanFunc &otherBooleanFunc);

   bool setTruthTableUsingTrue( int inputsThatProduceTrue[], int arraySize );

   bool setTruthTableUsingFalse( int inputsThatProduceFalse[], int arraySize );

   bool eval(int input);

   bool getState();

private:

   void allocateCleanArray();

   void deallocateArray();

   static bool isTableSizeValid(int tableSize);

};

int BooleanFunc::MAX_TABLE_FOR_CLASS = 65536;

int BooleanFunc::DEFAULT_TABLE_SIZE = 16;

class MultiSegmentLogic

{

protected:

   int numSegs;

   BooleanFunc *segs;

public:

   MultiSegmentLogic (int numSegs = 0);

   ~MultiSegmentLogic();

   const MultiSegmentLogic & operator=(const MultiSegmentLogic &rhs);

   MultiSegmentLogic(const MultiSegmentLogic &otherMultiSegmentLogic);

   bool setNumSegs (int numSegs);

   bool setSegment (int segNum, BooleanFunc &funcForThisSeg);

   void eval (int input);

private:

   void allocateCleanArray();

   void deallocateArray();

};

class SevenSegmentLogic : public MultiSegmentLogic

{

public:

   static const int NUMBER_OF_SEGMENTS = 7;

   static const int NUMBER_OF_COLUMN =16;

   SevenSegmentLogic();

   bool getValOfSeg( int seg );

private:

   void loader();

};

class SevenSegmentImage

{

public:

   static const int MIN_HEIGHT = 5;

   static const int MIN_WIDTH = 3;

   static const int MAX_HEIGHT = 65;

   static const int MAX_WIDTH = 40;

   static const string DRAW_CHAR;

   static const string BLANK_CHAR;

private:

   bool **data;

   int topRow, midRow, bottomRow, leftCol, rightCol;

public:

   SevenSegmentImage( int width = MIN_WIDTH, int height = MIN_HEIGHT );

   ~SevenSegmentImage()

   {

      deallocateArray();

   }

   void clearImage();

   bool turnOnCellsForSegment( char segment );

   bool setSize( int width, int height );

   void display();

   // deep copy stuff

   SevenSegmentImage( const SevenSegmentImage &tdi );

   const SevenSegmentImage &operator=(const SevenSegmentImage &rhs);

private:

   bool validateSize( int width, int height );

   void allocateCleanArray();

   void deallocateArray();

   // helpers

   void drawHorizontal( int row );

   void drawVertical( int col, int startRow, int stopRow );

};

const string SevenSegmentImage::DRAW_CHAR = "*";

const string SevenSegmentImage::BLANK_CHAR = " ";

class SevenSegmentDisplay

{

private:

   SevenSegmentImage theImage;

   SevenSegmentLogic theDisplay;

public:

   SevenSegmentDisplay(

      int width = SevenSegmentImage::MIN_WIDTH,

      int height = SevenSegmentImage::MIN_HEIGHT

      );

   bool setSize( int width, int height );

void loadConsoleImage();

   void consoleDisplay();

   void eval( int input );

};

int main()

{

   //SevenSegmentImage Test

   SevenSegmentImage ssi;

   ssi.setSize( 7, 9 );

   ssi.turnOnCellsForSegment( 'a' );

   ssi.display();

   ssi.turnOnCellsForSegment( 'b' );

   ssi.display();

   ssi.turnOnCellsForSegment( 'c' );

   ssi.display();

   ssi.turnOnCellsForSegment( 'd' );

   ssi.display();

   ssi.clearImage();

   ssi.turnOnCellsForSegment( 'e' );

   ssi.display();

   ssi.turnOnCellsForSegment( 'f' );

   ssi.display();

   ssi.turnOnCellsForSegment( 'g' );

   ssi.display();

   ssi.clearImage();

   ssi.turnOnCellsForSegment( 'x' );

   ssi.display();

   ssi.turnOnCellsForSegment( '3' );

   ssi.display();

   //SevenSegmentDisplay Test

   SevenSegmentDisplay my7SegForCon( 15, 13 );

   my7SegForCon.setSize( 5, 5 );

   for ( int j = 0; j < 16; j++ )

   {

      my7SegForCon.eval( j );

      my7SegForCon.loadConsoleImage();

      my7SegForCon.consoleDisplay();

   }

   return 0;

}

// BooleanFunc method definitions

BooleanFunc::BooleanFunc (int tableSize, bool evalReturnIfError)

{

   truthTable = NULL;

   if (!isTableSizeValid(tableSize))

      tableSize = DEFAULT_TABLE_SIZE;

   else

      this->tableSize = tableSize;

   allocateCleanArray();

   state = evalReturnIfError;

   this->evalReturnIfError = evalReturnIfError;

}

BooleanFunc::~BooleanFunc()

{

   deallocateArray();

}

const BooleanFunc &BooleanFunc::operator=(const BooleanFunc &rhs)

{

   int index;

   if (this != &rhs)

   {

      deallocateArray();

      this->tableSize = rhs.tableSize;

      allocateCleanArray();

      for ( index = 0; index < tableSize; index++ )

         truthTable[index] = rhs.truthTable[index];

      this->evalReturnIfError = rhs.evalReturnIfError;

      this->state = rhs.state;

   }

   return *this;

}

BooleanFunc::BooleanFunc(const BooleanFunc &otherBooleanFunc)

{

   truthTable = NULL;

   *this = otherBooleanFunc;

}

bool BooleanFunc::setTruthTableUsingTrue

   (int inputsThatProduceTrue[], int arraySize)

{

   int index, inputValue;

   deallocateArray();

   allocateCleanArray();

   if (arraySize <= tableSize)

   {

      for (index = 0; index < arraySize; index++)

      {

         inputValue = inputsThatProduceTrue[index];

         if (inputValue >= 0 && inputValue < tableSize )

            truthTable[inputsThatProduceTrue[index]] = true;

      }

      return true;

   }

   else

      return false;

}

bool BooleanFunc::setTruthTableUsingFalse

   ( int inputsThatProduceFalse[], int arraySize )

{

   int index, k;

   deallocateArray();

   allocateCleanArray();

   if (arraySize > tableSize)

      return false;

   for (index = 0; index < tableSize; index++)

      truthTable[index] = true;

   for( k = 0; k < arraySize; k++)

   {

      if (inputsThatProduceFalse[k] >= 0 &&

         inputsThatProduceFalse[k] < tableSize)

         truthTable[inputsThatProduceFalse[k]] = false;

   }

   return true;

}

bool BooleanFunc::eval(int input)

{

   if ( input < 0 || input >= tableSize)

      state = evalReturnIfError;

   else

      state = truthTable[input];

   return state;

}

bool BooleanFunc::getState()

{

   return state;

}

void BooleanFunc::allocateCleanArray()

{

   int index;

   deallocateArray();

   truthTable = new bool [tableSize];

   for (index = 0; index < tableSize; index++)

      truthTable[index] = false;

}

void BooleanFunc::deallocateArray()

{

   if (truthTable == NULL)

      return;

   delete[] truthTable;

   truthTable = NULL;

}

bool BooleanFunc::isTableSizeValid(int tableSize)

{

   if (tableSize > 0 && tableSize <= MAX_TABLE_FOR_CLASS)

      return true;

   return false;

}

// MultiSegmentLogic method definitions

MultiSegmentLogic::MultiSegmentLogic (int numSegs)

{

   segs = NULL;

   if(!setNumSegs (numSegs))

      this->numSegs = 0;

   allocateCleanArray();

}

MultiSegmentLogic::~MultiSegmentLogic()

{

   deallocateArray();

}

const MultiSegmentLogic & MultiSegmentLogic::operator=

   (const MultiSegmentLogic &rhs)

{

   int index;

   if (this != &rhs)

   {

      deallocateArray();

      this->numSegs = rhs.numSegs;

      allocateCleanArray();

      for (index = 0; index < numSegs; index++)

         segs[index] = rhs.segs[index];

   }

   return *this;

}

MultiSegmentLogic::MultiSegmentLogic

   (const MultiSegmentLogic &otherMultiSegmentLogic)

{

   segs = NULL;

   *this = otherMultiSegmentLogic;

}

bool MultiSegmentLogic::setNumSegs (int numSegs)

{

   if (numSegs >=0 )

   {

      this -> numSegs = numSegs;

      if (segs != NULL)

         allocateCleanArray();

      return true;

   }

   return false;

}

bool MultiSegmentLogic::setSegment (int segNum, BooleanFunc &funcForThisSeg)

{

   if (segNum < 0 || segNum >= numSegs)

      return false;

   segs[segNum] = funcForThisSeg;

   return true;

}

void MultiSegmentLogic::eval (int input)

{

   int indexSeg;

   for (indexSeg = 0; indexSeg < numSegs; indexSeg++)

      segs[indexSeg].eval(input);

}

void MultiSegmentLogic::allocateCleanArray()

{

   deallocateArray();

   segs = new BooleanFunc [numSegs];

}

void MultiSegmentLogic::deallocateArray()

{

   if (segs == NULL)

      return;

   delete[] segs;

   segs = NULL;

}

// SeevenSegmentLogic method definitions

SevenSegmentLogic::SevenSegmentLogic() : MultiSegmentLogic (NUMBER_OF_SEGMENTS)

{

   loader();

}

bool SevenSegmentLogic::getValOfSeg (int seg)

{

   bool state;

   if (seg >= 0 && seg < numSegs)

   {

      state = segs[seg].getState();

   }

   else

   {

    return false;

   }

   return state;

}

void SevenSegmentLogic::loader()

{

   int indexTrue [NUMBER_OF_SEGMENTS][NUMBER_OF_COLUMN] = {

      {0,2,3,5,6,7,8,9,10,12,14,15,16,16,16,16},

      {0,1,2,3,4,7,8,9,10,13,16,16,16,16,16,16},

      {0,1,3,4,5,6,7,8,9,10,11,13,16,16,16,16},

      {0,2,3,5,6,8,9,11,12,13,14,16,16,16,16,16},

      {0,2,6,8,10,11,12,13,14,15,16,16,16,16,16,16},

      {0,4,5,6,8,9,10,11,12,14,15,16,16,16,16,16},

      {2,3,4,5,6,8,9,10,11,13,14,15,16,16,16,16}};

   BooleanFunc loader[NUMBER_OF_SEGMENTS];

   for (int k = 0; k < NUMBER_OF_SEGMENTS; k++)

   {

      loader[k].setTruthTableUsingTrue (indexTrue[k], NUMBER_OF_COLUMN);

      setSegment(k,loader[k]);

   }

}

// SevenSegmentImage method definitions

SevenSegmentImage::SevenSegmentImage (int width, int height)

{

   data = NULL;

   leftCol = 0;

   topRow = 0;

   if (!validateSize (width, height))

      setSize (MIN_WIDTH, MIN_HEIGHT);

}

void SevenSegmentImage::clearImage()

{

   int row, col;

   for ( row = 0; row <= bottomRow; row++ )

      for ( col = 0; col <= rightCol; col++ )

         data[row][col] = false;

}

bool SevenSegmentImage::turnOnCellsForSegment( char segment )

{

   char upperCharSegment;

   if (isalpha(segment))

   {

      upperCharSegment = toupper((int)segment);

      if (upperCharSegment >= 'A' && upperCharSegment <= 'G')

      {

         switch (upperCharSegment)

         {

         case 'A':

            drawHorizontal(topRow);

            break;

         case 'B':

            drawVertical(rightCol, topRow, midRow);

            break;

         case 'C':

            drawVertical(rightCol, midRow, bottomRow);

            break;

         case 'D':

            drawHorizontal(bottomRow);

            break;

         case 'E':

            drawVertical(leftCol, midRow, bottomRow);

            break;

         case 'F':

            drawVertical(leftCol, topRow, midRow);

            break;

         case 'G':

            drawHorizontal(midRow);

            break;

         }

         return true;

      }

   }

   return false;

}

bool SevenSegmentImage::setSize( int width, int height )

{

   deallocateArray();

   if (validateSize(width, height))

   {

      rightCol = width - 1;

      bottomRow = height - 1;

      midRow = bottomRow / 2;

   }

   else

      return false;

   allocateCleanArray();

   return true;

}

void SevenSegmentImage::display()

{

   int row, col;

   for ( row = topRow; row <= bottomRow; row++ )

   {

      for ( col = leftCol; col <= rightCol; col++ )

      {

         if (data[row][col] == true)

            cout << DRAW_CHAR;

         else

            cout << BLANK_CHAR;

      }

      cout << endl;

   }

   cout << endl << endl;

}

SevenSegmentImage::SevenSegmentImage (const SevenSegmentImage &tdi )

{

   data = NULL;

   *this = tdi;

}

const SevenSegmentImage &SevenSegmentImage::operator=

   (const SevenSegmentImage &rhs)

{

   int row, col;

   if (this != &rhs)

   {

      deallocateArray();

      this->midRow = rhs.midRow;

      this->bottomRow = rhs.bottomRow;

      this->rightCol = rhs.rightCol;

      allocateCleanArray();

      for ( row = topRow; row <= bottomRow; row++ )

         for ( col = leftCol; col <= rightCol; col++ )

            data[row][col] = rhs.data[row][col];

   }

   return *this;

}

bool SevenSegmentImage::validateSize( int width, int height )

{

   if (width >= MIN_WIDTH && width <= MAX_WIDTH &&

      height >= MIN_HEIGHT && height <= MAX_HEIGHT && height % 2 == 1)

      return true;

   return false;

}

void SevenSegmentImage::allocateCleanArray()

{

   int row;

   deallocateArray();

   data = new bool*[bottomRow+1];

   for ( row = 0; row <= bottomRow; row++ )

      data[row] = new bool[rightCol+1];

   clearImage();

}

void SevenSegmentImage::deallocateArray()

{

   int row;

   if (data == NULL)

      return;

   for ( row = topRow; row <= bottomRow; row++ )

      delete[] data[row];

   delete[] data;

   data = NULL;

}

void SevenSegmentImage::drawHorizontal( int row )

{

   int col;

   for ( col = leftCol; col <= rightCol; col++ )

      data[row][col] = true;

}

void SevenSegmentImage::drawVertical( int col, int startRow, int stopRow )

{

   int row;

   for ( row =startRow; row <= stopRow; row++ )

      data[row][col] = true;

}

// SevenSegmentDisplay method definitions

SevenSegmentDisplay::SevenSegmentDisplay(int width, int height)

{

   if(!setSize (width, height))

      (setSize (SevenSegmentImage::MIN_WIDTH, SevenSegmentImage::MIN_HEIGHT));

}

bool SevenSegmentDisplay::setSize( int width, int height )

{

   bool testSize;

   testSize = theImage.setSize (width, height);

   return testSize;

}

void SevenSegmentDisplay::loadConsoleImage()

{

   int x;

   char y;

   theImage.clearImage();

   for (x = 0, y = 'a'; x <= 6, y <= 'g'; x++, y++)

      if(theDisplay.getValOfSeg(x) == true)

         theImage.turnOnCellsForSegment(y);

}

void SevenSegmentDisplay::consoleDisplay()

{

   theImage.display();

}

void SevenSegmentDisplay::eval( int input )

{

   theDisplay.eval (input);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote