Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am doing very well on my tests but my teacher is bad at teaching hands on prog

ID: 3530134 • Letter: I

Question

I am doing very well on my tests but my teacher is bad at teaching hands on programming. Please help me out with my program please. I have written alot of it. Please help. Here is my questions and my program I have written... Please help me. 1) Move the code you currently have in the Display function into the class as a friend function. Change all of the references to your class members so that you directly reference the class private variables. So instead of using dHold.getMonth() you would now code it dHold.month 2) Overload the ++ operator. This function will now add 1 to the current year in the class. Overload the -- operator. This function will now subtract 1 from the current year in the class. Overload the == operator. This function will compare the years from two classes and return a boolean, true if they are equal and false if they are not. Overload the < operator. This function will compare the years from two classes and return a boolean, true if the first year is less than the second year and false if it is not. Overload the > operator. This function will compare the years from two classes and return a boolean, true if the first year is greater than the second year and false if it is not. 3) Create a private static member variable called MilitaryTime that is an integer data type. static int MilitaryTime; Create get and set member functions for this variable. On the set member function code the statement that will only allow the values of 12 and 24 to be valid. Tell the user if they have entered an invalid value. 4) Create 2 instances of the class in the main function (Same as the previous program) o The first instance will use the set member functions to populate the month, day and year. Example: D1.setMonth(12); o The second instance of the class will use the overloaded constructor to populate the month, day and year. Example: D2(5, 10, 2013) 5) Call the friend function Display to display the contents of the two classes Call the overloaded ++ operator for class 1 Call the overloaded -- operator for class 2 Call the friend function Display to display the contents of the two classes Write the code that will compare class 1 to class 2 using the overloaded comparison operators. Display on the screen the results of the comparison. #include "stdafx.h" #include #include #include using namespace std; class date { private: int month; int day; int year; public: date() { } date(int m, int d, int y); void setmonth(int m); void setday(int d); void setyear(int y); //bool leayear(); int getmonth() { return month; } int getday() { return day; } int getyear() { return year; } bool leapYear(); string getMonthName(); }; bool date::leapYear() { if ((year % 400 == 0 || year % 100 != 0) && (year % 4 == 0)) return true; else return false; } void date::setmonth(int m) { if (m > 12 || m < 1) cout << "Error"; else //m = 1; month = m; } void date::setday(int d) { if (d > 31 || d < 1) cout << "Error"; else //d = 1; day = d; } void date::setyear(int y) { if (y > 2013 || y < 1200) cout << "Error"; else //y = 1200; year = y; } date::date(int m, int d, int y) { month = m; day = d; year= y; //cout << month << "/" << day << "/" << year << endl; } string date::getMonthName() { switch (month) { case 1 : return "January"; break; case 2 : return "Febraury"; break; case 3 : return "March"; break; case 4 : return "April"; break; case 5 : return "May"; break; case 6 : return "June"; break; case 7 : return "July"; break; case 8 : return "August"; break; case 9 : return "September"; break; case 10 : return "October"; break; case 11 : return "November"; break; case 12 : return "December"; break; } } void Display(date &dHold) { cout << dHold.getmonth() << "/" << dHold.getday() << "/" << dHold.getyear() << endl; cout << dHold.getMonthName() << " " << dHold.getday() << ", " << dHold.getyear() << endl; cout << dHold.getday() << " " << dHold.getMonthName() << " " << dHold.getyear() << endl; cout << dHold.getyear(); if (dHold.leapYear()) cout << " is a leap year. "; else cout << " is not a leap year. "; } int main() { int month; int day; int year; cout << "Enter Month between 1 and 12" << endl; cin >> month; cout << "Enter day from 1 to 31)" << endl; cin >> day; cout << "Enter Year)"<< endl; cin >> year; date newDate(month, day, year); Display(newDate); date D2; D2.setday(15); D2.setmonth(6); D2.setyear(2000); Display (D2); //cout << monthName[month-1] << " " << newDate.getday() << ", " << newDate.getyear() << endl; //cout << newDate.getday() << " " << monthName[month-1] << " " << newDate.getyear() << endl; //cout << newDate.leapYear(); system ("PAUSE"); return 0; }

Explanation / Answer

#include using namespace std; //Must be known to TWO //before declaration of ONE. class ONE; class TWO { public: void print(ONE& x); }; class ONE { int a, b; friend void TWO::print(ONE& x); public: ONE() : a(1), b(2) { } }; void TWO::print(ONE& x) { cout