C++ 二维阵列七段数字时钟的实现
嘿,我对编程和这个网站都是新手。也许我已经吃了太多了…但是我想学习类,所以我找到了一个UML图,它是关于一个带有七段显示的数字时钟。就私有函数和公共函数而言,我能够辨别UML图想要的是什么,并且能够构建单独的类文件,现在将类构造为一个框架,但是对于如何继续,我一直处于困惑之中。以下是我目前拥有的文件: 基层C++ 二维阵列七段数字时钟的实现,c++,C++,嘿,我对编程和这个网站都是新手。也许我已经吃了太多了…但是我想学习类,所以我找到了一个UML图,它是关于一个带有七段显示的数字时钟。就私有函数和公共函数而言,我能够辨别UML图想要的是什么,并且能够构建单独的类文件,现在将类构造为一个框架,但是对于如何继续,我一直处于困惑之中。以下是我目前拥有的文件: 基层 #include <iostream> #include <string> using namespace std; //Declare and initializ
#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
#包括
#包括
使用名称空间std;
//声明并初始化速度增加或降低
常量int行=10;//将其移动到基类
类时钟字符
{
私人:
//字段声明
公众:
虚拟字符串getRow(int aRow)=0;//纯虚拟函数==抽象类
}; //末级
以及其他帮助拼凑时钟的课程:
#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
#包括
#包括
使用名称空间std;
类数字钟
{
私人:
数字时钟显示器;
公众:
/**
*构造函数。空。
*/
数字时钟
{
}
/**
*设置DigitalClockDisplay的小时、分钟和秒。
*/
无效设置时间(整数小时、整数分钟、整数秒)
{
}
/**
*基于12小时时钟,获取当前小时并递增。
*如果结果超过12小时,则返回到第一个小时。
*/
无效增量小时数()
{
}
/**
*以60分钟小时为基础,获取当前分钟并将其递增。
*如果结果超过60分钟,则返回到第1分钟并增加小时。
*/
void incrementMinutes()
{
}
/**
*基于60秒分钟,获取当前秒数并将其递增。
*如果结果超过60秒,则返回到第1秒并增加分钟。
*/
void incrementSeconds()
{
}
/**
*基于12小时时钟,获取当前小时并递减。
*如果结果小于第一个小时,则返回到第12个小时。
*/
无效递减率()
{
}
/**
*以60分钟小时为基础,获取当前分钟并将其递减。
*如果结果小于1分钟,则返回到第59分钟并减少小时数。
*/
无效递减分钟()
{
}
/**
*基于60秒分钟,获取当前秒数并将其递减。
*如果结果小于1秒,则返回到第59秒并减少分钟数。
*/
无效递减秒()
{
}
/**
*请求DigitalClockDisplay显示其时间。
*/
void displayTime()
{
}
/**
*延迟1秒后增加秒数。
*/
无效运行()
{
}
}; // 末级
#包括
#包括
使用名称空间std;
类别DigitalClockDisplay:公共数字时钟
{
私人:
七段数字;
七段荣誉数字;
七段数字;
七、货币数字;
七段速记数字;
七段数字;
结肠石菖蒲;
数字时钟;数字锁相显示;
公众:
/**
*构造函数初始化实例。
*/
数字时钟显示器()
{
}
/**
*指定的值被分成两位数的分量。
*tens位置被发送到代表tens位置的SevenSegment
*同样地,一的位置也是如此。
*/
无效设置小时数(整时间)
{
}
/**
*十位数和一位数是从代表性的七位数中收集出来的,合并后返回给调用者。
*/
int getHours()
{
返程时间;
}
/**
*指定的值被分成两位数的分量。
*tens位置被发送到代表tens位置的SevenSegment
*同样地,一的位置也是如此。
*/
无效设置分钟数(整数时间)
{
}
/**
*十位数和一位数是从代表性的七位数中收集出来的,合并后返回给调用者。
*/
int getMinutes()
{
返回分钟数;
}
/**
*指定的值被分成两位数的分量。
*tens位置被发送到代表tens位置的SevenSegment
*同样地,一的位置也是如此。
*/
无效设置秒(整数时间)
{
}
/**
*十位数和一位数是从代表性的七位数中收集出来的,合并后返回给调用者。
*/
int getSeconds()
{
返回秒数;
}
/**
*通过为每个显示组件调用getRow()一次生成一行输出。
*/
void DisplayTime()
{
getRow()
}
/**
*每个SevenSegment组件都初始化为零(0)。
*/
void initialize()
{
shensdigit=0;
hOnesDigit=0;
mTensDigit=0;
货币数字=0;
sTensDigit=0;
sOnesDigit=0;
}
}; // 末级
#包括
#包括
使用名称空间std;
类冒号:公共字符
{
私人:
int static const COLUMNS=7;
字符串数字数组[行+1][列+1];
数字钟控显示器;
公众:
/**
*构造函数初始化实例。
*/
冒号()
{
}
/**