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++ * 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...
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++ 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...
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...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY b. Use overloaded constructors to create Date objects initialized with dates of the formats in part (a). In the first case the constructor should receive three integer values. In the second case it should receive a String and two integer values. In the third case it should receive two integer values, the first...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
Create separate class with these members a, b, c, x, y, z int a b c...
Create separate class with these members a, b, c, x, y, z int a b c float x y z Demonstrate 3) A two arg float, int constructor, and a three arg int, float, float constructor to instantiate objects, initialize variables read from the keyboard, display the sum Note:- Please type and execute this above java program and also give the output for both problems. (Type a java program)
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
C++ Create a class for working with fractions. Only 2 private data members are needed: the...
C++ Create a class for working with fractions. Only 2 private data members are needed: the int numerator of the fraction, and the positive int denominator of the fraction. For example, the fraction 3/7 will have the two private data member values of 3 and 7. The following methods should be in your class: a. A default constructor that should use default arguments in case no initializers are included in the main. The fraction needs to be stored in reduced...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT