Question

2. Define a class named “Holiday” that manages one holiday info such as month (integer), day...

2. Define a class named “Holiday” that manages one holiday info such as month (integer), day (integer) and name (string). For example, 7, 4 and “Independence Day” • “toString” method to return holiday info as a string in the format: holiday name (month/day). For example, “Independence Day (7/4)” • “isLater” method that compares with another Holiday object and return true if the date of the holiday is later (month and day) and false otherwise. • “getMonth” method to return the month of the holiday • “getDay” method to return the day of the holiday Write a C++ program to show how to create multiple Holiday objects, comparing them using the isLater method, and printing out these objects.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

eturn Tdlse } return (other.day day); 28 clang version 7.0.0-3~ubuntu0.18.04.1 (tags/ : clang++-7 -pthread -o main main.cpp :

#include <iostream>

using namespace std;

class Holiday {
        private:
        int day, month;
        string name;

        public:
        Holiday(int d, int m, string n) {
                day = d;
                month = m;
                name = n;
        }
        
        string toString() {
                return name + " (" + to_string(day)
                        + "/" + to_string(month) + ")";
        }

        bool isLater(Holiday other) {
                if(other.month < month) {
                        return true;
                }
                if(other.month > month) {
                        return false;
                }
                return (other.day < day);
        }

        int getDay() {
                return day;
        }
        int getMonth() {
                return month;
        }
};

int main() {
        Holiday indDay(7, 4, "Independence Day");
        Holiday christ(12, 25, "Christmas");

        cout << indDay.toString() << endl;

        cout << christ.isLater(indDay) << endl;
}


Please upvote, as i have given the exact answer as asked in question. Still in case of any issues in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
2. Define a class named “Holiday” that manages one holiday info such as month (integer), day...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Will upvote C++ 1. (7 points) Define a class named “IntegerVariable” that manages a variable name...

    Will upvote C++ 1. (7 points) Define a class named “IntegerVariable” that manages a variable name (string) and an integer value. The data members must be declared as "private." The class must provide at least the following methods: a. "isSame VariableName" that compares with another Integer Variable object. It returns true if they both have the same variable name, and false otherwise. b. "toString" method to return string representing the variable information (name and value) c. "getValue” to return its...

  • The Java class called Holiday is started below. An object of class Holiday represents a holiday...

    The Java class called Holiday is started below. An object of class Holiday represents a holiday during the year. This class has three instance variables: name, which is a String representing the name of the holiday day, which is an int representing the day of the month of the holiday month, which is a String representing the month the holiday is in public class Holiday { private String name; private int day; private String month; // your code goes here...

  • java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the...

    java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date {    private String month;    private String day;    private String year;    public Date(String month, String day, String year) {       this.month = month;       this.day = day;       this.year = year;    }    public String getMonth() {       return month;    }    public String getDay() {       return day;    }    public String...

  • public class Date { private int month; private int day; private int year; /** default constructor...

    public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...

  • Assuming that a year has 365 days, write a class named DayOfYear that takes an integer...

    Assuming that a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example, Day 2 would be January 2. Day 32 would be February 1. Day 365 would be December 31. The constructor for the class should take as parameter an integer representing the day of the year, and the class should have...

  • Define a class Horse with two attributes, a string name and an integer numLegs. Write a...

    Define a class Horse with two attributes, a string name and an integer numLegs. Write a two parameter constructor and   a toString() method. *Write a class named Coll3 with a static method   "updateName". There are three parameters to the method: a   collection, an old name, and a new name. For every horse in the collection, if it has the same name as the parameter oldname, then   replace the horse's name with the parameter new name.   example: updateName({[X,4],[G,4],[X,3]}, X, Y) changes...

  • in java Define a class named ComparableNames thats extends Person and implements comparable Define a class...

    in java Define a class named ComparableNames thats extends Person and implements comparable Define a class named ComparableNames that extends Person (defined below) and implements Comparable. Override the compare To method to compare the person on the basis of name. Write a test class to find the order of two ComparableNames. class Person String name; Person00 Person(String n) name=n: Hint: in class ComparableName, you only need a constructor with arg to initialize the data filed defined in the super class...

  • Write a class named Month. The class should have an int field named monthNumber that holds...

    Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...

  • Write a class called Date that represents a date consisting of a year, month, and day....

    Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods: public Date(int year, int month, int day) Constructs a new Date object to represent the given date. public void addDays(int days) Moves this Date object forward in time by the given number of days. public void addWeeks(int weeks) Moves this Date object forward in time by the given number of seven-day weeks. public int daysTo( Date...

  • C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named month...

    C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT