class date
{
public:
int dd;
int mm;
int yy;
}; // I think a declaration such as Date [length ] as i want the for loop to iterate and input into the class and the output to output the 5 members of the date class.
int main ()
{
for (int n = 0; n < Length; n++);
{
cin >> date.dd;
cin >> date.mm;
cin >> date.yy;
}
cout << " The Date Stored in the Date Class is ";
cout << " Day : " << date.dd;
cout << " Month : " << date.mm;
cout << " Year : " << date.yy;
system ("pause");
return 0;
}
/code]
Now the basic objectives of this program is to store upto 5 dates inside the date class though i cannot get any input or output as my declartions in the cin and cout statement cannot find the member though i think i am close i am getting frustrated with it.
Then when i have this right i will be inputting from file so i want to make sure that the data is accurate
Thanks for that i thought i had done something stupid like not declaring i had though about the array of dates as well though I used similar for a struct though i had not dealt with classes I believe this should solve my issue thanks if I have any issue with this i will post back
#include <iostream>
usingnamespace std;
#define Length 5
class date
{
public:
int dd;
int mm;
int yy;
};date dateObject[Length];
int main ()
{
date dateObject;
for (int n = 0; n <Length; n++)
{
cout << " Please Enter in Day";
cin >>dateObject.dd;
cout << "Please Enter in Month";
cin >>dateObject.mm;
cout << "Please Enter In Year";
cin >>dateObject.yy;
}
for (int n = 0;n<Length;n++)
{
cout << " The Date Stored in the Date Class is ";
cout << " Day : " <<dateObject.dd;
cout << " Month : " <<dateObject.mm;
cout << " Year : " <<dateObject.yy <<endl;
}
system ("pause");
return 0;
}
The second program is meant to take in
10 dates seperated by spaces
ie DD MM YYY
each date is on a seperate line
stored in a file called dates.dat
so i am looking at using a file input for 10 spaces stored either in an element called date then outputting the day ,month,year
#include <iostream>
#include <fstream>
usingnamespace std;
#define Length 10
class date
{
public:
int dd;
int mm;
int yy;
string date;
};date dateObject[Length];
int main ()
{
date dateObject;
string date;
for (int n = 0; n <Length; n++)
{
ifstream myfile ("dates.dat");
if (myfile.is_open())
{
while ( myfile.good() )
{
myfile >>dateObject.dd;
myfile >> dateObject.mm;
myfile>>dateObject.yy;
}
myfile.close();}
}
for (int n = 0; n <Length; n++)
{
cout << " The Date Stored in the Date Class is ";
cout << "Day :"<< dateObject.dd<<endl;
cout <<"Month :"<<dateObject.mm<<endl;
cout <<" Year :" <<dateObject.yy<<endl;
}
{
system ("pause");
return 0;
}}
Though My code only outputs the last line which is also an issue i have found with the top program in this post the issue is reccuring I belive it is storing at equal to the length ie if the length varible is 5 it is taking the 5th value only and returning it 5 times