Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java. In both cases you cannot use libraries or packages that contain pre-built data structures, other than built-in support for objects, arrays, references, and pointers.
Classes in C++ and Java can represent anything in the real world. This assignment is to write a class to represent a Date in a Calendar.
Date Class Member Variables
The following table identifies and describes the purpose of each
Date class member variable:
|
Name |
Data Type |
Purpose |
|
month |
int |
Number corresponding to month of year (e.g., 1-12) |
|
day |
int |
Number corresponding to day of month (e.g, 1 to 28-31) |
|
year |
int |
Number corresponding to year |
All of these class member variables are private. You
cannot add to or otherwise change these class member variables.
Date Class Member Functions
The following table identifies and describes the purpose of each Date class member function:
|
Name |
Return Value | Parameters |
Purpose |
|
setDate |
void | 3 integers |
Assigns the value of each parameter to the month, date and year member variables respectively unless the date is not valid (see next section) |
|
printDate |
void | None | Outputs the date in the format month/day/year, such as 9/1/2018 |
Driver File
The code for the driver file is given below except of the last two statements. You need to call setDate andprintDate, but you are not told exactly how. You can't change the code for the driver file except for properly calling setDate and printDate in the last two statements.
#include <iostream>
using namespace std;
#include "date.h"
int main()
{
Date d1;
int m, d, y;
cout << "Enter month, day and year separated by spaces: ";
cin >> m >> d >> y;
// call setDate
// call printDate
return 0;
}
What the Program Does
The user is prompted to enter a month, day and year. If the date is valid, then the setDate member function assigns the month, day and year inputs to the Date instance. If the date is not valid, then the values 9, 1, and 2018 are assigned respectively to the month, day and year member variables of the Dateinstance. The printDate function then outputs the Dateinstance in the format month/day/year.
A date is valid if:
The month is between 1 and 12.
The day is between 1 and 31. Yes, I know, for some months the maximum number of days may be less than 31 (between 28 and 30), but at LAVC, our philosophy is "close enough for government work."
The year is between 1900 and 2018.
Sample Runs
Sample #1 - Valid Date
Enter month, day and year separated by spaces: 9 17 1921
9/17/1921
Sample #2 - Invalid Date (Default date printed)
Enter month, day and year separated by spaces: 13 1 2000
9/1/2018
Multiple Files
Use multiple files, separating the class declaration, class implementation and driver into separate files, as in Module #2. Thus, your project will have three files, date.h (the declaration file for the Date class), date.cpp(the implementation file for the Date class) and test.cpp (the “driver” file which tests the class). All class members (variables and functions) must be private unless they need to be public.
If you have any doubts, please give me comment...
date.h
#ifndef DATE_H
#define DATE_H
#include<iostream>
using namespace std;
class Date{
private:
int month;
int day;
int year;
public:
Date();
void setDate(int m, int d, int y);
void printDate();
};
#endif
date.cpp
#include "date.h"
Date::Date(){
month = 9;
day = 1;
year = 2018;
}
void Date::setDate(int m, int d, int y){
month = 9;
day = 1;
year = 2018;
if(m>=1 && m<=12 && d>=1 && d<=31 && y>=1900 && y<=2018){
bool isLeapYear = (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0));
//checking dates with 30 days
if(((month==4 || month==6 || month==9 || month==11) && d<=30) || (month==2 && ((isLeapYear && d<=29) || d<=28))){
month = m;
day = d;
year = y;
}
}
}
void Date::printDate(){
cout<<month<<"/"<<day<<"/"<<year<<endl;
}
main.cpp
#include <iostream>
using namespace std;
#include "date.h"
int main() {
Date d1;
int m, d, y;
cout << "Enter month, day and year separated by spaces: ";
cin >> m >> d >> y;
d1.setDate(m, d, y);
// call printDate
d1.printDate();
return 0;
}
Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java....
Using c++.Complete the implementation of the class date that
represents dates written in the form day/month/year. Do not modify
the main program. You must write the prototypes and the definitions
of the methods of the class.
Declaration of Class Date /File: date.h A class representing dates in the form: day, month and year dat e s are written to a stream in the form day/mon th / year day number () returns the number of days since 1/1 of the...
The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...
HW_8b - Famous People - One class used by another class - This exercise requires the declaration of two classes: o Famous People O Date - 5 Files are required: o Date.h o Date.cpp o Famous People.h o Famous People.cpp o main.cpp File: Date.h Private data members: O _month o _day 0 year - Public member functions: o Default constructor • Assign O's to all three data members. o Overloaded constructor • Three integer values are passed as arguments from...
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 LANGUAGE create an empty Java file called Date build it to find any syntax errors and eliminate them identify each member of this class and write your answer in a comment There are four different types of class member: constant, instance variable, constructor, and method identify a method as class method if it is static /* * Java program: Date.java * * Define the class Date */ import java.time.LocalDateTime; public class Date { private static final int daysEachYear =...
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()...
Programming Exercise 11-8 PROBLEM:The class dateType defined in Programming Exercise 6 prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2019. Derive the class extDateType so that the date can be printed in either form. Add a member variable to the class extDateType so that the month can also be stored in string form. Add a member function to output the month in the string format, followed...
// Enter your name as a comment for program identification // Program assignment testEmployeeAB.cpp // Enter your class section, and time /* The program testEmployeeAB.cpp tests the class Employee. The class Date is included so that the Employee class can use the Date data type. */ /* Data is entered to create an employee data file. */ /* A payroll report and equal employment opportunity report showing ethnicity data is displayed. */ //header files /* use the correct preprocessor directives...
In JAVA
1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...
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...