Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ DateType program. So I have this project where I need to do a bunch of instructions which I think I got them all done

C++ DateType program. So I have this project where I need to do a bunch of instructions which I think I got them all done except I do not know how to do the last one which is making it look like a calendar. I will post what it whats me to do below my code that I have so far. Any help on being able to make it look like a calendar would be very much appreciated. This could take a while to run but it works right. Thanks!!

Here is my code (I cleaned it up the best I could):

// Create the class

//Define the class dateType.

class dateType

{

ifstream infile;

public:

//Declare the required variables under the private access specifier.

private:

//Declare an integer variable to store the month.

int dMonth;

//Declare an integer variable to store the day.

int dDay;

//Declare an integer variable to store the year.

int dYear;

//Declare an integer variable to store the number of days in a month.

int noDays;

//Declare an integer variable to store the number of days passed in a year.

int Passeddays;

//Declare the required member functions under the public access specifier.

public:

//Define the function setMonth to set the month of the date.

int setMonth(int month);

//Define the function setDay to set the day of the date.

void setDay(int day);

//Define the function setYear to set the year of the date.

void setYear(int year);

//Define the function getDay to get the day of the date.

int getDay() const;

//Define the function getMonth to get the month of the date.

int getMonth() const;

//Define the function getYear to get the year of the date.

int getYear() const;

//Declare the function printDate to print the date.

void printDate() const;

//Declare the function isLeapYear to check whether a year is leap year or not.

bool isLeapYear(int year);

//Declare the function totalNumOfpassedDays to get the number of days passed in a year.

int totalNumOfpassedDays(int, int);

//Declare the function RemainingDays to find the number of remaining days in a year.

int RemainingDays(int);

//Declare the function NewDate to calculate the new date.

int NewDate(int, int, int, int);

//Declare the constructor of the class.

dateType(int month = 0, int day = 0, int year = 0);

};

//Define the function totalNumOfpassedDays to find the number of days passed in a year.

int dateType::totalNumOfpassedDays(int month, int day)

{

//Declare an integer variable to calculate the passed days in a year.

int i, passedDays = 0;

//Start the for loop from 1 to 12.

for (i = 1; i <= 12; i++)

{

//Check if the value of i is equal to the value of the month.

if (i == month)

{

//Exit from the loop.

break;

}

//Else part.

else

//Calculate the number of days passed in a year.

passedDays += setMonth(i);

}

//Add the days of the current month.

passedDays += day;

//Store the value of the passedDays into the variable

//Passeddays.

Passeddays = passedDays;

//Return the value of the variable passeddays.

return passedDays;

}

//Define the function NewDate to calculate the new date.

int dateType::NewDate(int month, int day, int year, int adddays)

{

//Check whether the value of the total days%month is

//equal to 0 or not.

if ((day + adddays) % month)

{

//Add the number of days to be added in the date to the day of the previous date.

dDay = day + adddays;

//Check if the total number of days is greater than 31.

if (dDay > 31)

{

//Find the absolute value of the days.

dDay = abs(dDay - 31);

//Increase the month if the number of days is greater than 31.

month++;

}

//Store the final value of the month into the variable dMonth.

dMonth = month;

//Check if the value of the variable month is greater than 12.

if (month > 12)

{

//Assign 1 to the variable dMonth.

dMonth = 1;

//Increase the value of the variable dYear.

dYear++;

}

}

//Return an integer value to the function.

return 0;

}

//Define the function to find the remaining days in a year.

int dateType::RemainingDays(int year)

{

//Declare an integer variable to store the number of days remaining in a year.

int remainingDays;

//Check whether the returned value of the function isLeapYear is not equal to the false.

if (isLeapYear(year))

{

//Calculate the remaining days in a leap year.

remainingDays = 366 - Passeddays;

}

//Else part.

else

//Calculate the remaining days in a year.

remainingDays = 365 - Passeddays;

//Return the total number of the days remaining in a year.

return remainingDays;

}

//Define the function to set the month of the date.

int dateType::setMonth(int month)

