Hi I need help please its simple I want to overload the << operator to display the date in a Date object in full name.  For example: 05/20/1999 should display as May 20, 1999 The display shall not update the Date object. I also dont know why the function wont accept 08 and 09 as values of month.  my Date.h file contains:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hi I need help please its simple I want to overload the << operator to display the date in a Date object in full name. 

For example: 05/20/1999 should display as May 20, 1999

The display shall not update the Date object.

I also dont know why the function wont accept 08 and 09 as values of month. 

my Date.h file contains:

 

C+ Date.cpp X +
1 #include <iostream>
2 #include <string>
3 #include "Date.h"
4 using namespace std;
5
6 Date::Date() {
7
8
9▼ Date::Date(const string& s) {
10
this->month = stoi(s.substr(0, 2));
11 this->day_ = stoi(s.substr(3, 2));
12 this->year_= stoi(s.substr(6));
13
14 ▼
15 ▼
16
17
18
19
20
21
22 ▼
23
24
25
26
27 ▼
28
22 23 2
29 ▼
30
31 ▼
32
33 ▼
34
35 ▼
36
37 ▼
38
39 ▼
40
}
41 ▼
42
43 ▼
44
45 ▼
46
47 ▼
48
}
bool operator<(Date& date1, Date& date2) {
if (date1 < date2) {
return true;
}
else
}
return false;
ostream& operator<<(ostream& output, const Date& d) {
unsigned int month = d.month_;
unsigned int day
d.day_;
unsigned int year = d.year__;
string monthoutput;
if (month=01) {
=
monthoutput = "January ";
} else if (month==02) {
monthoutput = "February ";
} else if (month==03) {
monthoutput = "March ";
} else if (month==04) {
monthoutput = "April";
} else if (month==05) {
monthoutput = "May";
} else if (month==06) {
monthoutput = "June ";
} else if (month==07) {
monthoutput = "July ";
} else if (month==08) {
monthoutput = "August";
} else if (month==09) {
monthoutput = "September ";
} else if (month==10) {
monthoutput = "October ";
} else if (month==11) {
monthoutput = "November ";
} else if (month==12) {
49 ▼
50
monthoutput = "December ";
51
} else monthoutput = "Month ";
52 output << monthoutput << day << ",
53
}
<< year;
⠀
> Console x
Shell x +
sh -c make -s
./Date.cpp:42:22: error: invalid digit '8' in octal constant
} else if (month==08) {
./Date.cpp:44:22: error: invalid digit '9' in octal constant
} else if (month==09) {
2 errors generated.
./main.cpp:12:6: error: redefinition of 'entered_date' with a different type: 'Date' vs 'std::string
' (aka 'basic_string<char>')
Date(entered_date);
./main.cpp:9:8: note: previous definition is here
string entered_date;
1 error generated.
make: *** [Makefile:9: main] Error 1
exit status 2
:
0
Transcribed Image Text:C+ Date.cpp X + 1 #include <iostream> 2 #include <string> 3 #include "Date.h" 4 using namespace std; 5 6 Date::Date() { 7 8 9▼ Date::Date(const string& s) { 10 this->month = stoi(s.substr(0, 2)); 11 this->day_ = stoi(s.substr(3, 2)); 12 this->year_= stoi(s.substr(6)); 13 14 ▼ 15 ▼ 16 17 18 19 20 21 22 ▼ 23 24 25 26 27 ▼ 28 22 23 2 29 ▼ 30 31 ▼ 32 33 ▼ 34 35 ▼ 36 37 ▼ 38 39 ▼ 40 } 41 ▼ 42 43 ▼ 44 45 ▼ 46 47 ▼ 48 } bool operator<(Date& date1, Date& date2) { if (date1 < date2) { return true; } else } return false; ostream& operator<<(ostream& output, const Date& d) { unsigned int month = d.month_; unsigned int day d.day_; unsigned int year = d.year__; string monthoutput; if (month=01) { = monthoutput = "January "; } else if (month==02) { monthoutput = "February "; } else if (month==03) { monthoutput = "March "; } else if (month==04) { monthoutput = "April"; } else if (month==05) { monthoutput = "May"; } else if (month==06) { monthoutput = "June "; } else if (month==07) { monthoutput = "July "; } else if (month==08) { monthoutput = "August"; } else if (month==09) { monthoutput = "September "; } else if (month==10) { monthoutput = "October "; } else if (month==11) { monthoutput = "November "; } else if (month==12) { 49 ▼ 50 monthoutput = "December "; 51 } else monthoutput = "Month "; 52 output << monthoutput << day << ", 53 } << year; ⠀ > Console x Shell x + sh -c make -s ./Date.cpp:42:22: error: invalid digit '8' in octal constant } else if (month==08) { ./Date.cpp:44:22: error: invalid digit '9' in octal constant } else if (month==09) { 2 errors generated. ./main.cpp:12:6: error: redefinition of 'entered_date' with a different type: 'Date' vs 'std::string ' (aka 'basic_string<char>') Date(entered_date); ./main.cpp:9:8: note: previous definition is here string entered_date; 1 error generated. make: *** [Makefile:9: main] Error 1 exit status 2 : 0
C+ main.cpp x +
> f main
1 #include <iostream>
2 #include <string>
3 using namespace std;
4 #include "Date.h"
5
6
7
8
9
string entered_date;
10 cout <<" Please enter a date in 01/11/1999 format:\t";
11 cin >> entered_date;
12 Date(entered_date);
13 }
int main() {
std::cout << "Hello World!\n";
Transcribed Image Text:C+ main.cpp x + > f main 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 #include "Date.h" 5 6 7 8 9 string entered_date; 10 cout <<" Please enter a date in 01/11/1999 format:\t"; 11 cin >> entered_date; 12 Date(entered_date); 13 } int main() { std::cout << "Hello World!\n";
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education