Question
Month Class
Design a class named Month. The class should have the following private members:

• Name: A string object that holds the name of a month, such as January, February, etc.
• monthNumber: An integer variable that holds the number of the month. For example, January would be 1, February would be 2, etc. Valid values for this variable are 1 through 12.

In addition, provide the following member functions:
1. A default constructor that sets monthNumber to 1 and name to January.
2. A constructor that accepts the name of the month as an argument. It should set name to the value passed as the argument and set monthNumber to the correct value.
3. A constructor that accepts the number of the month as an argument. It should set monthNumber to the value passed as the argument and set name to the correct month name.
4. Appropriate set and get functions for the name and monthNumber member variables.
5. Prefix and postfix overloaded ++ operator functions that increment monthNumber and set name to the name of next month. If monthNumber is set to 12 when these functions execute, they should set monthNumber to 1 and name to January.
6. Overload the = operator. It should set both the monthName and monthNumber variables.
7. Overload cout s << operator and cin s >> operator to work with the Month class. Demonstrate the class in a program.
o << cout s stream insertion operator. This operator should cause the date to be displayed in the form shown in the sample output below.
o >> cin s stream extraction operator. This operator should prompt the user for the name of a month. In the same operation, it should also set the monthName and monthNumber variables.

Requirements
1. You can assume the name of the month will be typed in with the first letter capitalized and all other letters lowercase.
2. The cin’s >> operator should read the month’s name (make sure you update the number).
3. Write the code for assigning to the month and monthNumber attributes in the set functions, and just call the appropriate set function from the constructors.
4. Use the main function below.

int main()
{
Month m1("February"); Month m2,m3, m4;

cout <<m1.getMonthName() << endl; cout <<m1.getMonthNumber()<< endl;

cout << endl; cout << m1;

cout << endl; m2 = ++m1;
cout << m1; cout << m2;

cout << endl; m3 = m1++;
cout << m1; cout << m3;

cout << endl;
cout << "Enter the name of a month: "; cin >> m4;

cout << m4;

system ("Pause") return 0;
}


Employees:
In this lab, you will assign dynamically allocated derived class objects to base class pointers and use polymorphism to display output based on the type of the object.
First, start by implementing the base class Employee.
This class will have:

- One private int attribute empID
- One public constructor that will take an int as an argument and assign it to empID
- A public function that will return the empID with the following prototype:
int getEmpID() const;
- A public pure virtual function with the following prototype:
virtual void printPay() =0;

Next, implement the derived class HourlyEmployee: public Employee. This class will have:
- One private double attribute hours
- One private double attribute payRate
- One public constructor that will take in three arguments: The employee id, the number of hours worked, and the pay rate. The constructor will pass the employee id argument to the base class constructor and assign the value of the other two arguments to its attributes.
- A public function that will return the hours with the following prototype:
double getHours() const;
- A public function that will return the payRate with the following prototype:
double getPayRate() const;
- An overridden public printPay function that will print the hourly empolyee’s id number and the weekly pay (i.e. hours * payRate) with 2 digits after the decimal place. The prototype is : void printPay();

Next, implement the derived class SalariedEmployee: public Employee.
This class will have:
- One private double attribute salary
- One public constructor that will take in two arguments: The employee id and the salary. The constructor will pass the employee id argument to the base class constructor and assign the value of the other arguments to its attribute.
- A public function that will return the salary with the following prototype:
double getSalary() const;

- An overridden public printPay function that will print the salaried empolyee’s id number and the weekly pay (i.e. salary/52) with 2 digits after the decimal place. The prototype is : void printPay();

You will also need to implement two stand-alone functions. The function

void getInput(vector <Employee *> & Ve);
will contain a loop that will give the user an option to enter information about an hourly employee or a salaried employee. Depending on the user’s choice, collect the appropriate input information from the user and use this information to dynamically construct a derived class object. Assign the address of the dynamically created derived class object to an element of the Ve vector. (Note: In this step, you are assigning the addresses of derived class objects to base class pointers).
The other function:

void printList(const vector <Employee *> & Ve);

will simply loop through the elements of the Ve vector and call the printPay() function of each of the dynamically allocated objects. (Note: In this step, you see the polymorphism in action. That is, depending on the type of the object there will be dynamic binding and the appropriate version of the printPay() function will execute).

Below is the code for the main function to be used in your program.

int main()
{
vector <Employee *> VEmp;

getInput(VEmp); printList(VEmp);
cout << "Lab 7 completed by: " << ??? << endl;

system("pause"); return 0;
}

Where “???” represents your first and last name and the employee ID of the first employee in the list. If there are no employees in the list, use your first and last name.
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

#include "Month.h"

/**
* A default constructor that sets monthNumber to 1 and name to January.
*/
Month::Month() {
    monthNumber = 1;
    month = "January";
}

/**
* A constructor that accepts the name of the month as an argument.
* It should set name to the value passed as the argument
* and set monthNumber to the correct value.
* @param name
*/

Month::Month(string month) {
    setMonth(month);
}

/**
* A constructor that accepts the number of the month as an argument.
* It should set monthNumber to the value passed as the argument
* and set name to the correct month name
* @param number
*/
Month::Month(int number) {
    setMonthNumber(number);
}

Month::Month(const Month& o) {
    month = o.month;
    monthNumber = o .monthNumber;
}

Month::~Month() {
}

int Month::getMonthNumber() const {
    return monthNumber;
}

string Month::getMonth() const {
    return month;
}

void Month::setMonthNumber(int number) {
    string n [] = {"January", "February", "March", "April",
       "May", "June", "July", "August", "September", "November", "December"};
    if (number < 1 || number > 12) {
       monthNumber = 1;
       month = n[0];
    } else {
       monthNumber = number;
       month = n[number - 1];
    }
}

void Month::setMonth(string month) {
    string n [] = {"January", "February", "March", "April",
       "May", "June", "July", "August", "September", "November", "December"};
    this->month = n[0];
    monthNumber = 1;
    for (int i = 0; i < 12; i++) {
       if (month == n[i]) {
            this->month = n[i];
            monthNumber = i + 1;
            break;
       }
    }
}

Month& Month::operator++() {
    monthNumber++;
    if (monthNumber > 12) {
       monthNumber = 1;
    }
    month = numberToName(monthNumber);
    return *this;
}

Month Month::operator++(int) {
    Month tmp = *this;
    ++ * this;
    return tmp;
}

Month& Month::operator--() {
    monthNumber--;
    if (monthNumber < 1) {
       monthNumber = 12;
    }
    month = numberToName(monthNumber);
    return *this;
}
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.zip
Purchase Solution
$24.00 $12
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 645 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,808+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,704+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,469+ sessions)
2 hours avg response

Similar Homework Solutions