2D阵列七段数字时钟实现

时间:2017-05-01 04:38:48

标签: c++

嘿所有我是编程和这个网站的新手...也许我已经咬了不止这个...但是我想要了解课程所以我发现了一个关于a的UML图表带七段显示的数字时钟。我能够辨别出UML图对于私有函数和public的想法,并且能够获得构造的单独的类文件,现在将类构造为骨架,但是如何继续这样做却不知所措。这是我到目前为止的文件: 基类

#include <iostream>
#include <string>
using namespace std;

//Declare and initialize a speed increase, or decrease
const int ROWS = 10;  // move this to base class


class ClockCharacter
{
private:
   //Field declarations

public:
   virtual string getRow(int aRow) = 0; // pure virtual function == abstract class

}; //end class

以及帮助拼凑时钟的其他课程:

#include <iostream>
#include <string>
using namespace std;

class DigitalClock
{
    private:

        DigitalClockDisplay aDigitalClockDisplay;

    public:
        /**
        * Constructor. Empty.
        */
        DigitalClock()
        {

        }

        /**
        * Set the hours, minutes and seconds of the DigitalClockDisplay.
        */
        void setTime(int theHours, int theMinutes, int theSeconds)
        {

        }

        /**
        * Based on a 12 hour clock, get the current hour and increment it.
        * If the result exceeds 12 hours wrap back to the 1st hour.
        */
        void incrementHours()
        {

        }

        /**
        * Based on a 60 minute hour, get the current minute and increment it.
        * If the result exceeds 60 minutes wrap back to the 1st minute and increment the hour.
        */
        void incrementMinutes()
        {

        }

        /**
        * Based on a 60 second minute, get the current second and increment it.
        * If the result exceeds 60 seconds wrap back to the 1st second and incremnt the minute.
        */
        void incrementSeconds()
        {

        }

        /**
        * Based on a 12 hour clock, get the current hour and decremnt it.
        * If the result is less than the 1st hour, wrap back to the 12th hour.
        */
        void decrementHours()
        {

        }

        /**
        * Based on a 60 minute hour, get the current minute and decrement it.
        * If the result is less than 1 minutes, wrap back to the 59th minute and decrement the hour.
        */
        void decrementMinutes()
        {

        }

        /**
        * Based on a 60 second minute, get the current second and decrement it.
        * If the result is less than 1 second wrap back to the 59th second and decremnt the minute.
        */
        void decrementSeconds()
        {

        }

        /**
        * Request that the DigitalClockDisplay display its time.
        */
        void displayTime()
        {

        }

        /**
        * Increment the seconds after a one second delay.
        */
        void run()
        {

        }

}; // End class

#include <iostream>
#include <string>
using namespace std;

class DigitalClockDisplay : public DigitalClock
{
    private:
        SevenSegment hTensDigit;
        SevenSegment hOnesDigit;
        SevenSegment mTensDigit;
        SevenSegment mOnesDigit;
        SevenSegment sTensDigit;
        SevenSegment sOnesDigit;
        Colon aColon;
        DigitalClock aDigitalClockDisplay;

    public:
        /**
        * Constructor to initialize the instance.
        */
        DigitalClockDisplay()
        {

        }

        /**
        * The specified value is separated into its two digit components.
        * The tens position is sent to the SevenSegment representing the tens position
        *   and likewise for the ones position.
        */
        void setHours(int theTime)
        {

        }

        /**
        * The tens and ones digits are collected from the represective SevenSegments, combined and returned to caller.
        */
        int getHours()
        {
            return Hours;
        }

        /**
        * The specified value is separated into its two digit components.
        * The tens position is sent to the SevenSegment representing the tens position
        *   and likewise for the ones position.
        */
        void setMinutes(int theTime)
        {

        }

        /**
        * The tens and ones digits are collected from the represective SevenSegments, combined and returned to caller.
        */
        int getMinutes()
        {
            return Minutes;
        }

