Ok, I'm terrible at programming. I've been reading the two textbooks I have and I feel like I'm getting dumber and dumber. All that being said, I could use some help. The instructions for my program are incredibly vague for the most part. So here's my instructions:
Design a class called Date that has data members to store month, day, and year. The class should have a default constructor and a three-parameter constructor that allows the date to be set at the time a new Date object is created. If the user creates a Date object without passing any arguments, or if any of the values passed are invalid, the default values of 1, 1, 2001 (i.e., January 1, 2001) should be used. Be sure your program only accepts reasonable values for month, day, and year. The day should be between 1 and the number of days in the selected month.
Alright, so what this doesn't mention is that I have to have a .h file for the class, and two .cpp files, one for my main and one for my functions. I have set up all three files and I was told my class was set up correctly. So I guess at the moment I'm having trouble with connecting the three files. I'm getting these errors that I don't know how to fix. It's probably easy but again, i'm terrible at this stuff. So here's my errors:
date.cpp:27: error: ISO C++ forbids declaration of ‘get_date’ with no type
date.cpp:27: error: prototype for ‘int date::get_date(int, int, int)’ does not match any in class ‘date’
./date.h:28: error: candidate is: void date::get_date(int, int, int)
main.cpp: In function ‘int main()’:
main.cpp:22: error: expected unqualified-id before ‘.’ token
|
And here's my files:
date.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
class date
{
private:
int month;
int day;
int year;
public:
date();
date( int, int, int );
void get_date( int, int, int );
void check_date( int, int, int );
int print_date( int, int, int );
};
|
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
|
#include <iostream>
#include <cstdlib>
#include "./date.h"
using namespace std;
date::date( int m, int d, int y )
{
month = m;
day = d;
year = y;
}
date::get_date( int m, int d, int y )
{
cout << "Enter month: ";
cin >> date.month;
cout << "Enter day: ";
cin >> date.day;
cout << "Enter year: ";
cin >> date.year;
}
|
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
#include <cstdlib>
#include "./date.h"
using namespace std;
int main()
{
int m, d, y;
date.date( m, d, y );
return 0;
}
|
I'm truly trying to understand this stuff so if there's anything at all someone can tell me to let me know what/why what I've done is wrong and any suggestions about how I might want to go about completing this code will be greatly appreciated. I must enforce that I don't expect to have any code written for me. Examples about things could be helpful. Mostly I just want to understand. All help is greatly appreciated. :)
**EDIT**
I just realized the line numbers aren't going to be correct because of how I copy and pasted. I hope this makes sense: date.cpp line 27 is the date::get_date( int m, int d, int y ). date.h line 28 is the void get_date(int, int, int). main.cpp line 22 is the date.date(m, d, y). Obviously my get date functions are messed up, I just don't know how. :)