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

(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...
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.
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
C++ program homework question 1 1. Create and implement a class called clockType with the following...
C++ program homework question 1 1. Create and implement a class called clockType with the following data and methods (60 Points.): Data: Hours, minutes, seconds Methods: Set and get hours Set and get minutes Set and get seconds printTime(…) to display time in the form of hh:mm:ss default and overloading constructor Overloading Operators: << (extraction) operator to display time in the form of hh:mm:ss >> (insertion) operator to get input for hours, minutes, and seconds operator+=(int x) (increment operator) to...
The Date Class This class will function similarly in spirit to the Date class in the...
The Date Class This class will function similarly in spirit to the Date class in the text, and behaves very much like a “standard” class should. It should store a month, day, and year, in addition to providing useful functions like date reporting (toString()), date setting (constructors and getters/setters), as well as some basic error detection (for example, all month values should be between 1-12, if represented as an integer). Start this by defining a new class called “Date” or...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime:...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime: long) +toString(): String +getTime(): long +setTime(elapseTime: long): void Constructs a Date object for the current time. Constructs a Date object for a given time in milliseconds elapsed since January 1, 1970, GMT. Returns a string representing the date and time. Returns the number of milliseconds since January 1, 1970, GMT. Sets a new elapse time in the object. The + sign indicates public modifer...
Class Instructions You will create a password verification program using C-strings and character testing. The user...
Class Instructions You will create a password verification program using C-strings and character testing. The user will enter a password as a C-string. (Character array). You must test that the password contains at least: One lowercase letter One uppercase letter One number (0-9) The password can contain no spaces You are to add one more requirement to the password. I need help in setting this program up. #include <iostream> #include <cctype> using namespace std; int main() { char input; cout...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Write a program in c++ to do the following: 2. Create an array to hold up...
Write a program in c++ to do the following: 2. Create an array to hold up to 20 integers. 3. Create a data file or download attached text file (twenty_numbers.txt) that contains UP TO 20 integers. 4. Request the input and output file names from the user. Open the files being sure to check the file state. 5. Request from the user HOW MANY numbers to read from the data file, up to twenty. Request the number until the user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT