C++ programming question
Topic: Class 'Date'
Hello everybody, can some one help me...
... Write a class Date with the following
properties:
a) Data elements of the class are day, month, year. All three data
elements are defined by the Type int.
b) A set and a get element function are to be provided for each
data element. In
Within the framework of this task, it should be assumed that the
values that are passed for day and year,
are correct. The value for the month should be checked to see
whether it is in the range from 1 to 12, and
If this is not the case, a message should be issued and the value
set to 1.
c) The class should have a constructor with three parameters that
contains the three data elements with these parameters
is initialized.
d) An element function toString is to be made available, which can
be used day, month, and year with
returns points separated as a string, e.g. 21.12.2018
Use the function std::to_string from <string> here as
well.
e) First sketch a class diagram (like the one in task 2 above) and
then set it to
class diagram into a C++ class definition in a header file. Then
implement the implementations
of the individual element functions in a separate implementation
file.
Use the class Date in an application program that demonstrates the
properties of the class.
Thank you in advance.
Here is the C++ implementation for the problem :
date.h (Header File) - This defines the class definition
class Date{
private :
int day;
int month;
int year;
public :
Date();
Date(int day,int month,int year);
void setDay(int day);
void setMonth(int month);
void setYear(int year);
int getDay();
int getMonth();
int getYear();
std::string toString();
};
date.cpp (This defines the methods of Date class) -
#include<bits/stdc++.h>
#include"date.h"
Date::Date(){}
Date::Date(int d,int m,int y){
day = d;
month = m;
year = y;
}
void Date::setDay(int d){
day = d;
}
void Date::setMonth(int m){
month = m;
}
void Date::setYear(int y){
year = y;
}
int Date::getDay(){
return day;
}
int Date::getMonth(){
return month;
}
int Date::getYear(){
return year;
}
std::string Date::toString(){
std::string s = std::__cxx11::to_string(day) + "." +
std::__cxx11::to_string(month) + "." +
std::__cxx11::to_string(year) ;
return s;
}
use_date_class.cpp (This c++ file uses the Date class) -
#include <iostream>
#include"date.h"
using namespace std;
int main()
{
Date obj;
int day,month,year;
cout<<"Enter the day : ";
cin>>day;
obj.setDay(day);
cout<<"Enter the month : ";
cin>>month;
if(month >12 && month <1){
cout<<"Entered month is invalid. Month is getting initialized
to 1 by default"<<endl;
obj.setMonth(1);
}
else{
obj.setMonth(month);
}
cout<<"Enter the year : ";
cin>>year;
obj.setYear(year);
cout<<"Date entered by you is :
"<<obj.toString()<<endl;
return 0;
}
To compile the above code run the following command-
g++ date.cpp use_date_class.cpp
in your terminal and run it using command
./a.out
Here is the screenshot of the output of code -

C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a...
- Classes Write a C++ program that creates a class called Date that includes three pieces of information as data members, namely: month (type int) day (type int) year (type int). Program requirements: - Provide set and a get member functions for each data member. - For the set member functions assume that the values provided for the year and day are correct, but in the setMonth member function ensure that the month value is in the...
Using C#, Create a date class with integer data members for year, month, and day. Also include a string data member for the name of the month. Include a method that returns the month name as string as part of the date. Separate the day from the year with comma in the method. Include appropriate constructor, properties, and methods. Override the ToString() method to display the date formatted with slashes(/) separating the month, day, and year. Create a second class...
Create a class called Date212 to represent a date. It will store the year, month and day as integers (not as a String in the form yyyymmdd (such as 20161001 for October 1, 2016), so you will need three private instance variables. Two constructors should be provided, one that takes three integer parameters, and one that takes a String. The constructor with the String parameter and should validate the parameter. As you are reading the dates you should check that...
dateInformation class. visual basic. Crate a class called DateInformation that includes three pieces of information as intense variable- a month(type Integer), a day(type Integer) and year (type Integer). Your class should provide properties that enables a client of the class to get and set the month, day, year values.The set acessor should perform validation and throw exception for invalid values. You class should have a constructor that initializes the three instances variables and uses the class's property to set each...
Program Description: Design a class named Date. The class should store a date in three integers: month, day, and year. Create the necessary set and get methods. Design member functions to return the date as a string in the following formats: 3/29/1988 29 MARCH 1988 MARCH 29, 1988 Input Validation: Do not accept values for day greater than 31 or less than 1. Do not accept values for month greater than 12 or less than 1. Do...
(IN JAVA ) Given the class Date that can prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2005. Please do the following: Derive the class ExtDate so that the date can be printed either form. Add a data member to the class ExtDate so that the month can also be stored in string form. Add a method to output the month in the string format followed...
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...
JAVA programing Question 1 (Date Class): 5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...
In c++ show both .cpp and .hpp file for the class: class Task { private: // These three member variables store the basic information about a task string title; string location; // This pointer will point to a dynamically-allocated array // of THREE strings. Each element contains the name of a supply required for this task. // This should start out set to NULL. string * tags; // This integer stores the number of elements in the tags array. int...
its about in C++
You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...