Question
please help me the fix the C++ code. //-----------------code start--------------- #include #include #include #include using namespace std; /*definations of all data types and functions*/ class
please help me the fix the C++ code.
//-----------------code start---------------
#include
public: Date(); Date(unsigned m, unsigned d, unsigned y); Date(const string &mn, unsigned d, unsigned y); voidprintNumeric() const; voidprintAlpha() const;
private: bool isLeap(unsigned y) const; unsigneddaysPerMonth(unsigned m, unsigned y) const; string name(unsigned m) const; unsigned number(const string &mn) const; }; /*declarations of Date class */
Date::Date() { day = 1; month = 1; monthName = "January"; year = 2000; }
Date::Date (unsigned m, unsigned d, unsigned y) { bool invalid = false; //if invalid month input, change to closest month if (m 12) { m = 12; invalid = true; } if (d daysPerMonth(m, y)) { d = daysPerMonth(m,y); invalid = true; } day = d; month = m; monthName = name(m); year = y; if (invalid) { cout
Date::Date (const string &mName, unsigned d, unsigned y) { //will change to true if invalid day boolinvalidDay = false; //will change to true if invalid month boolinvalidMonth = false; if (mName == "January" || mName == "january") { month = number("January"); monthName = "January"; } else if (mName == "February" || mName == "february") { month = number("February"); monthName = "February"; } else if (mName == "March" || mName == "march") { month = number("March"); monthName = "March"; } else if (mName == "April" || mName == "april") { month = number("April"); monthName = "April"; } else if (mName == "May" || mName == "may") { month = number("May"); monthName = "May"; } else if (mName == "June" || mName == "june") { month = number("June"); monthName = "June"; } else if (mName == "July" || mName == "july") { month = number("July"); monthName = "July"; } else if (mName == "August" || mName == "august") { month = number("August"); monthName = "August"; } else if (mName == "September" || mName == "september") { month = number("September"); monthName = "September"; } else if (mName == "October" || mName == "october") { month = number("October"); monthName = "October"; } else if (mName == "November" || mName == "november") { month = number("November"); monthName = "November"; } else if (mName == "December" || mName == "december") { month = number("December"); monthName = "December"; } //If invalid month name, change date to 1/1/2000 else { day = 1; month = number("January"); monthName = "January"; year = 2000; invalidMonth = true; }
//ifmonthName is correct but day number is invalid, change to closest day if ((!invalidMonth) && (d > daysPerMonth(month, y))) { day = daysPerMonth(month,y); invalidDay = true; } //outputs message if input was invalid if (invalidDay || invalidMonth) { cout
else { day = d; year = y; } }
void Date::printNumeric () const { cout
void Date::printAlpha () const { cout
bool Date::isLeap(unsigned y) const { //implies leap year if (y % 4 == 0) { //does not imply leap year if (y % 100 == 0) { //unlessits a multiple of 400 if (y % 400 == 0) { return true; } return false; } return true; } return false; }
unsigned Date::daysPerMonth(unsigned m, unsigned y) const { if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { return 31; } else if (m == 4 || m == 6 || m == 9 || m == 11) { return 30; } else if (isLeap(y)) { return 29; } return 28; }
/* Returns the name of a given month - e.g.name(12) returns the string "December" */ string Date::name(unsigned m) const { if (m = 12) { return "December"; } if (m == 2) { return "February"; } else if (m == 3) { return "March"; } else if (m == 4) { return "April"; } else if (m == 5) { return "May"; } else if (m == 6) { return "June"; } else if (m == 7) { return "July"; } else if (m == 8) { return "August"; } else if (m == 9) { return "September"; } else if (m == 10) { return "October"; } else if (m == 11) { return "November"; } return "January"; } /* Returns the number of a given named month */ unsigned Date::number(const string &mName) const { if (mName == "January") { return 1; } else if (mName == "February") { return 2; } else if (mName == "March") { return 3; } else if (mName == "April") { return 4; } else if (mName == "May") { return 5; } else if (mName == "June") { return 6; } else if (mName == "July") { return 7; } else if (mName == "August") { return 8; } else if (mName == "September") { return 9; } else if (mName == "October") { return 10; } else if (mName == "November") { return 11; } else if (mName == "December") { return 12; } return 0; }
Date getDate();
int main() {
Date testDate; testDate = getDate(); cout
return 0; }
Date getDate() { int choice; unsigned monthNumber, day, year; stringmonthName;
cout > choice; cout
if (choice == 1) { cout > monthNumber; cout > day; cout > year; cout > monthName; cout > day; cout > year; cout main.cpp 23 unsigned daysPerMonth(unsigned m, unsigned y) const; 24 string nane(unsigned m) const; 25 unsigned number(const string 8mn) const; 26 1; 27 *declarations of Date class/ 28 29 Date: :Date() 38 31 day 1; 32 month 1; 33 monthName "January"; 34 year - 2080; 35 36 37 Date::Date (unsigned m, unsiened d, unsigned y) 38 39 bool invalid false; 40 41 //if invalid month input, change to closest month Only show failing tests (20 tests hidden) Download this submission 13: Compare output 0/3 Output differs. See highlights below. Special character legend Febr 14 2016 Input Which Date constructor? (Enter 1, 2, or 3) 1- Month Number 2 - Month Name 3 - default month name? day? year? Your output Invalid date values: Date corrected to 1/1/2000 Numeric: 1/1/2000 Alpha January 1, 2000 Which Date constructor? (Enter 1, 2, or 3) 1 - Month Number 2 - Month Name 3- default month name? day? year? Invalid month ame:the Date was set to 1/1/2000 Expected output Numeric: 1/1/2000 Alpha January 1, 2000 14: Compare output Output differs. See highlights below. Special character legend 2 Octbr 32 2015 Input Which Date constructor? (Enter 1, 2, or 3) 1 - Month Number 2 - Month Name 3 - default Your output month name? day? year? Invalid date values: Date corrected to 1/1/2000. Numeric: 1/1/2000 Alpha January 1, 2000 Which Date constructor? (Enter 1, 2, or 3) 1 - Month Number 2 - Month Name 3 - default month name? day? year? Invalid month ame: the Date was set to 1/1/2000 Expected output Numeric: 1/1/2000 Alpha January 1, 2000 15: Compare output 0/3 Output differs. See highlights below. Special character legend august Input 6427 Which Date constructor? (Enter 1, 2, or 3) 1 Month Number 2 - Month Name 3 - default Your output month name? day? year? Numeric: 8/0/6427 Alpha August , 6427 Which Date constructor? (Enter 1, 2, or 3) 1 Month Number 2 - Month Name 3 - default month name Expected output day? year? Invalid date values: Date corrected to 8/1/6427 Numeric: 8/1/6427 Alpha August 1, 6427 24: Unit testA 0/15 Test invalid dates Testing invalid month name... Error: Constructor did not output correct error when month n Testing printNumeric. .. Testing printAlpha.. Testing invalid month number.. . Testing printNumeric. . . Test feedback Testing printAlpha Testing invalid day (month is valid) . . . Testing printNumeric. . . Testing printAlpha.. Testing invalid day & month. . . Testing printNumeric. . . Testing printAlpha
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started