日期函数定义的伪代码
Pseudocode for date function definition
我收到的伪代码:
Date& operator++(){
//add 1 to d //tomorrow, unless we were at the end of the month
//if is_date is false
// //need to change to first of next month
// set d to 1
// if m is December
// //need to change to next year too
// set m to January
// increment y
// else
// increment m
return *this;
}
我的解释:
Date& Date::operator++(){
if (is_date==false){
m=m+1;
d=1;
}
if (m==dec && d==29){
m=jan;
y=y+1;
}
else{
m=m+1;
}
d=d+1;
}
这看起来还行吗?我正在做一个基于Stroustrups书的硬件作业。只需要一些验证
让我们递增2010-03-10
:
if (is_date==false){
m=m+1;
d=1;
}
我们假设is_date
为真,因此不会发生任何操作。
if (m==dec && d==29){
m=jan;
y=y+1;
}
m
不是 dec,d
不是 29,因此不会发生任何操作。
else{
m=m+1;
}
等! m
递增。
d=d+1;
d
也是如此.
我们现在有2010-04-11
——不是我们想要的。
再看看伪代码 - 发生的第一件事就是添加一天。其他一切都只有在is_date是假的情况下才会发生。但是is_date不应该被解释为一些静态值,而应该被实现为检查日期是否有效(例如,我们有增量后的32天)。仅当新日期无效时,月份和/或年份才会递增。
相关文章:
- 如何实现此伪代码?
- 有人可以为此提供伪代码吗?
- 如何计算以下伪代码的封闭形式
- 为赋值编写伪代码,并希望仔细检查它是否有意义
- 将伪代码转换为C++
- 我误解了这个伪代码了吗
- 无法使用类属性代码定义编译 c++
- 在C 中编写一个简单的排序算法以及伪代码版本
- 用于删除链接列表的节点的伪代码
- 在cpp中创建嵌套对象.下面的伪代码中的函数调用序列是什么
- 我试图通过 c++ 中的相关实验室作业理解的类中给出的伪代码
- 将伪代码转换为C++
- 使合并排序几乎与家庭作业的伪代码相同
- 尝试将伪代码转换为合并排序的实际代码
- 日期函数定义的伪代码
- CPP项目的伪代码
- BFS的伪代码(来自算法设计,第二版)混淆
- 接收访问无线介质到有限状态机的伪代码
- 寻找8x8(或nxn)离散余弦变换(DCT)/IDCT伪代码
- 伪代码有助于编程工作