Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I would like to check if there is any way to improve the code following the requirements. Thanks. only include two files: Date.h and

Hello I would like to check if there is any way to improve the code following the requirements. Thanks.

only include two files: Date.h and testDate.cpp

Design a class called Date. The Date class should store a date in three integers: month, day, and year. There should be member functions to print the date in the different forms supported by the member methods. Here is the set of testing that you should include in the main application:

 // using the overloaded constructor. Date today(12, 25, 2012); // Show the date in form #1. today.showDate1(); // Store a new month, day, and year // in the object. today.setMonth(8); today.setDay(16); today.setYear(2012); // Show the date in form #2. today.showDate2(); // Show the date in form #3. today.showDate3(); // Test invalid date. Date someday(12, 32, 2012); 

Demonstrate the class by writing a complete program implementing it. Input Validation: Do not accept values for the day greater than 31 or less than 1. Do not accept values for the month greater than 12 or less than 1.

Date.h

#include #include #include #ifndef DATE_H #define DATE_H class Date { private: int month; int day; int year; std::vector<:string> months{ "Janurary", "Feburary", "March", "April" , "May", "June", "July", "August", "September", "October", "November", "December" }; bool check() { int maxDays = 0; maxDays = (tolower(months.at(month - 1).at(2)) == 'y') || (tolower(months.at(month - 1).at(3)) == 'u') || (tolower(months.at(month - 1).at(3)) == 'c') || (tolower(months.at(month - 1).at(3)) == 'y') || (tolower(months.at(month - 1).at(3)) == 'o') || ((tolower(months.at(month - 1).at(3)) == 'e') && (tolower(months.at(month - 1).at(0)) == 'd')); //check max days maxDays = 30 + maxDays - ((tolower(months.at(month - 1).at(0)) == 'f') * 2); if (month > 0 && month 0 && day

testDate.cpp

#include "Date.h" #include using namespace std; void Date::setMonth(int m) { month = m; } void Date::setDay(int d) { day = d; } void Date::setYear(int y) { year = y; } int const Date::getMonth() { return month; } int const Date::getDay() { return day; } int const Date::getYear() { return year; } void Date::showDate1() { if (check()) { cout

image text in transcribed

12/25/2012 August 16, 2012 16 August 2012 32 is not a valid value for the day. execution time : 0.105 S Process returned 1 (@x1) Press any key to continue

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 And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 2 Lncs 8056

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013th Edition

3642401724, 978-3642401725

More Books

Students also viewed these Databases questions

Question

x-3+1, x23 Let f(x) = -*+3, * Answered: 1 week ago

Answered: 1 week ago