no matching function for call to ""

Pages: 12
Yeah, you need to provide the 2 parameters, namely month, date as per line 19 of the Date.cpp file
Never mind, i fixed it :)
Thank you all for the help, with every little bit of help I understand more about this complicated language, have a nice day!
Here's my final code, it may be dirty, but I will learn to clean it up. (.cpp file)
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
#include "Date.h"
#include <string>
#include <iostream>
#include <iomanip>
int Date::dayNumber(int date)
{
    int dayDefault = 1;
    if (date < 1 || date > 31)
    {
        date = dayDefault;
        return date;
    }
    else
    {
        return date;
    }
}

std::string Date::monthWord(int month, int date)
{
	dayDefault = 1;
    if (month < 1 || month > 12)
    {
        month = monthDefault;
        monthName = "January";
        return monthName;
    }
    switch (month)
    {
        case 1:
        monthName = "January";
        if (date < 1 || date > 31)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 2:
        monthName = "February";
        if (date < 1 || date > 29)
    	{
        	date = dayDefault;
   	 	}
   	 	return monthName;
        break;
        case 3:
        monthName = "March";
        if (date < 1 || date > 31)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 4:
        monthName = "April";
        if (date < 1 || date > 30)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 5:
        monthName = "May";
        if (date < 1 || date > 31)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 6:
        monthName = "June";
        if (date < 1 || date > 30)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 7:
        monthName = "July";
        if (date < 1 || date > 31)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 8:
        monthName = "August";
        if (date < 1 || date > 31)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 9:
        monthName = "September";
        if (date < 1 || date > 30)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 10:
        monthName = "October";
        if (date < 1 || date > 31)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 11:
        monthName = "November";
        if (date < 1 || date > 31)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
        case 12:
        monthName = "December";
        if (date < 1 || date > 31)
    	{
        	date = dayDefault;
    	}
    	return monthName;
        break;
    }
}

int Date::yearNumber(int year)
{
    int yearDefault = 2000;
    if (year < 1900 || year > 2099)
    {
        year = yearDefault;
        return year;
    }
    return year;
}

void Date::showDates()
{
    std::cout << monthDefault << "/" << dayDefault << "/" << yearDefault << std::endl;
    std::cout << monthName << " " << dayDefault << ", " << yearDefault << std::endl;
    std::cout << dayDefault << "." << monthName << "." << yearDefault << std::endl;
    std::cout << std::setprecision(2) << yearDefault << "." << std::setfill('0') << std::setw(2) << monthDefault << "." << std::setfill('0') << std::setw(2) << dayDefault << std::endl;
}

int main()
{
    Date dates(4, 31, 2021);
    dates.showDates();
}
(.h file)
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
#ifndef DATE_H
#define DATE_H

#include <string>

class Date {
    private:
    int dayDefault;
    int yearDefault;
    std::string monthName;
    int monthDefault = 1;
    public:
    	
    Date(int month, int date, int year)
    {
        monthDefault = month;
        dayDefault = date;
        yearDefault = year;
        monthName = "";
        monthWord(month, date);
    }
    
    ~Date(){}
    int dayNumber(int);
    std::string monthWord(int, int);
    int yearNumber(int);
    void showDates();
};
#endif 
Something to think about in relation to the use of arrays I mentioned :)
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
#ifndef DATE_H
#define DATE_H

#include <string>

static const std::string month_name[]
{
    "dummy",
    "Jan","Feb","Mar", "Apr","May","Jun",
    "Jul","Aug","Sep", "Oct","Nov","Dec"
};

static const int days_in_month[]
{ -99, 31,28,31, 30,31,30, 31,31,30, 31,30,31 };

class Date
{
private:
    int day;
    int year;
    int month;
    
public:
    Date(int aMonth = 1, int aDay = 1, int aYear = 1901)
    {
        month = aMonth;
        day = aDay;
        year = aYear;
    }
    
    ~Date(){};
    
    std::string monthWord(int);
    void showDate();
    bool isValid();
};
#endif


//#include "Date.h"
#include <string>
#include <iostream>
#include <iomanip>

std::string Date::monthWord(int aMonth)
{
    return month_name[aMonth];
}

bool Date::isValid()
{
    if(year < 1900 or year > 2021)
        return false;
    
    if(month < 1 or month > 12)
        return false;
    
    if( day < 1 or day > days_in_month[month])
        return false;
        
       return true;
}

void Date::showDate()
{
    std::cout << month << "/" << day << "/" << year << std::endl;
    std::cout << monthWord(month) << " " << day << ", " << year << std::endl;
    std::cout << day << "." << monthWord(month) << "." << year << std::endl;
    
    std::cout
    << year << "."
    << std::setw(2) << std::setfill('0') << month << "."
    << std::setw(2) << std::setfill('0') << day << std::endl;
}

int main()
{
    Date date1(4, 29, 2021);
    date1.showDate();
    
    Date date2;
    date2.showDate();
    
    Date date3(7,14,1987);
    date3.showDate();
    
    Date date4(4,31,1987);
    if(date4.isValid())
        date4.showDate();
    else
        std::cout << "*** Invalid date\n";
    
    Date date5(12,12,2022);
    if(date5.isValid())
        date5.showDate();
    else
        std::cout << "*** Invalid date\n";
}
Last edited on
Registered users can post here. Sign in or register to post.
Pages: 12