Create the class diagrams psuedocode for all 5 parts a Creat

Create the class diagrams psuedocode for all 5 parts:

a.

Create a class named Year that contains data fields to hold the number of months in a year and the number of days in a year. Include a constructor that sets the number of months to 12 and the number of days to 365, and get and set methods for each field.

b.

Create a subclass named LeapYear. LeapYear’s constructor overrides Year’s constructor and sets the number of days to 366.

c.

Design an application that instantiates one object of each class and displays all the data.

d.

Add a method named daysElapsed() to the Year class. The daysElapsed() method accepts two arguments representing a month and a day; the method returns a value indicating the number of days that have elapsed since January 1 of that year. For example, on March 3, 61 days have elapsed (31 in January, 28 in February, and 2 in March). Create a daysElapsed() method for the LeapYear class that overrides the method in the Year class. For example, on March 3 in a LeapYear, 62 days have elapsed (31 in January, 29 in February, and 2 in March).

e.

Design an application that prompts the user for a month and day and then calculates the days elapsed in a Year and a LeapYear.

Solution

#include<iostream>
using namespace std;
class Year
{
        public:
        int months, days;
        Year(){

                months = 12;
                days   = 365;

                set(months, days);
        }
        void set(int months, int days)
        {
                int m, d;
                 m = months;
                 d = days;
                get(m, d);
        }

        void get(int months , int days)
        {
                cout<<months<<\" \"<<days<<\"\ \";

        }
        int daysElapsed(int month, int day)
        {
                int elapseddays = 0;
                int i, monthdays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
                for(i=0; i<month-1; i++)
                        elapseddays = elapseddays + monthdays[i];
                if(days == 365)
                        elapseddays = elapseddays + day-1;
                else if(days == 366)
                        elapseddays = elapseddays + day;

                return elapseddays;
        }
};
class LeapYear : public Year
{
        public:
        LeapYear()
        {
                months = 12;
                days = 366;
                set(months, days);
        }
};

int main()
{
        Year Y;
        LeapYear LY;
        int month, day;
        cout<<\"Enter month : \"; cin>>month;
        cout<<\"Enter day   : \"; cin>>day;

        cout<<\"year elapsed day      : \"<<Y.daysElapsed(month, day)<<\"\ \";
        cout<<\"Leap year elapsed day : \"<<LY.daysElapsed(month, day)<<\"\ \";
}
          

Create the class diagrams psuedocode for all 5 parts: a. Create a class named Year that contains data fields to hold the number of months in a year and the numb
Create the class diagrams psuedocode for all 5 parts: a. Create a class named Year that contains data fields to hold the number of months in a year and the numb

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site