Confused about class

I'm running into problems writing a program that uses class and other functions. Everything appears fine until the the very end, and I get the error message "too few arguments in the function call". Any help would be appreciated.

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
#include<string> 
using namespace std;

class Date {
public:
	Date();
	Date(int, int,int);
	void showDate1(int month,int day,int year);
	void showDate2(string monthName, int day, int year);
	void showDate3(int day,string monthName,int year);
	void setDate(int month, int day, int year);
	string monthName();
private:
	int month;
	int day;
	int year;
	
};
  

#include<string>
#include<iostream>
using namespace std;
#include "date.h"
//HW6 class implementation
Date::Date()
{
	day = 1;
	month = 1;
	year = 2001;
}

Date::Date(int month, int day, int year)
{
	day = day;
	month = month;
	year = year;

}
string Date::monthName()
{
	if (month == 1)
		return "January";
	else if (month == 2)
		return "February";
	else if (month == 3)
		return "March";
	else if (month == 4)
		return "April";
	else if (month == 5)
		return "May";
	else if (month == 6)
		return "June";
	else if (month == 7)
		return "July";
	else if (month == 8)
		return "August";
	else if (month == 9)
		return "September";
	else if (month == 10)
		return "October";
	else if (month == 11)
		return "November";
	else if (month == 12)
		return "December";
}

void Date:: showDate1(int month, int day, int year)
{
	cout << month << "/" << day << "/" << year << endl;
}
void Date :: showDate2(string monthName, int day, int year)
{
	cout << monthName << " " << day << ", " << year << endl;
}
void Date:: showDate3(int day, string monthName, int year)
{
	cout << day << " " << monthName << " " << year << endl;
}
void Date:: setDate(int month, int day, int year)
{
	day = day;
	month = month;
	year = year;
}


#include <iostream>
using namespace std;
#include "date.h"
int main()
{
	Date d1;
	Date d2(2, 12, 2010);
	d1.showDate1();
	d2.showDate2();
	d1.setDate(8, 29, 1986);
	d1.showDate3();
	system("pause");
	return 0;
}
Where is your error, what line is complaining?
The message is appearing at 95, 96, and 98.
On your declaration of the functions you have:
1
2
3
void showDate1(int month,int day,int year);
void showDate2(string monthName, int day, int year);
void showDate3(int day,string monthName,int year);


When you call the functions you have:
1
2
3
d1.showDate1();
d2.showDate2();
d1.showDate3();


showDate1(), showDate2(), showdate3() are declared with 3 variables as arguments, but are used without.
I tried the call code like this

d1.showDate1(int month, int day, int year);

on all three errors and all I got was a new error code, saying type name not allowed.
You should do something like this:

d1.showDate1(30, 4, 2016);

then

d2.showDate("April", 4, 2016);

then

d1(30, "April", 2016);
Last edited on
Topic archived. No new replies allowed.