{

//Declare an integer variable to store the year of the date.

int year1;

//Assign the value of the variable dYear to the variable year1.

year1 = dYear;

//Check if the value of the variable month is less than 12.

if (month <= 12)

{

//Assign the value of the variable month to the varaible dMonth.

dMonth = month;

//Switch expression.

switch (month)

{

//Assign 31 to the variable noDays for the case 1, 3, 5, 7, 8, 10, and 12.

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12: noDays = 31;

break;

//Assign 30 to the variable noDays for the case 4, 6, 9, 11.

case 4:

case 6:

case 9:

case 11:noDays = 30;

break;

//Check whether the year is a leap year or not for case 2.

case 2:if (isLeapYear(year1))

{

//Assign 29 to the variable noDays.

noDays = 29;

}

//Else part.

else

{

//Assign 28 to the variable noDays.

noDays = 28;

}

}

}

//Else part.

else

{

//Display the message that the given month is an

//invalid month.

cout << "Invalid Month" << endl;

//Set the value of the variable dMonth to 0.

dMonth = 0;

}

//Return the value of the variable noDays.

return noDays;

}

//Define the function setDay to set the day of the date.

void dateType::setDay(int day)

{

//Check whether the day is less than the total number of days in the given month.

if (day <= noDays)

{

//Assign the value of the variable day to the //dDay.

dDay = day;

}

//Else part.

else

{

//Display the message that the given day is an

//invalid day.

cout << "Invalid Day" << endl;

//Set the value of the variable dDay to 0.

dDay = 0;

}

}

//Define the function setYear.

void dateType::setYear(int year)

{

//Set the value of the variable dYear.

dYear = year;

}

//Define the function isLeapYear.

bool dateType::isLeapYear(int year)

{

//Check whether the given year is a leap year or not.

if (((year % 4 == 0) && (year % 100 == 0)) || (year % 400 == 0))

{

//Return true if the condition is true.

return true;

}

//Else part.

else

{

//Return false if the condition is false.

return false;

}

}

//Define the function printDate.

void dateType::printDate()const

{

//Display the date.

cout << dMonth << "-" << dDay << "-" << dYear << endl;

}

//Define the function getDay to get the day of the date.

int dateType::getDay() const

{

//Return the day of the date.

return dDay;

}

//Define the function getMonth to get the month of the date.

int dateType::getMonth() const

{

//Return the month of the date.

return dMonth;

}

//Define the function getYear to get the year of the date.

int dateType::getYear() const

{

//Return the year of the date.

return dYear;

}

//Define the constructor of the class with the required parameters.

dateType::dateType(int month, int day, int year)

{

//Initialize the day, month, year of the given date.

dMonth = month;

dDay = day;

dYear = year;

}

//Start the main() function.

int main()

{

//Declare the required variables.

int m, d, y, numDays, passed, remain;

//Create an object of the class and initialize it using constructor of the class.

dateType date(0, 0, 0);

//Display the message to input the month of the date.

cout << "Enter Month as a number:";

//Prompt the user to input the month of the date.

cin >> m;

//Display the message to input the day of the date.

cout << "Enter Day:";

//Prompt the user to input the day of the date.

cin >> d;

//Display the message to input the year of the date.

cout << "Enter Year:";

//Prompt the user to input the year of the date.

cin >> y;

//Call the setYear function to set the year.

date.setYear(y);

//Declare a boolean variable check to check whether

//the year is a leap year or not.

bool check = date.isLeapYear(y);

//If the value of the variable check is not equal to false.

if (check)

//Display the message that the given year is a //leap year.

cout << "This year is a leap year." << endl;

//Else part.

else

//Display the message that the given year is not //a leap year.

cout << "This year is not a leap year." << endl;

//Call the setMonth function to set the month of the

//date and to find the number of days in the current

//month.

numDays = date.setMonth(m);

//Display the number of days in the current month.

cout << "Number of days in the month is: " << numDays

<< endl;

//Call the totalNumOfpassedDays function to calculate

//the number of the days passed in the current year.

passed = date.totalNumOfpassedDays(m, d);

//Display the number of the days passed in the current

//year.

cout << "Total number of days passed are: " << passed

<< endl;

//Call the RemainingDays function to find the number //of days remaining in the year.

remain = date.RemainingDays(y);

//Display the number of the days remaining in the //current year.

cout << "Total number of remaining days are: "

<< remain << endl;

//Call the NewDate function to calculate the new date.

date.NewDate(3, 18, 2017, 25);

//Display the new date by calling the printDate //function.

cout << "The new date is: ";

date.printDate();

//Use this system call to hold the console screen.

system("pause");

//Return an integer value to the main() function.

return 0;

}

Here is my output:

Enter Month as a number:2 Enter Day:7 Enter Year:2018 This year is not a leap year. Number of days in the month is: 28 Total number of days passed are: 38 Total number of remaining days are: 327 The new date is: 4-12-2018

Here are my instructions (number 8 is the only one I think I have left to do and m Isleapyear might not be working either):

1. In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables.

2. Add a member function, isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class.

3. The class dateType was designed and implemented to keep track of a date, but it has very limited operations. Redefine the class dateType so that it can perform the following operations on a date, in addition to the operations already defined:

a. Set the month.

b. Set the day.

c. Set the year.

d. Return the month.

e. Return the day.

f. Return the year.

g. Test whether the year is a leap year.

h. Return the number of days in the month. For example, if the date is 3-12-2017, the number of days to be returned is 31 because there are 31 days in March.

i. Return the number of days passed in the year. For example, if the date is 3-18-2017, the number of days passed in the year is 77. Note that the number of days returned also includes the current day.

j. Return the number of days remaining in the year. For example, if the date is 3-18-2017, the number of days remaining in the year is 288.

k. Calculate the new date by adding a fixed number of days to the date. For example, if the date is 3-18-2017 and the days to be added are 25, the new date is 4-12-2017.

4. Write the definitions of the functions to implement the operations defined for the latest version of the class dateType.

5. The class dateType prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2017.

a. Derive the class extDateType so that the date can be printed in either form.

b. Add a member variable to the class extDateType so that the month can also be stored in string form.

c. Add a member function to output the month in the string format, followed by the yearfor example, in the form March 2017.

d. Write the definitions of the functions to implement the operations for the class extDateType.

e. Using the classes extDateType and dayType, design the class calendarType so that, given the month and the year, we can print the calendar for that month. To print a monthly calendar, you must know the first day of the month and the number of days in that month. Thus, you must store the first day of the month, which is the form dayType, and the month and the year of the calendar. Clearly, the month and the year can be stored in an object of the form extDateType by setting the day component of the date to 1 and the month and year as specified by the user. Thus, the class calendarType has two member variables: an object of the type dayType and an object of the type extDateType.

f. Design the class calendarType so that the program can print a calendar for any month starting January 1, 1500. Note that the day of January 1 of the year 1500 is a Monday. To calculate the first day of a month, you can add the appropriate days to Monday of January 1, 1500.

6. For the class calendarType, include the following operations:

a. Determine the first day of the month for which the calendar will be printed. Call this operation firstDayOfMonth.

b. Set the month.

c. Set the year.

d. Return the month.

e. Return the year.

f. Print the calendar for the particular month.

g. Add the appropriate constructors to initialize the member variables.

7. Write the definitions of the member functions of the class to implement the operations of the class calendarType.

8. Write a test program to print the calendar for either a particular month or a particular year. For example, the calendar for September 2017 is: September 2017

Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Thanks (again) for any advice you can give me on how to finish this.

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_2

Step: 3

blur-text-image_3

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

Explore the nature and importance of diversity management;

Answered: 1 week ago

Question

RP-1 How did the humanistic theories provide a fresh perspective?

Answered: 1 week ago

Question

Describe the job youd like to be doing five years from now.

Answered: 1 week ago

Question

So what disadvantages have you witnessed? (specific)

Answered: 1 week ago