How should i do this ?

Hey buddy,
Here's the problem :
???
Define a struct Date to keep track of dates. Provide fucntions that read Dates from input, write Dates to output, and initialize a Date with a date.
???
I've written the functions that read dates from input and write them to the output in the code below.

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
#include <iostream>
#include <string>
using namespace std;

struct Date{
		int day;
		string month;
		int year;
	};

void readate(Date* date)
{
	cout<<" insert a date. "<<endl;
	cout<<" day : "; cin>>date->day;
	cout<<" month : "; cin>>date->month;
	cout<<" year : "; cin>>date->year;
	cout<<" I got it, thanks !! \a"<<endl;
}
void writedate(Date date)
{
	if( date.month == "") cout<<" You haven't inserted a date yet. " <<endl;
	else cout<< " The date you inserted is : " <<date.day<<" "<<date.month<<" "<<date.year<<endl;
}


int main()
{
	Date newDate;
	int action;
	while(1)
	{
	cout<<" Choose one of the actions below : \n"
		<<"1. insert  date \n"
		<<"2. read  date"<<endl;
	cin>> action;
	if(action==1) 
	readate(&newDate);
	else if(action==2) 
		{
		writedate(newDate);
		break;
		}
	else 
	{
		cout<< " This wasn't an action dumb ass ! \a "<<endl;
	}
	}
}

  




I just don't get the last part, " initialize a Date with a date ". should it be a function with the below declaration ?

 
void initDate(Date,date);


if so, how should i extract data from the second argument "date" which is probably going to be in one piece ?

It means, do somthing like:
1
2
3
4
int main()
{
    Date today = { 9, "June", 2014 };
    // ... 
thanks for answering my friend,
i did consider this, but it wasn't that challenging.
is it possible to cin an input like say " 27-december-1994 " and manage to extract the data then initialize the Date sturct with it ?
It's challenging if you can't do it.

That doesn't make it wrong.
Topic archived. No new replies allowed.