Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6.12 C++ please #include #include using namespace std; int DateParser(string month) { int monthInt = 0; if (month == January) monthInt = 1; else if

6.12
C++ please
image text in transcribed

#include

#include

using namespace std;

int DateParser(string month) {

int monthInt = 0;

if (month == "January")

monthInt = 1;

else if (month == "February")

monthInt = 2;

else if (month == "March")

monthInt = 3;

else if (month == "April")

monthInt = 4;

else if (month == "May")

monthInt = 5;

else if (month == "June")

monthInt = 6;

else if (month == "July")

monthInt = 7;

else if (month == "August")

monthInt = 8;

else if (month == "September")

monthInt = 9;

else if (month == "October")

monthInt = 10;

else if (month == "November")

monthInt = 11;

else if (month == "December")

monthInt = 12;

return monthInt;

}

int main () {

while (std::getline(std::cin, date)) {

if (date == "-1") {

break;

}

std::string month = date.substr(0, date.find(" "));

int firstComma = date.find(",");

if (firstComma == std::string::npos) {

continue;

}

int day;

try {

day = std::stoi(date.substr(month.length() + 1, firstComma - month.length() - 1));

} catch (std::invalid_argument&) {

continue;

}

int year;

try {

year = std::stoi(date.substr(firstComma + 2));

} catch (std::invalid_argument&) {

continue;

}

if (months.count(month) == 0) {

continue;

}

std::cout

}

}

Complete main0 to read dates from input, one date per line. Each dates format must be as follows March 1. 1990. Any date not following thot format is incorrect and should be ignored. Use the substro function to parse the string and extract the date. The input ends with - 1 an: a line alone Output each correct date as:3-1-1990 Ex, if the input it: Mareh 1. 1990 Aptid 2 :1995 T/I5/20 Deeember 13, 2003 -1 then the cutput if 31159032122093 Uie the provided DateParaen 0 function to convert a month sting to an integor if the roonth sting is valid an intrge in the range to to 12 inclugive is returned otherwise ois returned Ex Dateparser " February") retums 2 and DateParuer( 7/15/20 )

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

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions

Question

Derive the recursive order-update equation given in (12.3.19)

Answered: 1 week ago