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...

  • 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 :...

  • 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...

  • Please write the program in C++ Problem Description: Design a class called Date. The class should...

    Please write the program in C++ Problem Description: Design a class called Date. The class should store a date in three integers: month, day, and year.     Create the necessary set and get methods.       Design member functions to return the date as a string in the following formats:                                     12/25/2012                                     December 25, 2012                                     25 December 2012 Input Validation: Do not accept values for day greater than 30 or less than 1. Do not accept values for month...

  • - Classes Write a C++ program that creates a class called Date that includes three pieces...

    - Classes Write a C++ program that creates a class called Date that includes three pieces of information as data members, namely:  month (type int)  day (type int)  year (type int). Program requirements: - Provide set and a get member functions for each data member. - For the set member functions assume that the values provided for the year and day are correct, but in the setMonth member function ensure that the month value is in the...

  • Student.h Student.cpp Person.h Person.cpp In this assignment, you need to create a class to keep track...

    Student.h Student.cpp Person.h Person.cpp In this assignment, you need to create a class to keep track of books borrowed bya student. Each book has a name, Student (who borrowed it), and the date that was borrowed (see the .h file below). Use also need to use the Person class and the Student class included in the folder. Student class inherits from the Person class as was shown in the classroom Create a Date class (in the same project of the...

  • 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 =...

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