I'm still very new to programming, and have bumped into an issue that I'm sure is very basic.
So what I'm trying to do, is use functions that I defined in one .h-file, and then wrote out in the .cpp-file belonging to that .h-file, in another .cpp-file. Is this possible?
Date.h file:
#pragma once
#ifndef DATE_GUARD
#define DATE_GUARD
#include <iostream>
class Date
{
public:
Date();
Date(int);
int getDay();
int getMonth();
int getYear();
int getDate();
bool leapYear();
~Date();
private:
int theDate;
};
#endif
CPR.h file
#pragma once
#include"Date.h"
class CPR
{
public:
CPR();
CPR(unsigned long); //DDMMYYXXXX
Date getDate();
int getFinalFour();
bool validate();
int getFirstCipher();
int getSecondCipher();
int getThirdCipher();
int getFourthCipher();
int getFifthCipher();
int getSixthCipher();
int getSeventhCipher();
int getEighthCipher();
int getNinthCipher();
int getTenthCipher();
~CPR();
private:
int CPRNummer;
Date birthday;
};
Date.cpp file
#include "Date.h"
Date::Date()
{
}
Date::Date(int aDate)
{
theDate = aDate;
}
int Date::getDay()
{
return theDate / 10000;
}
int Date::getMonth()
{
return (theDate / 100) % 100;
}
int Date::getYear()
{
return (theDate % 100);
}
bool Date::leapYear()
{
if (getYear() % 4 != 0)
return false;
if (getYear() % 100 == 0 && getYear() % 400 != 0)
return false;
return true;
}
int Date::getDate()
{
return theDate;
}
Date::~Date()
{
}
CPR.cpp file (only important part)
#include "CPR.h"
#include "Date.h"
#include <iostream>
bool CPR::validate()
{
if (getDay() < 1 || getDay() > 31)
return false;
if (getMonth() < 1 || getMonth() > 12)
return false;
if (getYear() < 1700 || getYear() > 2100)
return false;
if (getMonth() == 2 && leapYear() && getDay() > 29)
return false;
if (!leapYear() && getMonth() == 2 && getDay() > 28 || getMonth() == 4 && getDay() > 30 || getMonth() == 6 && getDay() > 30 || getMonth() == 9 && getDay() > 30 || getMonth() == 11 && getDay() > 30)
return false;
return true;
}
So I'm trying to use the leapYear(), getMonth(), getDay() and getYear() functions from Date.cpp in CPR.cpp.