![](/media/cache/profiles/ba5be68d3d541f2ca043d77fc54fe702.jpg.50x50_q85.jpg)
3rd Repo, trying to figure this out.
Fork of SOFT253_Template_Weather_OS_54 by
LocalDate/LocalDate.cpp@85:422d0a1b95cf, 2017-05-13 (annotated)
- Committer:
- niallfrancis
- Date:
- Sat May 13 17:35:58 2017 +0000
- Revision:
- 85:422d0a1b95cf
- Parent:
- 83:0d3572a8a851
Finished commenting classes;
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 | |
niallfrancis | 85:422d0a1b95cf | 4 | /** |
niallfrancis | 85:422d0a1b95cf | 5 | @file : LocalDate.cpp |
niallfrancis | 85:422d0a1b95cf | 6 | @authors : Radu Marcu, Jacob Williams, Niall Francis, Arron Burch |
niallfrancis | 85:422d0a1b95cf | 7 | |
niallfrancis | 85:422d0a1b95cf | 8 | @section DESCRIPTION |
niallfrancis | 85:422d0a1b95cf | 9 | |
niallfrancis | 85:422d0a1b95cf | 10 | This is class is the LocalDate class, reponsible for handling the date and |
niallfrancis | 85:422d0a1b95cf | 11 | time. It allows for the date and time to be set during run time, and automatically |
niallfrancis | 85:422d0a1b95cf | 12 | updates the time every second. The class also allows the date to be returned to |
niallfrancis | 85:422d0a1b95cf | 13 | areas of the program. |
niallfrancis | 85:422d0a1b95cf | 14 | */ |
niallfrancis | 85:422d0a1b95cf | 15 | |
niallfrancis | 85:422d0a1b95cf | 16 | |
aburch1 | 83:0d3572a8a851 | 17 | LocalDate::LocalDate(int d, int m, int y,int h,int mm,int s) |
aburch1 | 83:0d3572a8a851 | 18 | { |
aburch1 | 83:0d3572a8a851 | 19 | day = d; |
aburch1 | 83:0d3572a8a851 | 20 | month = m; |
aburch1 | 83:0d3572a8a851 | 21 | year = y; |
aburch1 | 83:0d3572a8a851 | 22 | hour = h; |
aburch1 | 83:0d3572a8a851 | 23 | min = mm; |
aburch1 | 83:0d3572a8a851 | 24 | sec = s; |
aburch1 | 83:0d3572a8a851 | 25 | } |
aburch1 | 83:0d3572a8a851 | 26 | |
aburch1 | 83:0d3572a8a851 | 27 | LocalDate::LocalDate() |
aburch1 | 83:0d3572a8a851 | 28 | { |
aburch1 | 83:0d3572a8a851 | 29 | day = 12; |
aburch1 | 83:0d3572a8a851 | 30 | month = 12; |
aburch1 | 83:0d3572a8a851 | 31 | year = 2012; |
aburch1 | 83:0d3572a8a851 | 32 | hour = 12; |
aburch1 | 83:0d3572a8a851 | 33 | min = 12; |
aburch1 | 83:0d3572a8a851 | 34 | sec = 12; |
aburch1 | 83:0d3572a8a851 | 35 | } |
aburch1 | 83:0d3572a8a851 | 36 | |
aburch1 | 83:0d3572a8a851 | 37 | LocalDate::LocalDate(LocalDate *localDate) |
aburch1 | 83:0d3572a8a851 | 38 | { |
aburch1 | 83:0d3572a8a851 | 39 | day = localDate->day; |
aburch1 | 83:0d3572a8a851 | 40 | month = localDate->month; |
aburch1 | 83:0d3572a8a851 | 41 | year = localDate->year; |
aburch1 | 83:0d3572a8a851 | 42 | hour = localDate->hour; |
aburch1 | 83:0d3572a8a851 | 43 | min = localDate->min; |
aburch1 | 83:0d3572a8a851 | 44 | sec = localDate->sec; |
aburch1 | 83:0d3572a8a851 | 45 | } |
aburch1 | 83:0d3572a8a851 | 46 | |
aburch1 | 83:0d3572a8a851 | 47 | /** |
aburch1 | 83:0d3572a8a851 | 48 | Sets values to passed in localDate object. |
aburch1 | 83:0d3572a8a851 | 49 | |
aburch1 | 83:0d3572a8a851 | 50 | @param localDate : LocalDate object storing data. |
aburch1 | 83:0d3572a8a851 | 51 | */ |
aburch1 | 83:0d3572a8a851 | 52 | void LocalDate::setValues(LocalDate *localDate) |
aburch1 | 83:0d3572a8a851 | 53 | { |
aburch1 | 83:0d3572a8a851 | 54 | day = localDate->day; |
aburch1 | 83:0d3572a8a851 | 55 | month = localDate->month; |
aburch1 | 83:0d3572a8a851 | 56 | year = localDate->year; |
aburch1 | 83:0d3572a8a851 | 57 | hour = localDate->hour; |
aburch1 | 83:0d3572a8a851 | 58 | min = localDate->min; |
aburch1 | 83:0d3572a8a851 | 59 | sec = localDate->sec; |
aburch1 | 83:0d3572a8a851 | 60 | } |
aburch1 | 83:0d3572a8a851 | 61 | |
aburch1 | 83:0d3572a8a851 | 62 | /** |
aburch1 | 83:0d3572a8a851 | 63 | Takes data stored in LocalDate objects and formats it. |
aburch1 | 83:0d3572a8a851 | 64 | |
aburch1 | 83:0d3572a8a851 | 65 | @return charArray : Char array containing formatted data to be printed. |
aburch1 | 83:0d3572a8a851 | 66 | */ |
aburch1 | 83:0d3572a8a851 | 67 | char* LocalDate::ToString() |
aburch1 | 83:0d3572a8a851 | 68 | { |
aburch1 | 83:0d3572a8a851 | 69 | char *charArray = new char[40]; |
aburch1 | 83:0d3572a8a851 | 70 | snprintf(charArray, 256, "%i/%i/%i, %i:%i:%i",day,month,year,hour,min,sec); |
aburch1 | 83:0d3572a8a851 | 71 | return charArray; |
aburch1 | 83:0d3572a8a851 | 72 | } |
aburch1 | 83:0d3572a8a851 | 73 | |
aburch1 | 83:0d3572a8a851 | 74 | /** |
aburch1 | 83:0d3572a8a851 | 75 | Increases time stored in object by one second, calculating the new time. |
aburch1 | 83:0d3572a8a851 | 76 | */ |
aburch1 | 83:0d3572a8a851 | 77 | void LocalDate::TickSecond() |
aburch1 | 83:0d3572a8a851 | 78 | { |
aburch1 | 83:0d3572a8a851 | 79 | sec++; |
aburch1 | 83:0d3572a8a851 | 80 | if(sec == 60) |
FairyMental | 47:468a89d62c23 | 81 | { |
aburch1 | 83:0d3572a8a851 | 82 | sec=0; |
aburch1 | 83:0d3572a8a851 | 83 | min++; |
aburch1 | 83:0d3572a8a851 | 84 | if(min==60) |
aburch1 | 83:0d3572a8a851 | 85 | { |
aburch1 | 83:0d3572a8a851 | 86 | |
aburch1 | 83:0d3572a8a851 | 87 | min = 0; |
aburch1 | 83:0d3572a8a851 | 88 | hour++; |
aburch1 | 71:a935e4b88ad8 | 89 | |
aburch1 | 83:0d3572a8a851 | 90 | if(hour ==24) |
FairyMental | 46:0de1f3c7d118 | 91 | { |
aburch1 | 83:0d3572a8a851 | 92 | hour = 0; |
aburch1 | 83:0d3572a8a851 | 93 | day++; |
aburch1 | 83:0d3572a8a851 | 94 | |
aburch1 | 83:0d3572a8a851 | 95 | if(day ==31) |
FairyMental | 46:0de1f3c7d118 | 96 | { |
aburch1 | 83:0d3572a8a851 | 97 | day = 0; |
aburch1 | 83:0d3572a8a851 | 98 | month++; |
aburch1 | 83:0d3572a8a851 | 99 | if(month==13) |
FairyMental | 46:0de1f3c7d118 | 100 | { |
aburch1 | 83:0d3572a8a851 | 101 | month = 1; |
aburch1 | 83:0d3572a8a851 | 102 | year++; |
FairyMental | 46:0de1f3c7d118 | 103 | } |
FairyMental | 46:0de1f3c7d118 | 104 | } |
FairyMental | 46:0de1f3c7d118 | 105 | } |
FairyMental | 46:0de1f3c7d118 | 106 | } |
FairyMental | 46:0de1f3c7d118 | 107 | } |
aburch1 | 83:0d3572a8a851 | 108 | } |