labs-edaf30/lab4/date_test.cc

41 lines
1,019 B
C++
Raw Normal View History

2021-10-27 15:15:47 +02:00
#include <iostream>
#include "date.h"
2024-12-11 15:54:56 +01:00
int main() {
// Test input och output
bool cont = true;
while (cont) {
std::cout << "Type a date: ";
Date aDate;
std::cin >> aDate;
2021-10-27 15:15:47 +02:00
2024-12-11 15:54:56 +01:00
if (std::cin.eof()) {
cont = false;
} else if (!std::cin.good()) {
std::cout << "Wrong input format" << std::endl;
std::cin.clear();
std::cin.ignore(10000, '\n');
} else {
std::cout << "Output: " << aDate << std::endl;
}
}
2021-10-27 15:15:47 +02:00
2024-12-11 15:54:56 +01:00
// Testa 'next' med dagens datum
std::cout << "--- Today and more than a month ahead:" << std::endl;
Date d1;
std::cout << d1 << std::endl;
for (int i = 1; i <= 35; ++i) {
d1.next();
std::cout << d1 << std::endl;
}
// Testa 'next' från nyårsafton
std::cout << "--- New Year's Eve and the next day:" << std::endl;
Date d2(2013, 12, 31);
std::cout << d2 << std::endl;
d2.next();
std::cout << d2 << std::endl;
return 0;
2021-10-27 15:15:47 +02:00
}