labs-edaf30/lab4/date_test.cc
2024-12-11 15:54:56 +01:00

40 lines
1,019 B
C++

#include <iostream>
#include "date.h"
int main() {
// Test input och output
bool cont = true;
while (cont) {
std::cout << "Type a date: ";
Date aDate;
std::cin >> aDate;
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;
}
}
// 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;
}