Question

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 classes

- make sure to use the member initialization list

create 3 objects and test the implemented methods.

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

//Birthdate.cpp

#include<iostream>
using namespace std;

class Birthdate{
   private:
       int year,month,day;
      
   public:
       Birthdate(){}
      
       Birthdate(int y,int m,int d){
           year = y;
           month = m;
           day = d;
       }
       Birthdate(Birthdate & date){
           year = date.year;
           month = date.month;
           day = date.day;
       }
      
       ~Birthdate(){}
      
       void setYear(int y){
           year = y;
       }
       void setMonth(int m){
           month = m;
       }
       void setDay(int d){
           day = d;
       }
       int getYear(){
           return year ;
       }
       int getMonth(){
           return month;
       }
       int getDay(){
           return day ;
       }
       int age(){
           return 2019 - year;
       }
};

//Person.cpp

#include"BirthDate.cpp"

class Person{
   private:
       string firstName;
       string lastName;
       Birthdate datOfBirth;
       int SNN;
      
   public:
       Person(string fname , string lname,Birthdate d , int s){
           firstName = fname;
           lastName = lname;
           datOfBirth = d;
           SNN = s;
       }
       ~Person(){}
      
       void print(){
           cout<<"First Name : "<<firstName<<"\n";
           cout<<"Last Name : "<<lastName<<"\n";
           cout<<"Date of Birth : "<<datOfBirth.getDay()<<"-"<<datOfBirth.getMonth()<<"-"<<datOfBirth.getYear()<<"\n";
           cout<<"SSN : "<<SNN<<"\n";
       }
      
};

//main.cpp

#include"Person.cpp"

int main(){
   Birthdate date(2000,10,12);
   Person p("abc","xyz",date,10);
   p.print();
   cout<<date.age();
}

Add a comment
Know the answer?
Add Answer to:
Create a C++ project with 2 classes, Person and Birthdate. The description for each class is...
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
  • Language: C++ Create an abstract base class person. The person class must be an abstract base...

    Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

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

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • Create the class Book which has the following members: 1. private members: 1. title as String...

    Create the class Book which has the following members: 1. private members: 1. title as String 2. isbn as String 3. author as String 4. price as double 2. public members: 1. default constructor which initializes all data members to their default values. 2. non-default constructor which initializes all data members to parameters values. 3. toString which returns a representing String of the Book. 4. add all the setters and getters. Create the class EBook which is a subclass of...

  • C++ Program 3 Create a class Person Include three(3) variables: firstName, lastName, YearOfBirth Write default and...

    C++ Program 3 Create a class Person Include three(3) variables: firstName, lastName, YearOfBirth Write default and parameterized constructors Write getters and setters for each variable. Declare 2 instances of the person class P1 and P2, one for both default and parm constructors Declare ptrPerson1 and ptrPerson2. Assign ptrPerson1 address of P1 Assign ptrPerson2 address of P2 Call all the getters and setters using the ARROW notation to test the class. Example:    ptrP1à getFirstName()

  • For this homework assignment, you will create two classes that will work with each other. The...

    For this homework assignment, you will create two classes that will work with each other. The first is a class you will write is called CQuadratic, which represents a second-order quadratic equation (e.g., 3x2 + 2x + 9).  CQuadratic will only have one constructor (type constructor), which will take the coefficients of the quadratic equation (e.g., 3, 2, 9) and assign them to it’s three private data members (the three coefficient variables). The class also has an Evaluate function that passes...

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...

  • for c++ answer the following and create the following (1)Declare a class to hold Employee Data....

    for c++ answer the following and create the following (1)Declare a class to hold Employee Data. It must have at least 2 attributes and 1 method in addition to getters/setters for 1 of the 2 attributes. Also, include at least 2 constructors and a destructor. Put the appropriate members in public and private sections. You don't need to write the code to implement the class except for getters and setters which should include the appropriate inline code. (2) What is/are...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

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