In: Computer Science
This assignment uses data structures, selection, use, control structures, logic, computation, file I/O, etc. In C++
There should be 3 files for the project: theMain.cpp, dateClass.h, dateClass.cpp (or similar file names)
For input/output. Read at least 10 dates in a data file set up this way:
The first number is the number of data items in the file. Then after that, each row is one date in the format month day year.
here is a sample data file of 6 elements:
6
1 1 2016
12 31 2011
11 01 -5506
13 02 2002
2 31 2020
2 21 2015
the output would be:
1 1 2016 would be: 1/1/16, January 1, 2016 and 1 January 2016
12 31 2011 would be: 12/31/11, December 31, 2011 and 31 December 2011
11 01 -5506 is an unknown date
13 02 2002 is an unknown date
2 31 2020 is an unknown date
2 21 2015 would be: 2/13/15, February 21, 2015 and 13 February 2015
if you program the main program similar to the example below, the output will be close to the example in the textbook. (the example below does not use files or a loop to read data)
#include <iostream>
#include <string>
#include "dateClass.h"
using namespace std;
int main()
{
Date aDate(3,15,2016);
aDate.displayShort();
aDate.displayLong();
aDate.displayGlbl();
cout << endl;
system("pause");
return 0;
} //end main
Here is the answer for your question in C++ Programming Language.
Kindly upvote if you find the answer helpful.
NOTE : I have used dev-c++ to compile the code, hence I had to include .cpp file instead of .h file in main.cpp file. (i.e., I had used #include "dateClass.cpp" instead of #include "dateClass.h" in main.cpp file). If including .h file works for you please include that only.
Please comment below if you have any doubts.
######################################################################
CODE :
dateClass.h
#ifndef MYDATE_H #define MYDATE_H #include<string> using namespace std; class Date{ public: Date(int,int,int); string validateDate(); void displayShort(); void displayLong(); void displayGlbl(); private: int day; int month; int year; string months[12]; }; #endif |
#############################################################
dateClass.cpp
#include "dateClass.h" Date::Date(int month,int day,int year){ |
####################################################################
main.cpp
#include <iostream> #include "dateClass.cpp" |
##########################################################################
DateFile.txt
6 1 1 2016 12 31 2011 11 01 -5506 13 02 2002 2 31 2020 2 21 2015 |
##########################################################################
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
dateClass.h
dateClass.cpp
###################################################################
main.cpp
###########################################################################
DateFile.txt
#####################################################################
OUTPUT :
Any doubts regarding this can be explained with pleasure :)