Hi basically my problem is that I am getting what I believe to be is the address of the object but I want to get the value that is stored in the object. Below is the code I wrote. I've included Date.cpp and my main function file. Say if I typed in 5/26/1988
I'm getting 1231231313/123123123123/-2 or something like that. What is going wrong?
//Main file
int main(){
//Value that returns true or false in the form of 0 or 1
bool test;
//Sets up a constructor and Date object to use in the Date class
Date individualBirth;
//creates an object to be implemented in the Actor class
Actor characterAttributes;
//Queries the user for the day of the month the individual was born
cout << "On what day was your individual born?(DD)" << endl;
int setDay;
cin >> setDay;
test = individualBirth.validityDay(setDay);
while(test == 0){
cout << "On what day was your individual born?(DD)" << endl;
cin >> setDay;
test = individualBirth.validityDay(setDay);
}
//Queries the user for the month the individual was born on
cout << "On what month was your individual born?(MM)" << endl;
int setMonth;
cin >> setMonth;
//calls mutator function and returns a boolean value
test = individualBirth.validityMonth(setMonth);
//Makes sure user enters a legitimate month within 1 to 12
while(test == 0){
cout << "On what month was your individual born?(MM)" << endl;
cin >> setMonth;
test = individualBirth.validityMonth(setMonth);
}
//Queries the user for the year the individual was born on
//Any year is possible!
cout << "What year was your individual born?(YYYY)" << endl;
int setYear;
cin >> setYear;
//Calls default constructor to set user input values to the Date class
Date(setDay, setMonth, setYear);
//Displays date of birth of the individual in correct format
cout << individualBirth.getCharacteristics() << endl;
//Queries user for the temperament of the individual
cout << "Enter 1 if the individual is good or -1 if the individual is bad:" << endl;
int setTendency;
cin >> setTendency;
test = characterAttributes.validityTendency(setTendency);
//Makes sure user typed in a 1 or a -1 for the user's temperament
while(test == 0){
cout << "Please enter the character's temperament by typing 1 or -1 in uppercase then press enter" << endl;
cin >> setTendency;
test = characterAttributes.validityTendency(setTendency);
}
//Queries user for the height of the individual
cout << "What is the height of the individual in feet?" << endl;
int setHeight;
cin >> setHeight;
test = characterAttributes.validityHeight(setHeight);
//Makes sure user typed in an integer between 0 and 1000
while(test == 0){
cout << "What is the height of the individual in feet?" << endl;
cin >> setHeight;
test = characterAttributes.validityHeight(setHeight);
}
//Queries user for the weight of the individual
cout << "What is the weight of the individual in pounds?" << endl;
int setWeight;
cin >> setWeight;
test = characterAttributes.validityWeight(setWeight);
//Makes sure user typed in an integer between 0 and 1000
while(test == 0){
cout << "What is the weight of the individual in pounds?" << endl;
cin >> setWeight;
test = characterAttributes.validityWeight(setWeight);
}
//Sends values to the default constructor in the Actor class
Actor(setHeight, setWeight, setTendency);
characterAttributes.getCharacteristics();
}
//Date.cpp
Date::Date(){
test = false;
}
//constructor initializes variables to user input
Date::Date(int initialDay, int initialMonth, int initialYear){
day = initialDay;
month = initialMonth;
year = initialYear;
}
//returns day of birth
int Date::getDay() const{
return day;
}
//returns month of birth
int Date::getMonth() const{
return month;
}
//returns year of birth
int Date::getYear() const{
return year;
}
//Mutator method that checks validity of the day
bool Date::validityDay(int testDay){
if(testDay > 0 && testDay < 31)
test = true;
else
test = false;
return test;
}
//Mutator method that checks validity of the month
bool Date::validityMonth(int testMonth){
if(testMonth > 0 && testMonth < 13)
test = true;
else
test = false;
return test;
}
//Collects day, month, year of birth and formats them for the appropriate display
string Date::getCharacteristics(){
day = getDay();
month = getMonth();
year = getYear();
string date;
string brackets = "/";
//Takes the first integer and converts it into a string
//Creating a new variable and assigning it to out.str()
std::string dayString;
std::stringstream out;
out << day;
dayString = out.str();
std::string monthString;
std::stringstream out2;
out2 << month;
monthString = out2.str();
std::string yearString;
std::stringstream out3;
out3 << year;
yearString = out3.str();
//After converting the integers to strings
//concantenation is necessary to attach the strings to create
//a string that looks something like this DD/MM/YYYY
date = dayString + brackets + monthString + brackets + yearString;
return date;
}