For class I have a main function provided by the instructor, and I need to build everything to make his main to work correctly. It is based on a Date class that we previously made that has a normal print function in MM/DD/YYYY. I know how to do everything except this:
I don't know how to convert the format to words without creating new objects. I believe it's related to enum, because that's what I can gather from the notes but I can't find a solution anywhere. Any help is appreciated.
Is converting ints to words your only problem or is there more?
Anyway, you will most definitely need a lot of constant strings. For example, a print function could look like this:
Well it's hard for me to explain. He gave us the main function file and told us to make a class with methods that, when compiled and ran, would give the same output that is in the comments next to each line. Where I am really confused is the "Date::setFormat(TEXT)" and "NUMERIC" lines. I don't know what that could even refer to and after reading on enum's for a while I haven't seen anything like that. So I guess my question is what do lines 1 and 8 mean and how do I go about making a method for that that changes the output of each Date object?
Date::setFormat(TEXT); is a static function. For it to make some difference, it has to change some variable. Since the function is static, so is the variable. Your class could look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
enum FORMAT{TEXT, NUMERIC};
class Date{
...
static FORMAT format;
public:
staticvoid setFormat(FORMAT f){
format = f;
}
};
FORMAT Date::format = TEXT;
//and then in your operator <<...
if(Date::format == TEXT){
//pretty much my code
}elseif(Date::format == NUMERIC){
//print mm/dd/yyy
}
note you'll probably have to make operator << a friend function, write a getFormat function of make Date::format public.