Need help understanding set-get and classes...

So our professor told us to do the following:

Modify the Date.h and Date.cpp to include four more member functions setDate(), getDate(), setMonth(), getMonth(). Use these functions to modify the Date, Month along with year in the TestFriendClass.cpp.

Submit all three program files.


This is Date.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Date
{
public:
	Date(int, int, int);
	void setYear(int);
	int getYear();

	friend class AccessDate;

private:
	int year;
	int month;
	int day;
};


This is Date.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "Date.h"

Date::Date(int newYear, int newMonth, int newDay)
{
  year = newYear;
  month = newMonth;
  day = newDay;
}

int Date::getYear()
{
  return year;
}

void Date::setYear(int newYear)
{
  year = newYear;
}


This is TestFriendClass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include "Date.h"
using namespace std;

class AccessDate
{
public:
  static void p()
  {
    Date birthDate(2010, 3, 4);
    birthDate.year = 2000;
    cout << birthDate.year;
  }
};

int main()
{
  AccessDate::p();

  return 0;
}


Can somebody show me how to do this as well as including explanations? I just really have a hard time understanding classes especially when doing the set-get part. Sorry if this is a stupid question. I am very new to programming, and C++ is my first language.
closed account (E0p9LyTq)
Class basics:
http://www.cplusplus.com/doc/tutorial/classes/
http://www.learncpp.com/cpp-tutorial/81-welcome-to-object-oriented-programming/
Topic archived. No new replies allowed.