Hey people,
I have a program here which is giving me a lot of problems. Im just learn c++ and I'm following a book, the excercise is spearation of interface and implementation.
Here's the code (3 files) :
* Main Program *
* Second file - "pair.h" *Code:#include <string.h>
#include <iostream.h>
#include "pair.h"
class Date : public Pair {
public:
int getYear () {
return aYear;
}
Date (int day, int month, int year) {
// set attributes of pair
setNum1 (day);
setNum2 (month);
// set new attribute
aYear = year;
}
void output () {
cout << getNum1 () << "." << getNum2 () << "."
<< aYear << endl;
}
void output2 () {
cout << "the value of day is " << day << endl; }
private:
int aYear; // the year
};
main () {
Date HeidiKlum (4,8,1976); // the constructor
HeidiKlum.output2 ();
cout << "the contents of aYear is for Heidi is" << " "
<< HeidiKlum.getYear () << endl;
};
* Third file - "pair.cpp" *Code:// pair.h file
#ifndef PAIR_H__
#define PAIR_H__
class Pair {
public:
Pair (int num1, int num2);
Pair ();
void output ();
void setNum1 (int num);
void setNum2 (int num);
private:
int aNum1;
int aNum2;
};
#endif
Code:// Pair.cpp file
#include <iostream.h>
#include "pair.h"
Pair :: Pair (int num1, int num2) {
aNum1 = num1;
aNum2 = num2;
}
Pair :: Pair () {
aNum1 = 0;
aNum2 = 0;
}
void Pair :: output () {
cout << aNum1 << " " << aNum2 << endl;
}
void Pair :: setNum1 (int num) {
aNum1 = num;
}
void Pair :: setNum2 (int num) {
aNum2 = num;
}
Thanks for the help!:mad: :mad: