Question

Create a class named Date in C++ Class has 3 private data items (name the data...

  1. Create a class named Date in C++
  2. Class has 3 private data items (name the data items month, day, year)
    1. int month
    2. int day
    3. int year
  3. Member functions
    1. ‘getters’   a getter for each data item
      1. Use ‘get’ and the data items name
      2. The data item name must be capitalized
      3. Return the data item
      4. Example: int getMonth()        {return month;}
    2. ‘setters’   a setter for each data item
      1. Use ‘set’ and the data items name
      2. The data item name must be capitalized
      3. Change the data items value
      4. Example: void setMonth(int x)          {month = x;}
    3. display()
      1. blank line
      2. month is               mm
      3. day is                     dd
      4. year is                   yyyy
      5. blank line

             notice, month, day, and year values line up and are printed in that order

             use ‘getters’ in the display function – not the data item name

since the setters and getters are small one line member functions, the setters and getters

can be coded inside the class definition.

The member function    void display()    is coded outside the class definition.

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

NOTE: I have completed answer for your question. Please check and let me know if you have any queries. I will get back to you within 24 hours. Thanks for your patience.

Code:

#include <iostream>

using namespace std;

class Data{
// declaring data items
public:
int month, day, year;
  
// getter and setter methods
int getMonth(){
return month;
}
int setMonth(int x){
month = x;
}
int getDay(){
return day;
}
int setDay(int x){
day = x;
}
int getYear(){
return year;
}
int setYear(int x){
year = x;
}
  
void display(void);
};

// display function outside the class definition
void Data::display(){
cout << endl;
cout << "month is " << month << endl;
cout << "day is " << day << endl;
cout << "year is " << year << endl;
cout << endl;
};

int main()
{
// creating Data instance
Data d1;
  
d1.setMonth(05);
d1.setDay(06);
d1.setYear(2019);
  
d1.display();
  
return 0;
}

Code output screenshot:

Add a comment
Know the answer?
Add Answer to:
Create a class named Date in C++ Class has 3 private data items (name the data...
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
  • public class Date { private int month; private int day; private int year; /** default constructor...

    public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...

  • C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member fu...

    C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member functions inside Date.h and Date.cpp. Step 2. Design another ADT that implements a class named Watch, add 3 private member variables hour, minute, second, along with their appropriate public constructor / getter / setter member functions inside Watch.h and Watch.cpp. Step 3. Next, implement the additional SmartWatch...

  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • In C++ Consider the following Date class: #include <iostream> using namespace std; class MyDate { private:...

    In C++ Consider the following Date class: #include <iostream> using namespace std; class MyDate { private: int month, day, year; public: MyDate() {setDate(2,27,2006);} MyDate(int, int, int); void setDate(int mm, int dd, int yyyy); void showDate(); }; MyDate::MyDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::setDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::showDate() { cout << "The date is "...

  • Write a program in C++ with comments! Create an abstract class Property, containing the data items...

    Write a program in C++ with comments! Create an abstract class Property, containing the data items owner, address and price. Add an abstract method showOwner(). Also provide getter/setters for all the data items. Make validations if necessary in the setter so that no invalid values are entered. Create a class House, to inherit the Property class. This class should contain additional data item – yardSize – an integer – the size of the yard of the house, getter and setter...

  • Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 -...

    Given the following date class interface: class date {private: int month;//1 - 12 int day;//1 - 28. 29. 30. 31 depending on month & year int year;//4-digit, e.g.. 2017 public: date();//Default constructor (investigate; find what it is used for)//Postcondition: the newly declared date object is initialized to 01/01/2000 date(int mm, int dd, int yyyy);//Second constructor//Postcondition: the newly declared data object is initialized to mm/dd/yyyy void setDate(int mm. int dd. int yyyy);//Postcondition: set the contents of the calling date object to...

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

  • The rest of question 4: object. Make sure that the implementation of class Employee2 includes all...

    The rest of question 4: object. Make sure that the implementation of class Employee2 includes all necessary revisions to all members functions that appeared in class Employee implementation. Heres a link for the class Employee: http://www.cs117.ghriga.com/blog/2017/10/07/practice-4/ de the program and determine its output if the user enters-2 B) Trace the program and determine its output if the u C) Trace the program and determine its output if the ts D) Trace the program and determine its output if the user...

  • Examine the following class definition: public class Date private int year; private int month; private int...

    Examine the following class definition: public class Date private int year; private int month; private int day; public Date() { ...) public void set (int x, int y, int z) { ...) public int getYear() { ...) // returns year public int getMonth() { } // returns month public int get Day () { ...) // returns day //more methods here -- 1 Which of the following statements in a client program correctly prints out the day of the object...

  • Given the definition of a class called Bag as following: class Bag { private:             int...

    Given the definition of a class called Bag as following: class Bag { private:             int items[100];             int itemCount; public:             Bag();             bool add(int item);             int getMin();             bool containsOdd();             int getLast();             void display(); }; Please provide the definition of the member function: bool add(item) ------ This function add an new integer into the bag.

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