Question

In: Computer Science

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
        Use 4 digits for the year... - validate greater or equal to 0001

   Have a default constructor which set values to 01 01 1900

   Have a parameterized constructor which lets you set date

* Next, Create a person class

   Which has string firstname, lastname ( private members )

   Date of birth (using new date class YOU declared - place declaration as private member in person )

   Write getter and setters for firstname and last name ( public members )

   Write getter and setters for month, day and year for private data declaration ( public members )

   Write a person default constructor function that defaults "None" "None" for firstname and lastname ( public members )

   Write a person parmaterized constructor function that can pass data to firstname and lastname, and
      the composed birthdate. ( public members )

* Code and test a person class

   Declare a person Person1 using the default constructor, to test it.

      Using getters and setters of the person class to test fully.

   Declare a person Person2 using the parmaterized constructor, to test it.

      Using getters and setters of the person class to test fully.

Solutions

Expert Solution

#include <iostream>

using namespace std;

// Online C++ compiler to run C++ program online
#include <iostream>

class Date
{
  public:                         //access control
    int day;                      //these data members
    int month;                    //can be accessed
    int year;                     //from anywhere
 
  Date()                                //   setter
  {                                     // Constructor without parameters
    day = 01;
    month = 01;
    year = 1900;
  } 
  
  Date(int x, int y, int z)              //  setter
  {                                      // Constructor with parameters
    if(x>=01 && x<=31 && y>=1 && y<=12 && z>=0001)
    {
        day = x;
        month = y;
        year = z;
    }
    else
    {
        cout << "Invalid Input";
    }    
  }
  
  public:
  int dayGetter()
  {
      return day;
  }
  
  public:
  int monthGetter()
  {
      return month;
  }
  
  public:
  int yearGetter()
  {
      return year;
  }
};

class Person
{
    private:                        //access control
        string firstName;           //these data members
        string lastName;            //can be accessed
        Date dateOfBirth;           //from anywhere
    
    public:
    
    Person(string x, string y, Date d)             //   setter
    
    { // Constructor with parameters
        firstName = x;
        lastName = y;
        Date dateOfBirth = d;
    }
    
    public:
    
    Person() 
    {                              // Constructor without parameters   (setter)
        firstName = "None";
        lastName = "None";
    }
    
    public:
    string firstNameGetter()
    {
      return firstName;
    }
    
    public:
    string lastNameGetter()
    {
    return lastName;
    }

};

int main() {
    
    cout << "Hello world!\n\n";
    Date d1(17, 03, 2020);
    cout << d1.yearGetter() << "\n";
    Person p1;
    cout << p1.lastNameGetter() << "\n";
}

Related Solutions

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...
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...
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...
Java program Create class DateClass with the following capabilities: Output the date in multiple formats, such...
Java program Create class DateClass with the following capabilities: Output the date in multiple formats, such as MM/DD/YYYY June 14, 1992 DDD YYYY Use overloaded constructors to create DateClass 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 of which represents the day...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables:...
1. Create a console program in C#, * Create a class: "Student.cs" * Add 3 variables: StudentName (string), SchoolYear (int), YearsUntilGraduation(int) * Method YTK() = 12 - SchoolYear; 2. Main *Enter name *Enter age *You will attend school:____ years before graduating.
In Python, create a program with 2 classes that do the following. HashCreate class, this class...
In Python, create a program with 2 classes that do the following. HashCreate class, this class will accept a directory and hash each file in the directory and store the results in a dictionary. The dictionary will contain the hash value and file name. HashVerify, the second class will accept the dictionary as input and save that in an instance attribute. This class must also contain a method for lookups that require a file path as input. The lookup method...
C++ problem 11-2 In this chapter, the class dateType was designed to implement the date in...
C++ problem 11-2 In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear, to check whether...
Create a working C# Program that will accept an input and has the following class. areaCircle...
Create a working C# Program that will accept an input and has the following class. areaCircle – computes the area of the circle volumeCube – computes the volume of a cube perimeterTraingle – computes the perimeter of a triangle surfaceAreaRect – computes the surface area of a rectangle *You may usePass by Value and/or Pass by Reference *Using ConsoleApp
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS COVERING THE FOLLOWING POINTS: 1) COUNTING NUMBER OF OBJECTS CREATED ( NO OBJECT ARRAY TO BE USED) USING ROLE OF STATIC MEMBER 2) SHOWING THE VALID INVALID STATEMENTS IN CASE OF STATIC MEMBER WITH NON STATIC MEMBER FUNCTION, NON STATIC MEMBERS OF CLASS WITH STATIC MEMBER FUNCTION, BOTH STATIC. SHOW THE ERRORS WHERE STATEMENTS ARE INVALID. 3) CALL OF STATIC MEMBER FUNCTION, DECLARATION OF...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT