Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6730517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:25:04+00:00 2026-05-26T10:25:04+00:00

First: I know how to write the program, so I’m not asking for help

  • 0

First: I know how to write the program, so I’m not asking for help with that. However, I am pasting a copy of the problem so you can see what the assignment entails. My question is specifically aimed at where do you place variables to keep from making everything global?

Assignment

Design a class called Date that has integer data members to store month, day, and year. The class should have a three-parameter default constructor that allows the date to be set at the time a new Date object is created. If the user creates a Date object without passing any arguments, or if any of the values passed are invalid, the default values of 1, 1, 2001 (i.e., January 1, 2001) should be used. The class should have member functions to print the date in the following formats:

3/15/10
March 15, 2010
15 March 2010

Questions

1) The teacher has instructed us to avoid using magic numbers in our code, so the first question is regarding my implementation of the default constructor:

// These are outside the class.
#define DEFAULT_MONTH 1
#define DEFAULT_DAY   1
#define DEFAULT_YEAR  2001

// This is inside the class definition.
Date(int month = DEFAULT_MONTH, int day = DEFAULT_DAY, int year = DEFAULT_YEAR);

Is this correct?

2) The class needs access to an array of string objects which hold the month names so I can use them for date outputs which display the month name instead of the month number. I used an enum for the numeric month (which will be used for the switch).

const enum MONTH_IDS { JANUARY = 1, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY,
    AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER };

const string MONTH_NAMES[NUM_MONTHS] = { "January", "February", "March",
    "April", "May", "June", "July", "August", "September", "October",
    "November", "December" };

The question for this part, is where do you place them?

Some things I can’t do…
I am not allowed to use static class members yet because that will be covered in the next chapter. We also have not gone over pointers, but we can use references.

Thanks for your help!

I would ask the instructor but he is out of town and the assignment is due tomorrow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:25:05+00:00Added an answer on May 26, 2026 at 10:25 am

    1) Defines are ugly. static const int members are what I would do, but you can’t … How about enums?

    struct Date {
        enum Constants {
            DEFAULT_YEAR = 2001,
            DEFAULT_MONTH = 1,
            DEFAULT_DAY = 1,
        };
    
    
        Date(int month = DEFAULT_MONTH, int day = DEFAULT_DAY, int year = DEFAULT_YEAR);
    
    };
    

    2) A static member array is just what you need. But since you can’t … maybe static local variables:

    struct Date {
        std::string MonthToString(enum MONTH_IDS m) {
            static const char *monthNames[] = {
                "January", "February", "March", "April", "May", "June",
                "July", "August", "September", "October", "November", "December" };
            if(m >= sizeof(monthNames)/sizeof(monthNames[0]))
                return std::string("Unknown");
            return std::string(monthNames[m]);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first time SO user :) I know that I can format a number like
First off: I know that this isn't reliable for actually checking if I can
I would like to write a program that keeps asking for user input until
I have a program (that I did not write) which is not designed to
Let me state first: I know that any user that wants to run a
Let's get this out of the way first: I know that SessionFactory is immutable
First of all: I do know that there are already many questions and answers
I know that I need to tell my UITextField to resign first responder when
I'm working on a program for class that involves solving the Chinese Postman problem
I'm trying to write a program that scans in values from the console and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.