Question

Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date. You will make some modific ation to the Date

Compares two Date objects values and returns true if they are the same, otherwise returns false. equals B. (15 points) Defin

int arguments (for year, month, and day of dob), and a double value for the salary to initialize data members of an Employee

Submission Submit a ZIP file that contains seven files on the follow ing names (case-sensitive): Date.h Date.cpp Person.h Per

Alice Brown Bob Bush 1980 12 5 56980 1972 3 26 120500 Carl Capra David Lieberman 1976 11 26 87000 1990 5 12 45200 John Menchi

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

TASK A)

Date.h

#include <algorithm>
#include<string>
#ifndef DATE_H
#define DATE_H
using namespace std;

class Date {
//Data members of the class

int year;
int month;
int day;

public:


//Creating arguments-constructor having default values

Date(int year = 2001, int month = 1, int day = 1) {


//We have used && AND operator because we want to satisfy both conditions

//Validation of Year

if (year > 1900 && year <=2019) {
this->year = year;
} else {
this->year = 2001; //Default Condition

}


//Validation of Month

if (month > 1 && month < 12) {
this->month = month;
} else {
this->month = 1; //Default Condition

}


//Validation of days

int months_of_31days[7]={1, 3, 5, 7, 8, 10, 12};
int months_of_30days[4]={4, 6, 9, 11};

//Using the find method of "algorithm.h" library we can know if the number is inside the array or not


//Validation of 31 days
if ((std::find(std::begin(months_of_31days), std::end(months_of_31days), 1) != std::end(months_of_31days)) && day > 1 && day < 31) {
this->day = day;
}

//Validation of 30 days
else if ((std::find(std::begin(months_of_30days), std::end(months_of_30days), 1) != std::end(months_of_30days)) && day > 1 && day < 30) {
this->day = day;
}

//Validation of February with days should be less than 28
else if (month == 2 && day < 28) {
this->day = day;
} else {
this->day = 1; //Default Condition
}
}

//Copy Constructor

Date(const Date &obj) {
year = obj.year;
month = obj.month;
day = obj.day;
}

int getYear() {
return year;
}

int getMonth() {
return month;
}

int getDay() {
return day;
}
  
void print(){
string print_date=to_string(month)+"-"+to_string(day)+"-"+to_string(year);
cout<<print_date<<endl;
}

};

#endif /* DATE_H */

Date.cpp

#include <cstdlib>
#include<iostream>
#include"Date.h"
using namespace std;

int main() {

cout << "Date Check for general Case" << endl;
Date d_genral(2019, 11, 8);
d_genral.print();

cout << "Date Check for Year" << endl;
Date d_year(1815, 3, 2);
d_year.print();

cout << "Date Check for Month" << endl;
Date d_month(2017, 15, 7);
d_month.print();

cout << "Date Check for Day" << endl;
Date d_day(2019, 4, 37);
d_day.print();


return 0;
}


Output:

Date Check for general Case
11-8-2019
Date Check for Year
3-2-2001
Date Check for Month
1-7-2017
Date Check for Day
4-1-2019

Q 7 0 7 B O W - Date.cpp Date.h> Source History ... 9 #include <cstdlib> #include<iostream> #include Date.h using namespace

// Creating arguments-constructor having default values Date(int year = 2001, int month = 1, int day = 1) { //We have used &&Q 7 0 7 B D O W . - Date.cpp 2 Date.h Source History B . . 9 #include <algorithm> #include<string> #ifndef DATE_H #define DATSource History LE - QF D T B D O OW 54 //Using the find method of algorithm.h library we can know if the number is inside t

Add a comment
Know the answer?
Add Answer to:
Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date....
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
  • Design and implement a C++ class called Date that has the following private member variables month...

    Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • 2- Write a program that has a Person class, a Student class, that is derived from...

    2- Write a program that has a Person class, a Student class, that is derived from Person, and a Faculty class, derived from Person as well, with the following specifications: The Person class has the following members: a. An integer private member variable named SSN. b. Two string protected member variables named firstName and lastName. C. An integer protected member variable named age. d. A constructor that takes SSN, first name, last name, and age as parameters. e. A constructor...

  • C++ edit: You start with the code given and then modify it so that it does...

    C++ edit: You start with the code given and then modify it so that it does what the following asks for. Create an EmployeeException class whose constructor receives a String that consists of an employee’s ID and pay rate. Modify the Employee class so that it has two more fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an EmployeeException if the hourlyWage is less than $6.00 or over $50.00. Write a program that...

  • Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and...

    Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and will add various functionality. We will store the following private variables specific to Warehouse: . a std::vector of float values which indicate the monetary values of each sale made by this salesman . a std::string which stores that salesman's position title . a float which stores their commission percentage, i.e., the percentage of sales they receive as a paycheck . a float which stores...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • HW_8b - Famous People - One class used by another class - This exercise requires the...

    HW_8b - Famous People - One class used by another class - This exercise requires the declaration of two classes: o Famous People O Date - 5 Files are required: o Date.h o Date.cpp o Famous People.h o Famous People.cpp o main.cpp File: Date.h Private data members: O _month o _day 0 year - Public member functions: o Default constructor • Assign O's to all three data members. o Overloaded constructor • Three integer values are passed as arguments from...

  • C++ Your solution will consist of the following four files: HeartRates.h (class specification file) HeartRates.cpp (class...

    C++ Your solution will consist of the following four files: HeartRates.h (class specification file) HeartRates.cpp (class implementation file) 200_assign4.cpp (application program) 200_assign4.pdf (sample runs) For your fourth programming assignment you will be writing the following C++ program: The formula for calculating your maximum heart rate in beats per minute is 220 minus your age in years. Your target heart rate is a range that is 50-85% of your maximum heart rate. Create a class called HeartRates. The class attributes should...

  • Part I: (The Myate class) Design a class named MyDate. The class contains: • The data...

    Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...

  • Create a C++ project with 2 classes, Person and Birthdate. The description for each class is...

    Create a C++ project with 2 classes, Person and Birthdate. The description for each class is shown below: Birthdate class: private members: year, month and day public members: copy constructor, 3 arguments constructor, destructor, setters, getters and age (this function should return the age) Person class: private members: firstName, lastName, dateOfBirth, SSN public members: 4 arguments constructor (firstName, lastName, datOfBirth and SNN), destructor and printout Implementation: - use the separated files approach - implement all the methods for the 2...

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