C++ Find the errors in the code for Date Class and Source.cpp program and fix them.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.2: Providing Class Conversion Capabilities
Problem 6E
icon
Related questions
Question

C++

Find the errors in the code for Date Class and Source.cpp program and fix them.

source.cpp

include <iostream>
#include "Date.h" // include definition of class Date from Date.h using namespace std;

// function main begins program execution
int main()
{
Date date(); // create a Date object for May 6, 1981

// display the values of the three Date data members
cout << "Month: " << date.getMonth() << endl;
cout « "Day: " << date.getDay() << endl;
cout << "Year: " << date.getYear(2017) << endl;

cout << "\nOriginal date:" << endl;
date = displayDate(); // output the Date
// modify the Date
setMonth(13);
setDay(1);
setYear(2005);

cout "\nNew date:" << endl;
date.displayDate(); // output the modified date
} // end main

Date.h


// class Data definition
#include <iostream>
using namespace std;

//Data constructor that initializes the three data members;
class Date
{
public
date(m, d, y)
{
setMonth();
setDay();
setYear();
};
// set month
void setMonth()
{
month = m;

if (month < 1)
month = 1;

if (month > 12)
month == 1;
} // end function setMonth
int getMonth()
{
return month;
} // end function getMonth

// set day
int setDay(int d)
{
d = day;
} // end function setDay

// return day
void getDay()
{
return day;
} // end function getDay

// set year
void setYear(int y)
{
year = y;
} // end function setYear

// return year
int getYear{};
{
year;
// end function getYear

// print Date in the format mm/dd/yyyy
void displayDate(int, int, int) {
cout << month << '/' << day << '/' << year << endl;
} // end function displayDate
Private;
int month; // the month of the date
int day; // the day of the date
int year; // the year of the date

}; // end class Date

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Data members
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr