Alright this mite b kind of long so thx in advance if u can help me i really really appreciate this. my program was already done. its an association and containment program between pets and their owners and ive done all the stuff already except the owners birthdate.. I now have to use the schools Date class to output the owners birthdate and im havin trouble doing that. i had it working b4 using their class now icant get it. Its alot of diff files ill post what i think shows the prob and if u need more ill post it.
here is the date.cpp file i wont post the .h b/c its pretty much the same ig uess but w/ ou the definitions
Date.cpp - THIS CANT B CHANGED i didnt write this lol
Code:
#include "Date.h"
#include <iostream>
#include <cstdlib>
// When we're not in a header file, it is ok to
// have "using namespace std"
using namespace std;
namespace CS1124{
Date::Date(string date) {
// atoi comes
month = atoi(date.substr(0,2).c_str());
day = atoi(date.substr(3,2).c_str());
year = atoi(date.substr(6,4).c_str());
}
void Date::display(std::ostream& os) const {
os << month << '/' << day << '/' << year;
}
bool Date::earlierThan(Date d) const {
if (year > d.year)
return false;
else if (year < d.year)
return true;
else if (month > d.month)
return false;
else if (month < d.month)
return true;
else if (day >= d.day)
return false;
else
return true;
}
int Date::getYear() const {
return year;
}
void Date::setYear(int x) {
year = x;
}
}
here is my owners.h - ive cut it down
Code:
#ifndef OWNER_H
#define OWNER_H
#include "Pet.h"
#include "Date.h"
#include <string>
namespace CS1124
{
class Owner
{
public:
//constructor initializes the name of the owner and the birthdate
Owner(std::string ownerName, std::string date);
void displayDate ();
private:
//int month, day, year;
std::string ownerName; //owners name
Date date; //from date class. will get the birthdate
Pet* pet; // pointer to the pet class for a pet
};
//Overload << to output the information
std::ostream& operator << (std::ostream & os,const Owner& owner);
}
#endif
and the cpp cut down as well
Code:
#include "Owner.h"
#include "Date.h"
using namespace std;
namespace CS1124
{
//constructor intializes the owners name, the birthdate from the date class
//as well as setting the owner to have no initial pet
Owner::Owner(std::string ownerName, std::string date):
ownerName(ownerName), date(date), pet(NULL)
{}
//output the owners and pets names
void Owner::displayDate()
{
date.display();
}
ostream& operator << (ostream & os,const Owner& owner)
{
//--------------------------------------------
//THIS IS WHERE MY PROBLEM ISS!!!!!!!
//owner.displaydate in specific
//-----------------------------------------------
//display the owner
os<< "Owner: " << owner.getName()
<< " DOB: " <<" " << owner.displayDate();
os << " My Pet: ";
//Check if he has a pet
if(owner.getPet())//display that pet
os<<owner.getPet()->getName();
else //if not say he doesnt
os<<"I don't have a pet.";
return os;
}
}
im sorry its so long - basically i just want to display the date and i have to use the date class to get it and display... ive tried doing
date.display() in the overload << function that didnt work.
i tried now as u can c making a display func inside of owner that dislays the date but thast not working any help is appreciated.. im aslo going to attach the files incase any1 gets really bored.
BTW i coulnt upload Pet.h and pet.cpp b/c im liimted to 5 but i can in another post if any1 wants it lol i doubt it