So im doing a program where i need to take dates from a text file and insert it into an array and do the following:
Create a minimal DateType class which provides at least these operations:
1) SetDate to assign a value to an existing DateType object (parameters of month, day,
and year).
2) An input function that would read dates directly in the format used by the input file.
3) Output to display a date in the format mm/dd/yyyy.
4) Compare two dates for == and > (separate functions).
I got most of it done but i need to make it look for two of the same date and delete one of them if it finds two of the same date. I went to a tutor and he told me that i have to first overload the == and > < operators then then do a bubble sort to order them from least to greatest or vise versa and then create a loop to see if the next one in the array is the same ex: array[i] == array[i+1] ( which is the easy part)
what i need help on is the overloading operators and the bubble sort. I have the idea but i don't know where to start. Any help would be appreciated.
Here's whats i have so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream>
#include <fstream>
using namespace std;
class DateType
{
struct calender // struct to prepare for the array
{
int month;
int day;
int year;
};
calender arr[20]; // put the struct into the array
void readDate() // reads in the info from the text file and puts it into the array
{
ifstream dates("dates.txt");
for( int i=0; !dates.eof() && i < 18;i++)
{
dates >> arr[i].month;
dates >> arr[i].day;
dates >> arr[i].year;
}
}
void compareDate( )
{
readDate(); // this is where i was thinking of making the bubble sort but i heard the main is where it needs to be.
}
public:
void printDate( ) // gets the info from readDate and prints out the dates in format
{
readDate();
for( int i=0; i < 18;i++)
{
cout << arr[i].month << "/" << arr[i].day << "/" << arr[i].year << endl;
}
}
};
int main()
{
DateType myDate;
myDate.printDate();
system("pause");
return 0;
}
|
any help would be appreciated. I'm not looking for someone to do the work for me (it would be nice though) but if someone could give me a push to the right direction, that would help a lot. Thanks in advance