Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ ONLY File Exceptions containts class Date with exceptions and a driver. Run the driver with the following data and describe what happens. //****************************************** //

C++ ONLY File Exceptions containts class Date with exceptions and a driver. Run the driver with the following data and describe what happens. //****************************************** // Test driver for class Date, which // is the Date class with exception handling //****************************************** #include #include "Date.h" using namespace std; int main() { int month; int day; int year; cout << "Enter month. Negative month stops test." << endl; cin >> month; while (month >= 0) { cout << "Enter day and year" << endl; cin >> day >> year; try { Date date1(month, day, year); cout << "Valid date." << endl; } catch (MonthError error) { cout << "Attempt to create date with invalid month." << endl; } catch (DayError error) { cout << "Attempt to create date with invalid day." << endl; } catch (YearError error) { cout << "Attempt to create date with invalid year." << endl; } cout << "Enter month. Negative month stops test." << endl; cin >> month; } return 0; }

//**************************************** // IMPLEMENTATION File for a Date ADT // Month, day, and year are kept as integers //****************************************

#include #include "Date.h"

bool IsLeapYear(int year); using namespace std; Date::Date() { month = 1; day = 1; year = 1582; }

//****************************************

Date::Date(int initMonth, int initDay, int initYear) { static int daysInMonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (initMonth <= 0 || initMonth > 12) throw MonthError(); else month = initMonth; if (!(initDay > 0 && day <= daysInMonth[initMonth-1])) throw DayError(); else if (month == 2 && day == 29 && !IsLeapYear(initYear)) throw DayError(); else day = initDay; if (initYear < 1582) throw YearError(); else year = initYear; }

//*****************************************

int Date::GetMonth() const { return month; }

//*****************************************

int Date::GetDay() const { return day; }

//****************************************

int Date::GetYear() const { return year; }

//****************************************

bool Date::operator<(const Date& otherDate) const { if (year < otherDate.year) return true; else if (year > otherDate.year) return false; else if (month < otherDate.month) return true; else if (month > otherDate.month) return false; else if (day < otherDate.day) return true; else return false; }

//*****************************************

bool Date::operator>(const Date& otherDate) const { return otherDate < *this; }

//*****************************************

bool Date::operator==(const Date& otherDate) const { return (month==otherDate.month) && (day==otherDate.day) && (year==otherDate.year); }

//********************************************************** bool IsLeapYear(int year) // IsLeapYear returns true if year is a leap year and // false otherwise. { if (year % 4 != 0) // Is year not divisible by 4? return false; // If so, can't be a leap year // Must be divisible by 4 at this point if (year % 100 != 0) // Is year not a multiple of 100? return true; // If so, is a leap year // Must be divisible by 100 at this point if (year % 400 != 0) // Is year not a multiple of 400? return false; // If so, then is not a leap year // Must be divisible by 400 at this point return true; // Is a leap year }

Input Data Restults
2 29 2009
3 30 2010
2 2 2007
6 31 2012

Clearly there is something wrong can you find the errors? correct the code and re-run the program with the data

Input data Results
2 29 2009
3 30 2010
2 2 2007
6 31 2012

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 Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

What is the difference between fundamental risk and price risk?

Answered: 1 week ago

Question

=+ If strikes occur, are they legally regulated?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago