-
Notifications
You must be signed in to change notification settings - Fork 0
/
Date.cpp
76 lines (70 loc) · 1.28 KB
/
Date.cpp
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
#include <iostream>
#include "Customer.h"
#include "Date.h"
#include "Inventory.h"
#include "Tablet.h"
Date::Date(int m, int d, int y)
{
day=d;
month=m;
year=y;
}
Date::Date(string s)
{
string delimiter;
if(s.find("/")>=0)
{
delimiter="/";
}
else delimiter="-";
int arr[2];
size_t pos = 0;
string token;
int i=0;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
arr[i]=atoi(token.c_str());
s.erase(0, pos + delimiter.length());
i++;
}
year=atoi(s.c_str());
day=arr[1];
month=arr[0];
}
Date::~Date()
{
cout<<"Date Deleted"<<endl;
}
void Date::setDate(string s)
{
string delimiter;
if(s.find("/")>=0)
{
delimiter="/";
}
else delimiter="-";
int arr[2];
size_t pos = 0;
string token;
int i=0;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
arr[i]=atoi(token.c_str());
s.erase(0, pos + delimiter.length());
i++;
}
year=atoi(s.c_str());
day=arr[1];
month=arr[0];
}
string Date::getDate()
{
string b="";
ostringstream ss;
ss << month;
ss<<"/";
ss<<day;
ss<<"/";
ss<<year;
return ss.str();
}