Question

CO 3) Demonstrate encapsulation by creating a declaration file from the following UML diagram:

(Note) The declaration file is the header file (.h file) and implementation file is the .cpp file.

Date 0 - num Date: static int - day: int - month: int - year int +Date0 +Date(int, int, int) +Date(Date &) +Date0 +get Day0:

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

\color{blue}\underline{Data.h:}

#ifndef DATE_H
#define DATE_H

class Date {
private:
    static int numDate;
    int day;
    int month;
    int year;
public:
    Date();
    Date(int day, int month, int year);
    Date(Date &d);
    ~Date();

    int getDay();
    void setDay(int day);
    int getMonth();
    void setMonth(int month);
    int getYear();
    void setYear(int year);
    void displayDate();
};

#endif

\color{blue}\underline{Data.cpp:}

#include "Date.h"
#include <iostream>

using namespace std;

Date::Date() {
    numDate++;
}

Date::Date(int day, int month, int year) : day(day), month(month), year(year) {
    numDate++;
}

Date::Date(Date &d) : day(d.day), month(d.month), year(d.year) {
    numDate++;
}

Date::~Date() {
    numDate--;
}

int Date::getDay() {
    return day;
}

void Date::setDay(int day) {
    this->day = day;
}

int Date::getMonth() {
    return month;
}

void Date::setMonth(int month) {
    this->month = month;
}

int Date::getYear() {
    return year;
}

void Date::setYear(int year) {
    this->year = year;
}

void Date::displayDate() {
    cout << day << "/" << month << "/" << year << endl;
}

int Date::numDate = 0;

\color{blue}\underline{main.cpp:}

#include <iostream>
#include "Date.h"
using namespace std;

int main() {
    Date date(3, 7, 2019);
    date.displayDate();
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
CO 3) Demonstrate encapsulation by creating a declaration file from the following UML diagram: (Note) The...
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
  • 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...

  • n this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A...

    n this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A test driver for testing the class defined in the other 2 files. You can name your file in the way you like. Remember it must be a .cpp file. In DateType.h file, type these lines: // To declare a class for the Date ADT // This is the header file DateType.h class DateType { public: void Initialize(int newMonth, int newDay, int newYear); int GetYear()...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

  • Using JAVA FX how would I combine the two programs below into one interface that allows...

    Using JAVA FX how would I combine the two programs below into one interface that allows the user to pick which specific program they would like to play. They should be able to choose which one they want to play and then switch between them if necesary. All of this must be done in JAVA FX code Black jack javafx - first game program package application; import java.util.Arrays; import java.util.ArrayList; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.application.Application; import javafx.geometry.Pos; import javafx.geometry.Insets;...

  • Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class...

    Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...

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