Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++. write a class called Date to store a date. Member Variables (also called data members) Your class shoud have 3 integer member variables that

C++.

write a class called Date to store a date.

Member Variables (also called data members)

Your class shoud have 3 integer member variables that will store the day, month and year of the date. Your class should not have any other member variables. All member variables should be private.

Member functions

All the member functions described below should be public member functions.

Write a constructor function for your class that has no parameters. The constructor should set the month to 1 (January), the day to 1 and the year to 2001.

Write a "set" member function that allows a new date to be stored in an existing Date object. The function should have 3 integer parameters - one each for the month, day and year. The purpose of these parameters is to provide the values to be stored in the member variables of the object. Your set function should do validation checking on the data supplied in the parameters as follows:

The month should be between 1 and 12 (inclusive).

The day should be between 1 and 31 (inclusive).

The year should be between 1950 and 2020 (inclusive).

If one or more of the parameters contains invalid values, do not update any member variables of the object. Otherwise, store the information from the parameters into the corresponding member variables of the object.

The prototype might look like: void set(int theMonth, int theDay, int theYear);

Write three "print" member functions. Each should print a Date in one of the following formats: 3/15/2016 March 15, 2016 15 March 2016 Important: these are class member functions that print the date stored in a Date object.

Your prototypes might look like: void printNumeric( ); void printAmerican( ); void printEuropean( );

Alternate implementation for "print" functions: Generally you should avoid doing any input or output in a class member functions (the application programmer should have control over input and output). Displaying an object in some standard format is an exception to this rule, but you might want to have these functions return the formatted date as a string so that the application can do the printing.

Testing

Write a main function to test your class. Be sure that your output shows that each of your member functions works. And be sure that you try invalid data as well as valid data.

Other Requirements

Global variables are variables that are declared outside any function. Do not use global variables in your programs. Declare all your variables inside functions.

Use the C++ string class to represent strings in your program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

How is percentage change calculated? AppendixLO1

Answered: 1 week ago

Question

What is job rotation ?

Answered: 1 week ago