        /**
        * The specified value is separated into its two digit components.
        * The tens position is sent to the SevenSegment representing the tens position
        *   and likewise for the ones position.
        */
        void setSeconds(int theTime)
        {

        }

        /**
        * The tens and ones digits are collected from the represective SevenSegments, combined and returned to caller.
        */
        int getSeconds()
        {
            return Seconds;
        }

        /**
        * Output is generated one line at a time by calling getRow() for each of the display components.
        */
        void DisplayTime()
        {
            getRow()
        }

        /**
        * Each of the SevenSegment components is initialized to zero (0).
        */
        void initialize()
        {
            hTensDigit = 0;
            hOnesDigit = 0;
            mTensDigit = 0;
            mOnesDigit = 0;
            sTensDigit = 0;
            sOnesDigit = 0;
        }
}; // End Class

#include <iostream>
#include <string>
using namespace std;

class Colon : public ClockCharacter
{
    private:
        int static const COLUMNS = 7;
        string digitArray[ROWS + 1][COLUMNS + 1];

        DigitalClockDisplay aColon;

    public:
        /**
        * Constructor to initialize the instance.
        */
        Colon()
        {

        }

        /**
        * Set the appropriate segments in the digitArray[][].
        */
        void setColon()
        {

        }

        /**
        * Remove values that were set in setColon();
        */
        void clearColon()
        {

        }

        /**
        * Returns a string of all the cells values for the specified row in digitArray[][].
        */
        string getRow(int aRow)
        {

        }

        /**
        * Clear the array representation by setting all cells to a space (" ").
        */
        void initialize()
        {
            string digitArray[ROWS + 1][COLUMNS + 1] = {{" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                        {" ", " ", " ", " ", " ", " ", " ", " "}};
        }
}; // End class

#include <iostream>
#include <string>
using namespace std;

class SevenSegment : public ClockCharacter
{
    private:
        int static const COLUMNS = 7; // Defines the number of columns for the SevenSegment array representation.

        /**
        * This is the array representation of the SevenSegment display. 
        * It is declared with one more row and column to account for the 0 element.
        */
        string digitArray[ROWS + 1][COLUMNS + 1]; 

        int digitValue; // this variable stores the value that the SevenSegment represents. It can be used for calculations.

        DigitalClockDisplay hTensDigit;
        DigitalClockDisplay hOnesDigit;
        DigitalClockDisplay mTensDigit;
        DigitalClockDisplay mOnesDigit;
        DigitalClockDisplay sTensDigit;
        DigitalClockDisplay sOnesDigit;

    public:
        /**
        * Constructor to initialize the instance.
        */
        SevenSegment()
        {

        }

        /**
        * Set the digitValue and set the appropriate segments in the digitArray[][]. 
        * Each of the seven segments will be either set or cleared depending on the specified digit.
        */
        void setDigit(int aValue)
        {

        }

        /**
        * Return the digitValue.
        */
        int getDigitValue()
        {
            return digitValue;
        }

        /**
        * Sets the specified segment.
        */
        void setSegment(int aSegment)
        {
            Segment = aSegment;
        }

        /**
        * Clears the specified segment.
        */
        void clearSegment(int aSegment)
        {

        }

        /**
        * Returns a string of all the cells values for the specified row in digitArray[][].
        */
        string getRow(int aRow)
        {
            return Row;
        }

        /**
        * Clear the array representation by setting all cells to a space (" ").
        */
        void initialize()
        {
             string digitArray[ROWS + 1][COLUMNS + 1] = {{" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}, 
                                                         {" ", " ", " ", " ", " ", " ", " ", " "}};
        }
}; // End class

我正在分离UML图留下的评论,我想我有几个正确的...但我仍在努力与其他人。我只有其他程序员朋友推荐的书籍,因为我是新的,有些材料有点超出我的范围。任何和所有的帮助将不胜感激。我正在查看七段显示器,并且认为我可以设计数字类似于我如何设置void initialize()功能但是我可以使用*符号而不是空格?再一次,欢迎任何帮助,欢迎回来。

0 个答案:

没有答案