0 / 0 / 0
Регистрация: 19.03.2018
Сообщений: 6
1

Описать структуру «дата» (год, месяц, день

09.04.2018, 13:42. Показов 4272. Ответов 1
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Описать структуру «дата» (год, месяц, день). Определить функцию «дней до конца года» вычисляющую количество дней до конца года.
0
Лучшие ответы (1)
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
09.04.2018, 13:42
Ответы с готовыми решениями:

Создайте структуру Дата с элементами День, Месяц, Год.
Народ, не могу понять структуры и учитель ничего не объясняет, помогите с кодом. Создайте...

Создайте класс «Дата» со свойствами год, високосный год, месяц, день месяца и день недели
Создайте класс «Дата» со свойствами год, високосный год, месяц, день месяца и день недели. ...

Дана дата в формате день:месяц:год. Определить день недели
Задание: Дана дата в формате день:месяц:год. Определить день недели.

Дата, год, месяц, день
/* Дата год, месяц, день от 01.01.0001 до 31.12.2999 Date Високосными являются года кратные...

1
"C with Classes"
1634 / 1392 / 521
Регистрация: 16.08.2014
Сообщений: 5,828
Записей в блоге: 1
09.04.2018, 13:52 2
Лучший ответ Сообщение было отмечено SAFsf как решение

Решение

SAFsf, может поможет
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <cstddef>
#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <cstring>
#include <ctime>
 
typedef unsigned char DateType;
class BadDate { };
 
class Date
{
public:
    Date();
    explicit Date(const std::string&);
 
    void SetDate(const std::string&);
    std::string GetDate() const;
 
    int GetDay() const;
    int GetMonth() const;
    int GetYear() const;
 
    static bool IsLeapYear(DateType);
    static DateType DaysInMonth(DateType, bool);
 
    Date& operator=(const Date&);
 
    bool operator<(const Date&) const;
    bool operator>(const Date&) const;
    bool operator==(const Date&) const;
    bool operator!=(const Date&) const;
 
private:
    std::string day, month, year;
    const unsigned char SIZE = 8;
};
 
Date::Date()
{
    time_t s; tm t;
 
    s = time(nullptr);
    localtime_s(&t, &s);
    
    day = std::to_string(t.tm_mday);
    month = std::to_string(t.tm_mon + 1);
    year = std::to_string(t.tm_year - 100);
}
Date::Date(const std::string& s)
{
    SetDate(s);
}
 
void Date::SetDate(const std::string& s)
{
    if (s.size() !=  SIZE) throw BadDate();
 
    std::string::const_iterator cIt = s.cbegin();
    while (isspace(*cIt) ) cIt++;
 
    if (!day.empty() ) day.clear();
    if (!month.empty() )month.clear();
    if (!year.empty() )year.clear();
 
    for (unsigned char i = 0; i < SIZE; i++)
    {
        switch (i)
        {
        case 0:
        case 1:
            day.push_back(*cIt++);
            break;
 
        case 3:
        case 4:
            month.push_back(*cIt++);
            break;
 
        case 6:
        case 7:
            year.push_back(*cIt++);
            break;
 
        default:
            if (*cIt++ != '.') throw BadDate();
        }
    }
 
    DateType d, m , y;
 
    try
    {
        d = std::stoi(day);
        m = std::stoi(month);
        y = std::stoi(year);
    }
    catch(...)
    {
        throw BadDate();
    }
 
    if (m > 12) throw BadDate();
    if (d > DaysInMonth(m, IsLeapYear(y) ) ) throw BadDate();
}
std::string Date::GetDate() const
{
    return day + '.' + month + '.' + year;
}
 
inline int Date::GetDay() const
{
    return std::stoi(day);
}
inline int Date::GetMonth() const
{
    return std::stoi(month);
}
inline int Date::GetYear() const
{
    return std::stoi(year);
}
 
Date& Date::operator=(const Date& d)
{
    day = d.day;
    month = d.month;
    year = d.year;
 
    return *this;
}
 
bool Date::operator<(const Date& d) const
{
    return this->GetYear() < d.GetYear() ||
        this->GetMonth() < d.GetMonth() ||
        this->GetDay() < d.GetDay();
}
bool Date::operator>(const Date& d) const
{
    return d.operator<(*this);
}
bool Date::operator==(const Date& d) const
{
    return !d.operator<(*this) && !d.operator>(*this);
}
bool Date::operator!=(const Date& d) const
{
    return !d.operator==(*this);
}
 
bool Date::IsLeapYear(DateType i)
{
    return ( !(i % 4) || !(i % 100) || !(i % 400) );
}
DateType Date::DaysInMonth(DateType m, bool l)
{
    switch(m)
    {
    case 1:    return 31;
    case 2:
        if (l) return 29;
        else   return 28;
    case 3:    return 31;
    case 4:    return 30;
    case 5:    return 31;
    case 6:    return 30;
    case 7:    return 31;
    case 8:    return 31;
    case 9:    return 30;
    case 10:   return 31;
    case 11:   return 30;
    case 12:   return 31;
    default:   throw BadDate();
    }
}
 
std::ostream& operator<<(std::ostream& s, const Date& d)
{
    s << d.GetDate();
    return s;
}
std::istream& operator>>(std::istream& s, Date& d)
{
    std::string temp;
    s >> temp;
    d.SetDate(temp);
 
    return s;
}
 
int main()
{
    Date d;
 
    return 0;
}
0
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
09.04.2018, 13:52
Помогаю со студенческими работами здесь

Дата в формате <день>.<месяц>.<год>
а дальше нужно будет определить, например, сколько дней прошло с начала года и т.п. Подскажите,...

Создать структуру, содержащую день, месяц и год.
Ввести несколько структур с полями день месяц год Написать программу, выполняющую...

Создать класс Date – дата, содержащая поля: день, месяц, год.
Создать класс Date – дата, содержащая поля: день, месяц, год. Определить операторы &quot;+&quot; и &quot;-&quot;, как...

Дата вводится строкой нужно извлечь день месяц и год в int переменные
Дата вводится строкой нужно извлечь день месяц и год в int переменные. два варианта передачи...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2023, CyberForum.ru