Thank you, all, for the help. Alas, I have two more errors which I've been unable to resolve.
Errors:
Date_Hardesty.cpp: In member function ‘std::string Date::getMonthName(int)’:
Date_Hardesty.cpp:81:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:83:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:85:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:87:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:89:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:91:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:93:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:95:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:97:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:99:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:101:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:103:7: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp:105:11: error: ‘name’ was not declared in this scope
Date_Hardesty.cpp: In member function ‘void Date:rintLong()’:
Date_Hardesty.cpp:118:73: error: expected primary-expression before ‘int’
DateDemo.cpp: In function ‘int main()’:
DateDemo.cpp:38:37: error: expected primary-expression before ‘int’
That same ole header file:
Code:
#include <string>
//prevent multiple inclusions of header
#ifndef DATE_H
#define DATE_H
//Define Date class
class Date
{
public:
explicit Date () : month (1), day (1), year (2000) // my default
{ // constructor
// sets date to
}; // Jan 1, 2000
explicit Date (int month, int day, int year); //my 3-arg constructor
void setMonth (int); //function sets the Month
void setDay (int); //function sets the Day
void setYear (int); //function sets the Year
int getMonth (); //the function to return the int Month
int getDay (); //the function to return the int Day
int getYear (); //the function to return the int Year
std::string getMonthName (int); //to receive the string name of the Month
void print (); //function to output Date as MM/DD/YYYY
void printLong (); //function to output Date as DD MonthName YYYY
~Date (); //makin' sure everything gets destructed in order
private:
int month, day, year;
}; //end the class Date
#endif
excerpts from my Date_Hardesty.cpp file
Code:
//**LINE 77** function to return the MonthName to main
std::string Date::getMonthName (int m)
{
if (m = 1)
name = "January";
if (m = 2)
name = "February";
if (m = 3)
name = "March";
if (m = 4)
name = "April";
if (m = 5)
name = "May";
if (m = 6)
name = "June";
if (m = 7)
name = "July";
if (m = 8)
name = "August";
if (m = 9)
name = "September";
if (m = 10)
name = "October";
if (m = 11)
name = "November";
if (m = 12)
name = "December";
return name; //send the Month's name back to main
} //end getMonthName
So, I tried adding a string "name" to the "private" area of my header, but that gave me the same errors. I tried adding "name" to my cpp file with my main function, but that also did not work. Clearly I should be initializing "name" somewhere else, but I don't know where.
Then, the errors about, "expected primary expression before 'int'" confuses me.
Code:
//**LINE 38** start function to set the Day according to the assignment's parameters
void Date::setDay(int d)
{
if (d >= 1 && d <= 31)
day = d;
else
day = 1;
} //end setDay
...
some more code
...
//**LINE 115** function to format the DD Month YYYY printLong function
void Date::printLong ()
{
cout << setfill ('0') << setw (2) << getDay() << " " << getMonthName(int) << " " << getYear() << "\n";
} //end printLong function
Your thoughts?