Hello. I'm trying to make a C++ program practices with classes and OOP with dates, using three files: main.cpp, Date.cpp, and Date.h. I'm getting errors in main.pp for undefined references and in Date.cpp. there is alse an error for undefined reference Requirements Date.h will contain the class declaration. The following is required in the class declaration: The private attributes are the month, day, and year. The public member functions are PrintDate, SetDate, and NextDate The default constructor should initialize all data to the value 0. NextDate should still return a new Date object with the next day's information. This function needs to be completed (For this, just assume Feb has 29 days all the time even though it is not true.) Date.cpp will contain the implementation of all member functions and the constructor main.cpp* will need to be updated to use the member functions. Example: SetDate(today,2,13,2016); // today.month = 2; // today.day = 13; // today.year = 2016; PrintDate(today); // should print 2/13/16 tomorrow = NextDate(today); Becomes today.SetDate(2,13,2016); today.PrintDate(); tomorrow = today.NextDate(); Date.h #ifndef DATE__H /* To prevent multiple inclusion problems */ #define DATE__H class Date { private: int month; int day; int year; public: void SetDate(int mo, int da, int yr); void PrintDate(Date date); Date NextDate(Date date); }; #endif Required Output: DateExample by student name 2/13/16 2/14/16 2/14/16 1/1/00 3/1/00 2/29/00 3/1/17 2/29/16 0/0/00
Hello. I'm trying to make a C++ program practices with classes and OOP with dates, using three files: main.cpp, Date.cpp, and Date.h. I'm getting errors in main.pp for undefined references and in Date.cpp. there is alse an error for undefined reference
Requirements
-
Date.h will contain the class declaration. The following is required in the class declaration:
- The private attributes are the month, day, and year.
- The public member functions are PrintDate, SetDate, and NextDate
- The default constructor should initialize all data to the value 0.
- NextDate should still return a new Date object with the next day's information. This function needs to be completed (For this, just assume Feb has 29 days all the time even though it is not true.)
-
Date.cpp will contain the implementation of all member functions and the constructor
-
main.cpp* will need to be updated to use the member functions. Example:
-
SetDate(today,2,13,2016);
// today.month = 2;
// today.day = 13;
// today.year = 2016;PrintDate(today); // should print 2/13/16
tomorrow = NextDate(today);
-
Becomes
Date.h
#ifndef DATE__H /* To prevent multiple inclusion problems */
#define DATE__H
class Date
{
private:
int month;
int day;
int year;
public:
void SetDate(int mo, int da, int yr);
void PrintDate(Date date);
Date NextDate(Date date);
};
#endif
Required Output:
DateExample by student name
2/13/16
2/14/16
2/14/16
1/1/00
3/1/00
2/29/00
3/1/17
2/29/16
0/0/00
![1 #include <iomanip>
2 #include <iostream>
3
4 #include "Date.h"
3
0
7 ✓ void Date::SetDate(int mo, int da, int yr) {
8
9
10
11
12
13
14
15
10
17
18
19 Date Date::NextDate(Date date) {
20
21
22
23
24
25
20
27
28
29
30-
31
32
33
34 v
35
30
37
38
39
40
939959
41
42
43
44
45
40
47
48
}
month = mo;
day = da;
year = yr;
void Date::PrintDate(Date date) {
std::cout<<date.month <<"/" <<date.day <<"/" << std::setfill('0')
<<< std::setw(2) <<date.year 100 << std::setfill(' ')
<<< std::endl;
}
}
Date newDate;
int monthEnd;
newDate= date;
newDate.day++;
// ... replace with remaining code
if (newDate.month == 2){
monthEnd = 29;
}
else if(newDate.month == 4 || newDate.month == 6 || newDate.month == 9 || newDate.month == 11){
//April, June, September, and November
monthEnd = 30;
}
else{
}
monthEnd = 31;
//check
if (newDate.day> monthEnd){ //If there was a 30 versus a 31 in 30 day month, then it would go to the next day and month
newDate.day = 1;
newDate.month++;
if (newDate.month > 12){ //if the number of month is greater than december, move to the next month in the new year
newDate.month = 1;
newDate.year++;
}
}
return newDate;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3eb03a80-7cae-4d33-b228-e2e0361c370e%2Fe65a6624-f86f-4733-ae1a-7a3791579436%2Fz9ffi1q_processed.png&w=3840&q=75)
![3 #include <iostream>
#include <iomanip>
0
7
8 #include "Date.h"
9
10
11 int main()
12 {
13
14
15
10
17 //SetDate(today,2,13, 2010);
// today.month= 2;
// today.day = 13;
// today.year = 2010;
18
19
20
21
22
23
24
33
34
35
30
37
38
Date today, tomorrow, valentines day, no_date;
std::cout<<"DateExample by Rahma Seid\n";
23
20
27
28
29 today. SetDate(12, 31, 1999);
30 tomorrow.PrintDate( tomorrow);
31
32
today. SetDate(2, 13, 2010);
today.PrintDate(today);
tomorrow = today.NextDate(today);
45
40
47
48
49
50
31
52
// should print 2/13/10
tomorrow.PrintDate(tomorrow); // should print 2/14/10
valentines day = tomorrow;
today.PrintDate(valentines day); // should print 2/14/16
}
tomorrow = today. NextDate(today);
39 tomorrow.PrintDate( tomorrow);
40
today.SetDate(2, 28, 1900);
tomorrow.PrintDate( tomorrow); // should print 3/1/00
tomorrow = today.NextDate( today);
// should print 1/1/00
today.SetDate(2, 28, 2000);
tomorrow = today. NextDate(today);
41
today.SetDate(2, 28, 2017);
42 tomorrow = today. NextDate(today);
43 tomorrow.PrintDate( tomorrow);
today.SetDate(0, 0, 0000);
today.PrintDate(no_date);
// should print 2/29/00
return 0;
today.SetDate(2, 28, 2010);
tomorrow = today. NextDate(today);
tomorrow.PrintDate( tomorrow);
// should print 3/1/17
// should print 2/29/10
// should print 0/0/00](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3eb03a80-7cae-4d33-b228-e2e0361c370e%2Fe65a6624-f86f-4733-ae1a-7a3791579436%2Fhuawc0c_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 8 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)