imported lab skeletons
This commit is contained in:
parent
4fc8b6c771
commit
e4df45f4a9
47 changed files with 15122 additions and 87 deletions
30
lab4/date.cc
Normal file
30
lab4/date.cc
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#include <ctime> // time and localtime
|
||||
#include "date.h"
|
||||
|
||||
int Date::daysPerMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
|
||||
Date::Date() {
|
||||
time_t timer = time(0); // time in seconds since 1970-01-01
|
||||
tm* locTime = localtime(&timer); // broken-down time
|
||||
year = 1900 + locTime->tm_year;
|
||||
month = 1 + locTime->tm_mon;
|
||||
day = locTime->tm_mday;
|
||||
}
|
||||
|
||||
Date::Date(int y, int m, int d) {}
|
||||
|
||||
int Date::getYear() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Date::getMonth() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Date::getDay() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Date::next() {
|
||||
}
|
||||
|
||||
19
lab4/date.h
Normal file
19
lab4/date.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef DATE_H
|
||||
#define DATE_H
|
||||
|
||||
class Date {
|
||||
public:
|
||||
Date(); // today's date
|
||||
Date(int y, int m, int d); // yyyy-mm-dd
|
||||
int getYear() const; // get the year
|
||||
int getMonth() const; // get the month
|
||||
int getDay() const; // get the day
|
||||
void next(); // advance to next day
|
||||
private:
|
||||
int year; // the year (four digits)
|
||||
int month; // the month (1-12)
|
||||
int day; // the day (1-..)
|
||||
static int daysPerMonth[12]; // number of days in each month
|
||||
};
|
||||
|
||||
#endif
|
||||
64
lab4/date_test.cc
Normal file
64
lab4/date_test.cc
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include <iostream>
|
||||
#include <iomanip> // for setw and setfill
|
||||
#include "date.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::setw;
|
||||
using std::setfill;
|
||||
|
||||
/*
|
||||
* Prints the date d in the format yyyy-mm-dd. You shall replace this
|
||||
* function with an overloaded operator<<, and add an overloaded operator>>.
|
||||
*
|
||||
*/
|
||||
void print(const Date& d) {
|
||||
cout << setw(4) << setfill('0') << d.getYear() << '-';
|
||||
cout << setw(2) << setfill('0') << d.getMonth() << '-';
|
||||
cout << setw(2) << setfill('0') << d.getDay();
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Check input and output of dates. Uncomment the following when you
|
||||
// have added operator>> and operator<<.
|
||||
/*
|
||||
bool cont = true;
|
||||
while (cont) {
|
||||
cout << "Type a date: ";
|
||||
Date aDate;
|
||||
cin >> aDate;
|
||||
if (cin.eof()) {
|
||||
cont = false;
|
||||
} else if (!cin.good()) {
|
||||
cout << "Wrong input format" << endl;
|
||||
// restore stream state and ignore the rest of the line
|
||||
cin.clear();
|
||||
cin.ignore(10000, '\n');
|
||||
}
|
||||
else {
|
||||
cout << "Output: " << aDate << endl;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Check 'next' by creating an object describing today's date, then
|
||||
// printing dates more than a month ahead
|
||||
cout << "--- Today and more than a month ahead:" << endl;
|
||||
Date d1;
|
||||
print(d1);
|
||||
cout << endl;
|
||||
for (int i = 1; i <= 35 ; ++i) {
|
||||
d1.next();
|
||||
print(d1);
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
// Check so 'next' functions correctly from one year to the next
|
||||
cout << "--- New Year's Eve and the next day:" << endl;
|
||||
Date d2(2013, 12, 31);
|
||||
print(d2);
|
||||
cout << endl;
|
||||
d2.next();
|
||||
print(d2);
|
||||
cout << endl;
|
||||
}
|
||||
7
lab4/test.html
Normal file
7
lab4/test.html
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
This is a line without a tag
|
||||
This is <tag tag> a line with one tag
|
||||
And this <tag> line has two tags <...>
|
||||
A line with a starting tag < ..... continues
|
||||
... we're still in a tag ...
|
||||
... finishes> which finished on this line <last tag>
|
||||
Special chars: <> &
|
||||
Loading…
Add table
Add a link
Reference in a new issue