0

Ok So from many people information. I have made this programe. But i am not able to use input operater overloading. So please help me in this. An also tell me how to make this programme simple. Once again thanks a lot to push me to do my homework on my owm.

// MyDate.h: Header file that contains declaration of functions and data members.
#include<iostream>
#include<stdlib.h>
#include<string>
#include<conio.h>
using namespace std;

class MyDate
{
private:
	  char newdate[30];
	  int l,b,c,d,a,w,x,y,z,r;
public:	
	void getdata(void);
	void DateDay(void);	

};
// MyDate.cpp : Cpp file that contains function implementation defined in MyDateTest.cpp and declared in MyDate.h.
#include"MyDate.h"
#include<iostream>
#include<stdlib.h>
#include<string>
#include<conio.h>
using namespace std;

void MyDate :: getdata(void)
{	
	cin.getline(newdate,sizeof(newdate),'\n');	
}
void MyDate :: DateDay(void)
{	
	l= strlen(newdate);	
	if (strchr(newdate,','))
	{		
		int e;
		e=strlen(strchr(newdate,','));
		char second[10];		
		strcpy(second,strchr(newdate,','));
		int j=strlen(second);
 		if(j == 6)
		{
			char month[10],day[3],century[3],year[3];
			int space=1,temp1,temp2,temp3;
			for(int i=0;i<=l;i++)
			{
				if(newdate[i] == ' ')
				{
					if(space ==1)
					{
						temp1=i;
						space=space+1;
					}
					if(space == 2)
					{
					  temp2=i;
					}
				}
				if(newdate[i] == ',')
				{
					 temp3=i;
				}
			}
			for (int j=0;j<=temp1;j++)
			{
				if(j == temp1)
				{
					month[j]='\0';
				}
				else
				{
					month[j]=newdate[j];
				}

			}
			for(int k=temp1+1;k<=temp3;k++)
			{
				if(k == temp3)
				{
					day[k-(temp1+1)]='\0';
				}
				else
				{
					day[k-(temp1+1)]=newdate[k];
				}

			}
			for(int p=temp2+1;p<=l;p++)
			{
				if(p <= temp2+3)
				{
				 if(p<temp2+3)
				 {
					 century[p-(temp2+1)]=newdate[p];
				 }
				 else
				 {
					 century[p-(temp2+1)]='\0';
				 }
				}
				if(p >= temp2+3)
				{
					if(p<l)
					{
						year[p-(temp2+3)]=newdate[p];
					}
					else
					{
						year[p-(temp2+3)]='\0';
					}
				}
			}			
			b=atoi(day);
			c=atoi(year);
			d=atoi(century);			
			if(strcmp(month,"March")==0){a=1;}
			else if(strcmp(month,"April")==0){a=2;}
			else if(strcmp(month,"May")==0){a=3;}
			else if(strcmp(month,"June")==0){a=4;}
			else if(strcmp(month,"July")==0){a=5;}
			else if(strcmp(month,"August")==0){a=6;}
			else if(strcmp(month,"September")==0){a=7;}
			else if(strcmp(month,"October")==0){a=8;}
			else if(strcmp(month,"November")==0){a=9;}
			else if(strcmp(month,"December")==0){a=10;}
			else if(strcmp(month,"January")==0){a=11;c=c-1;}
			else if(strcmp(month,"February")==0){a=12;c=c-1;}
			else {cout<<"Date is invalid"<<"\n\n";goto x;}			
			w=((13*a)-1)/5;
			x=c/4;
			y=d/4;
			z=w+x+y+b+c-(2*d);			
			r=z%7;			
			switch(r)
			{
				case 0:cout<<"Day is Sunday"<<"\n\n";
					   break;
				case 1:cout<<"Day is Monday"<<"\n\n";
					   break;
				case 2:cout<<"Day is Tuesday"<<"\n\n";
					   break;
				case 3:cout<<"Day is Wednesday"<<"\n\n";
					   break;
				case 4:cout<<"Day is Thursday"<<"\n\n";
					   break;
				case 5:cout<<"Day is Friday"<<"\n\n";
					   break;
				case 6:cout<<"Day is Saturday"<<"\n\n";
					   break;
			}
		}
		else
		{
			cout <<"Date is invalid" <<"\n\n";
			
		}
		x:;		
	}
	else
	{
		cout <<"Date is invalid" <<"\n\n";		
	}

}
// MyDateTest.cpp : Cpp file that contains function definition.
#include"MyDate.h"
#include<iostream>
#include<stdlib.h>
#include<string>
#include<conio.h>
using namespace std;

void main()
{
	MyDate r1,r2,r3,r4,r5,r6,r7;
	cout<< "Enter Dates" <<"\n\n";

	r1.getdata();	
	r1.DateDay();

	r2.getdata();	
	r2.DateDay();

	r3.getdata();	
	r3.DateDay();

	r4.getdata();	
	r4.DateDay();

	r5.getdata();	
	r5.DateDay();

	r6.getdata();	
	r6.DateDay();

	r7.getdata();	
	r7.DateDay();

	getch();

}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by gerard4143
0

not sure if this is what you mean, but try

friend std::istream& operator>>(std::istream & in, classname & rhs)

the rest you can figure out

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.