Skip to main content
1 of 8
Edward
  • 66.6k
  • 4
  • 118
  • 282

I see a number of things that could help you improve your code.

Don't abuse using namespace std

Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid.

Choose better function names

There are two very similar names organize() and organizeInfo() and it's not obvious without reading the code what the difference might be.

Reconsider the constructor

I found this constructor counterintuitive:

date dawg(cin);

It would have been much easier to understand if it had been written like this:

date dawg;
cin >> dawg;

Use const where practical

Your outputInfo() member fuction does not alter the underlying date, so it should be declared const. In general, whenever you are writing a variable or function prototype look for places you can use const.

Write object I/O functions as inserters and extractors

Instead of a member function outputInfo, write an extractor instead:

friend ostream &operator<<(std::ostream &out, const date& d) { 
    return out << d.year << " " << d.month << " " << d.day; 
}

Similarly, instead of the constructor taking a reference to a std::istream, use a inserter:

friend istream& operator>>(std::istream &in, date& d) {
    return in >> d.year >> d.month >> d.day; 
}

Fix the prompt string

It may seem like a minor issue but the user interface is a very important part of most programs because it's the only part that a user would see. For that reason instead of "and ill try and organize" which sound like the program is not well, it should be "and I'll try ..."

Use true and false for boolean values

Since you're using C++, you should use the keywords true and false instead of 1 and 0 for boolean return values.

Eliminate return 0 at the end of main

When a C++ program reaches the end of main the compiler will automatically generate code to return 0, so there is no reason to put return 0; explicitly at the end of main.

Edward
  • 66.6k
  • 4
  • 118
  • 282