Question

In: Computer Science

C++ program: Create a Date class that contains three members: the month, the day of the...

C++ program:

Create a Date class that contains three members: the month, the day of the month, and the year, all of type int. The user should enter a date in the format 12/31/2001, store it in an object of type Date, then retrieve the object and print it out in the same format.

Next create an employee class. The member data should comprise an employee number (type int) and the employee’s compensation (in dollars; type float). Extend the employee class to also include a Date class and an enumerator, etype, to hold the employee’s type. The enumerated values are:{laborer, secretary, manager, accountant, executive, researcher }.

The Date field should be used to hold the date when the employee was hired. The etype variable should hold the employee type. These two items will be private member data in the employee definition, just like the employee number and salary. Member functions should allow the user to enter this data and display it.The program should ask the user to fill in the employees’ data for three employees, store it in an array of three objects of type Employee, and then display the information for each employee.

The program should allow the user to specify employee type by entering its first letter (‘l’, ‘s’, ‘m’, and so on) and then storing the type chosen as a value of a variable of type etype.

You will write an object oriented program to implement this. It is assumed that you will use good programming practices you have learnt in the course to write safe, reliable, and well tested programs.

Solutions

Expert Solution

SOLUTION-
I have solve the problem in C++ code with comments and screenshot for easy understanding :)

CODE-

//c++ code

#include<bits/stdc++.h>
using namespace std;

//class date
class Date {
public:
        int month, day, year;
        //constructor
        void set(int m, int d, int y) {   
                month = m;
                day = d;
                year = y;
        }
};


enum etype {
        laborer, secretary, manager, accountant,
        executive, researcher
};

class Employee {
// private:
        //data members
        int Employee_number;
        float compensation;
        Date D = Date();
        etype E;

public:
        //constructors
        Employee() {}

        Employee(int Emp, double com, int month, int day, int year, char c) {

                if (c == 'l') {
                        E = laborer;
                } else if (c == 's') {
                        E = secretary;
                } else if (c == 'm') {
                        E = manager;
                } else if (c == 'a') {
                        E = accountant;
                } else if (c == 'e') {
                        E = executive;
                } else {
                        E = researcher;
                }

                Employee_number = Emp;
                compensation = com;
                D.set(month, day, year);
        }

        void display() {
                cout << "Employee Number: " << Employee_number << endl;
                cout << "Employee Compensation: " << compensation << endl;
                cout << "Date of hiring: " << D.month << "/" << D.day << "/" << D.year << endl;
                cout << "Employee type: ";
                if (E == laborer) {
                        cout << "laborer";
                } else if (E == secretary) {
                        cout << "secretary";
                } else if (E == manager) {
                        cout << "manager";
                } else if (E == accountant) {
                        cout << "accountant";
                } else if (E == executive) {
                        cout << "executive";
                } else if (E == researcher) {
                        cout << "researcher";
                }
                cout << endl;
        }

};

int main()
{

        Employee arr[3] ;

        for (int i = 0; i < 3; ++i) {
                cout << "Employee " << i + 1 << " : \n";
                int n;
                double c;
                int month, day, year;
                char e;
                cout << "Enter employee number: ";
                cin >> n;
                cout << "Enter employee compensation: ";
                cin >> c;
                cout << "Enter date of hiring of employee: ";
                scanf("%2d/%2d/%4d", &month, &day, &year);
                cout << "Enter first letter of employee type: ";
                cin >> e;
                arr[i] = Employee(n, c, month, day, year, e);
                cout << endl;

        }

        cout << "Employee Details:\n";

        for (int i = 0; i < 3; ++i) {
                arr[i].display();
                cout << endl;
        }

        return 0;
}

SCREENSHOT-


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

Create a "Date" class that contains: three private data members: month day year (I leave it...
Create a "Date" class that contains: three private data members: month day year (I leave it to you to decide the type) "setters" and "getters" for each of the data (6 functions in total) One advantage of a "setter" is that it can provide error checking. Add assert statements to the setter to enforce reasonable conditions. For example, day might be restricted to between 1 and 31 inclusive. one default constructor (no arguments) one constructor with three arguments: month, day,...
C++ CLASSES 1. Define a class date that has day, month and year data members. 2....
C++ CLASSES 1. Define a class date that has day, month and year data members. 2. Define a class reservation with following data members: - An integer counter that generates reservation numbers. - An integer as a reservation number. The counter is incremented each time a reservation object is created. This value will be assigned as the reservation number. - Number of beds. - Reservation date from class date. 3. Define a class rooms with data members: - Room number...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class in the person class.    First, Create a date class.    Which has integer month, day and year    Each with getters and setters. Be sure that you validate the getter function inputs:     2 digit months - validate 1-12 for month     2 digit day - 1-3? max for day - be sure the min-max number of days is validate for specific month...
c++ Design the Weather class that contains the following members: Data members to store: -a day...
c++ Design the Weather class that contains the following members: Data members to store: -a day (an integer) -a month (an integer) -a year (an integer) -a temperature (a float) -a static data member that stores the total of all temperatures (a float) Member functions: -a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly entered temperature to the total). -a static...
Write a c++ program that asks the user for a date (Month and Day only) and...
Write a c++ program that asks the user for a date (Month and Day only) and displays the season in this day.The program asks then the user if he needs to enter another date, if he answers with ’Y’ or ’y’, the programwill take another date from the user and displays the season in this day.The program will keep repeating this until the user enters a character different than ’Y’ and ’y’.•Fall starts in September 21st•Winter starts in December 21st•Spring...
C++ Define a MyDate class to represent a data that has 3 data members: day, month,...
C++ Define a MyDate class to represent a data that has 3 data members: day, month, year. The class should have: A default constructor to initialize the day, month, and year to 0. A constructor that accepts three integers as arguments to initialize the day, month, and year if the three arguments are valid. A copy constructor that accepts a reference to a MyDate object as argument. This constructor use the argument's three data fields to initialize the day, month,...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: -...
C++ Assignment. Design the Weather class that contains the following members: Data members to store: - a day (an integer) - a month (an integer) - a year (an integer) - a temperature (a float) - a static data member that stores the total of all temperatures (a float) Member functions: - a constructor function that obtains a day, month, year and temperature from the user. This function should also accumulate/calculate the total of all temperatures (i.e., add the newly...
Day of week Write a program that asks the user for a date (year, then month,...
Day of week Write a program that asks the user for a date (year, then month, then day, each entered as a number on a separate line), then calculates the day of the week that date falls on (according to the Gregorian calendar) and displays the day name. You may not use any date functions built into Python or its standard library, or any other functions that do this work for you. Hint: Reverend Zeller may be useful, but his...
Date - month: int - day: int - year: int +Date() +Date(month: int, day: int, year:...
Date - month: int - day: int - year: int +Date() +Date(month: int, day: int, year: int) +setDate(month: int, day: int, year: int): void -setDay(day: int): void -setMonth(month: int): void -setYear(year: int): void +getMonth():int +getDay():int +getYear():int +isLeapYear(): boolean +determineSeason(): string +printDate():void Create the class Constructor with no arguments sets the date to be January 1, 1900 Constructor with arguments CALLS THE SET FUNCTIONS to set the Month, then set the Year, and then set the Day - IN THAT ORDER...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT