我无法在我的程序中正确显示“第二天”。赋值状态为“。”提示用户输入当前处理时间的小时,分钟,秒,即currTime。您的程序将计算下一个处理时间,即当前处理时间后30分钟。您的程序将显示当前处理时间。处理时间currTime和下一个处理时间1 nextTime1处理时间2 nextTime2。如果下一个处理时间到达第二天那么 在下一个处理时间旁边显示“下一天”(参见样本输出)。
示例输出显示:
当前Proc Time = 23:50:10 |下一步时间= 0:20:10(下一天)| 下一个Proc Time 2 = 0:50:10
我的问题出现在粗线“Next Proc Time 2 = 0:50:10”中,在我的代码中显示(下一天)它不应该,只有前一行,“Next Proc Time(Next日“应该显示。所以我的问题是我应该怎么做才能在Void TimeType :: Display()函数下更改我的代码,让它在正确等于一天时显示”Next Day“。此外,我道歉如果我的问题不是太具体,我只是不知所措,不知道如何解决这个问题。
#ifndef TIME_H
#define TIME_H
class TimeType { //class definition
private:
int sec;
int min;
int hr;
int day; // variable stores the information about the day, you need to track the transition to the next day
public:
TimeType();
void SetTime(int s, int m, int h, int d);
TimeType NextProcTime(void);
void Display();
};
#endif
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include "timetype.h"
using namespace std;
TimeType::TimeType()
{
sec = 0;
min = 0;
hr = 0;
}
void TimeType::SetTime(int s, int m, int h, int d)
{
sec = s;
min = m;
hr = h;
day = d;
}
TimeType TimeType::NextProcTime(void)
{
long buf = 0;
int h, m, s, d;
buf = (day * 86400 + hr * 3600 + min * 60 + sec) + (30 * 60); //calculation time in seconds needed for the allocation of time to reflect additional minutes
d = buf / 86400; // recalculation time for days hours minutes seconds
h = (buf - 86400 * d) / 3600;
m = (buf - 86400 * d - 3600 * h) / 60;
s = (buf - 86400 * d - 3600 * h - 60 * m);
TimeType T; //creating a buffer TimeType object
T.SetTime(s, m, h, d); //full a buffer TimeType object
return T; //return buffer TimeType object
}
void TimeType::Display()
{
if (day == 1)
{
printf(" %02i:%02i:%02i (next day)\t", hr, min, sec);
}
else {
printf(" %02i:%02i:%02i \t", hr, min, sec);
}
};
int main(int argc, char *argv[])
{
int hr = 0, min = 0, sec = 0;
TimeType currTime, nextTime1, nextTime2;
char t;
do
{
system("cls");
while (1) {
cout << "Please enter the current processing hour." << endl;
cin >> hr;
if (hr >= 0 && hr < 24)
break;
cout << "Invalid Input, try again." << endl << endl;
}
cout << endl;
while (1)
{
cout << "Please enter the current processing minute." << endl;
cin >> min;
if (min >= 0 && min < 60)
break;
cout << "Invalid Input, try again." << endl << endl;
}
cout << endl;
while (1)
{
cout << "Please enter the current processing second." << endl;
cin >> sec;
if (sec >= 0 && sec < 60)
break;
cout << "Invalid Input, try again." << endl << endl;
}
cout << endl;
currTime.SetTime(sec, min, hr, 0);
nextTime1 = currTime.NextProcTime();
nextTime2 = nextTime1.NextProcTime();
cout << "Current Proc Time = ";
currTime.Display();
cout << endl;
cout << "Next Proc Time 1 = ";
nextTime1.Display();
cout << endl;
cout << "Next Proc Time 2 = ";
nextTime2.Display();
cout << endl;
cout << endl << "Do you have more data to enter? (y/n)" << endl;
cin >> t;
cout << endl;
} while (t == 'y'); // cycle for program multiple using
return 0;
}