3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
LocalDate/LocalDate.cpp@83:0d3572a8a851, 2017-05-11 (annotated)
- Committer:
- aburch1
- Date:
- Thu May 11 19:23:55 2017 +0000
- Revision:
- 83:0d3572a8a851
- Parent:
- 82:668b51a39148
- Child:
- 85:422d0a1b95cf
Comments cleaned and improved throughout classes. Main header class comment complete, other class comments still need to be written.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
FairyMental | 46:0de1f3c7d118 | 1 | #include "LocalDate.h" |
FairyMental | 46:0de1f3c7d118 | 2 | #include <stdio.h> |
FairyMental | 68:d3765f93c16a | 3 | |
aburch1 | 83:0d3572a8a851 | 4 | LocalDate::LocalDate(int d, int m, int y,int h,int mm,int s) |
aburch1 | 83:0d3572a8a851 | 5 | { |
aburch1 | 83:0d3572a8a851 | 6 | day = d; |
aburch1 | 83:0d3572a8a851 | 7 | month = m; |
aburch1 | 83:0d3572a8a851 | 8 | year = y; |
aburch1 | 83:0d3572a8a851 | 9 | hour = h; |
aburch1 | 83:0d3572a8a851 | 10 | min = mm; |
aburch1 | 83:0d3572a8a851 | 11 | sec = s; |
aburch1 | 83:0d3572a8a851 | 12 | } |
aburch1 | 83:0d3572a8a851 | 13 | |
aburch1 | 83:0d3572a8a851 | 14 | LocalDate::LocalDate() |
aburch1 | 83:0d3572a8a851 | 15 | { |
aburch1 | 83:0d3572a8a851 | 16 | day = 12; |
aburch1 | 83:0d3572a8a851 | 17 | month = 12; |
aburch1 | 83:0d3572a8a851 | 18 | year = 2012; |
aburch1 | 83:0d3572a8a851 | 19 | hour = 12; |
aburch1 | 83:0d3572a8a851 | 20 | min = 12; |
aburch1 | 83:0d3572a8a851 | 21 | sec = 12; |
aburch1 | 83:0d3572a8a851 | 22 | } |
aburch1 | 83:0d3572a8a851 | 23 | |
aburch1 | 83:0d3572a8a851 | 24 | LocalDate::LocalDate(LocalDate *localDate) |
aburch1 | 83:0d3572a8a851 | 25 | { |
aburch1 | 83:0d3572a8a851 | 26 | day = localDate->day; |
aburch1 | 83:0d3572a8a851 | 27 | month = localDate->month; |
aburch1 | 83:0d3572a8a851 | 28 | year = localDate->year; |
aburch1 | 83:0d3572a8a851 | 29 | hour = localDate->hour; |
aburch1 | 83:0d3572a8a851 | 30 | min = localDate->min; |
aburch1 | 83:0d3572a8a851 | 31 | sec = localDate->sec; |
aburch1 | 83:0d3572a8a851 | 32 | } |
aburch1 | 83:0d3572a8a851 | 33 | |
aburch1 | 83:0d3572a8a851 | 34 | /** |
aburch1 | 83:0d3572a8a851 | 35 | Sets values to passed in localDate object. |
aburch1 | 83:0d3572a8a851 | 36 | |
aburch1 | 83:0d3572a8a851 | 37 | @param localDate : LocalDate object storing data. |
aburch1 | 83:0d3572a8a851 | 38 | */ |
aburch1 | 83:0d3572a8a851 | 39 | void LocalDate::setValues(LocalDate *localDate) |
aburch1 | 83:0d3572a8a851 | 40 | { |
aburch1 | 83:0d3572a8a851 | 41 | day = localDate->day; |
aburch1 | 83:0d3572a8a851 | 42 | month = localDate->month; |
aburch1 | 83:0d3572a8a851 | 43 | year = localDate->year; |
aburch1 | 83:0d3572a8a851 | 44 | hour = localDate->hour; |
aburch1 | 83:0d3572a8a851 | 45 | min = localDate->min; |
aburch1 | 83:0d3572a8a851 | 46 | sec = localDate->sec; |
aburch1 | 83:0d3572a8a851 | 47 | } |
aburch1 | 83:0d3572a8a851 | 48 | |
aburch1 | 83:0d3572a8a851 | 49 | /** |
aburch1 | 83:0d3572a8a851 | 50 | Takes data stored in LocalDate objects and formats it. |
aburch1 | 83:0d3572a8a851 | 51 | |
aburch1 | 83:0d3572a8a851 | 52 | @return charArray : Char array containing formatted data to be printed. |
aburch1 | 83:0d3572a8a851 | 53 | */ |
aburch1 | 83:0d3572a8a851 | 54 | char* LocalDate::ToString() |
aburch1 | 83:0d3572a8a851 | 55 | { |
aburch1 | 83:0d3572a8a851 | 56 | char *charArray = new char[40]; |
aburch1 | 83:0d3572a8a851 | 57 | snprintf(charArray, 256, "%i/%i/%i, %i:%i:%i",day,month,year,hour,min,sec); |
aburch1 | 83:0d3572a8a851 | 58 | return charArray; |
aburch1 | 83:0d3572a8a851 | 59 | } |
aburch1 | 83:0d3572a8a851 | 60 | |
aburch1 | 83:0d3572a8a851 | 61 | /** |
aburch1 | 83:0d3572a8a851 | 62 | Increases time stored in object by one second, calculating the new time. |
aburch1 | 83:0d3572a8a851 | 63 | */ |
aburch1 | 83:0d3572a8a851 | 64 | void LocalDate::TickSecond() |
aburch1 | 83:0d3572a8a851 | 65 | { |
aburch1 | 83:0d3572a8a851 | 66 | sec++; |
aburch1 | 83:0d3572a8a851 | 67 | if(sec == 60) |
FairyMental | 47:468a89d62c23 | 68 | { |
aburch1 | 83:0d3572a8a851 | 69 | sec=0; |
aburch1 | 83:0d3572a8a851 | 70 | min++; |
aburch1 | 83:0d3572a8a851 | 71 | if(min==60) |
aburch1 | 83:0d3572a8a851 | 72 | { |
aburch1 | 83:0d3572a8a851 | 73 | |
aburch1 | 83:0d3572a8a851 | 74 | min = 0; |
aburch1 | 83:0d3572a8a851 | 75 | hour++; |
aburch1 | 71:a935e4b88ad8 | 76 | |
aburch1 | 83:0d3572a8a851 | 77 | if(hour ==24) |
FairyMental | 46:0de1f3c7d118 | 78 | { |
aburch1 | 83:0d3572a8a851 | 79 | hour = 0; |
aburch1 | 83:0d3572a8a851 | 80 | day++; |
aburch1 | 83:0d3572a8a851 | 81 | |
aburch1 | 83:0d3572a8a851 | 82 | if(day ==31) |
FairyMental | 46:0de1f3c7d118 | 83 | { |
aburch1 | 83:0d3572a8a851 | 84 | day = 0; |
aburch1 | 83:0d3572a8a851 | 85 | month++; |
aburch1 | 83:0d3572a8a851 | 86 | if(month==13) |
FairyMental | 46:0de1f3c7d118 | 87 | { |
aburch1 | 83:0d3572a8a851 | 88 | month = 1; |
aburch1 | 83:0d3572a8a851 | 89 | year++; |
FairyMental | 46:0de1f3c7d118 | 90 | } |
FairyMental | 46:0de1f3c7d118 | 91 | } |
FairyMental | 46:0de1f3c7d118 | 92 | } |
FairyMental | 46:0de1f3c7d118 | 93 | } |
FairyMental | 46:0de1f3c7d118 | 94 | } |
aburch1 | 83:0d3572a8a851 | 95 | } |